# Record order events from a queue once

Keep one D1 journal entry per order event, even when the producer sends the event twice.

[Use template](https://dashboard.fasthook.io/workflow/new?templateKey=cloudflare-queues-order-events-to-d1&templateName=Record+order+events+from+a+queue+once)

**Required accounts**

- Cloudflare Queues
- Cloudflare D1

## Record order events from a queue once

### 1. Trigger · Message received in a queue

**Cloudflare Queues**. Start a workflow when the consumer receives a message from the selected queue.

### 2. Action · Record the order event once

**Cloudflare D1**. Run a statement with bound values, or send a batch. Each row in the results uses the column names from your query.

## Set up your workflow

1. **Prepare the event journal** In your destination D1 database, run CREATE TABLE IF NOT EXISTS order\_events (event\_id TEXT NOT NULL PRIMARY KEY, payload TEXT NOT NULL). The primary key enforces one row per event even when deliveries overlap.
2. **Connect the queue and database** In the queue trigger, choose the account and enter the source queue name. Attach the FastHook relay as its consumer. In “Record the order event once”, select the D1 database that contains order\_events.
3. **Choose a stable event ID** Send a JSON object such as \{"event\_id":"order-1007-paid","order\_id":"1007"\}. Reuse that event\_id when retrying payment confirmation. Give a later event, such as shipment, its own ID.
4. **Verify a repeat delivery** Activate the workflow and enqueue that same object twice. Check both workflow runs, then run SELECT COUNT(\*) FROM order\_events WHERE event\_id = 'order-1007-paid'. The expected count is 1.

## Related integrations

- [Cloudflare Queues integrations](https://www.fasthook.io/apps/cloudflare-queues/integrations)
- [Cloudflare D1 integrations](https://www.fasthook.io/apps/cloudflare-d1/integrations)
