# Archive queue messages in R2

Save each message body as a JSON file in the chosen R2 bucket, with a distinct object key for each queue and message.

[Use template](https://dashboard.fasthook.io/workflow/new?templateKey=cloudflare-queues-archive-to-r2&templateName=Archive+queue+messages+in+R2)

**Required accounts**

- Cloudflare Queues
- Cloudflare R2

## Archive queue messages in R2

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

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

### 2. Action · Save the message as JSON

**Cloudflare R2**. Run the R2 S3-compatible PutObject operation.

## Set up your workflow

1. **Select the queue to archive** Configure the relay Worker with the FastHook callback and shared secret. Set it as the source queue’s consumer and enter the queue name in the trigger.
2. **Choose the R2 bucket and object key** Select an R2 connection with write access to your bucket. Keep the file mapped to the queue trigger. The default key is queue-archive/\<queue\>/\<message\_id\>.json.
3. **Read back an archived message** Activate the workflow and send a JSON message with a recognizable value. Use the delivery’s message ID to find the object in R2 and compare its JSON with what you sent.

## Related integrations

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