Queues
Send messages with env.NAME.send, consume them with a queue handler.
Configuration
"queues": ["JOBS"]
Sending
env.JOBS.send({ type: "email", to: address }, { delaySeconds: 30 });
env.JOBS.sendBatch([{ body: a }, { body: b, delaySeconds: 5 }]);
Consuming
Consume messages with a queue handler on the same default export as fetch:
queue(batch) {
for (const msg of batch.messages) {
try { handle(JSON.parse(msg.body)); msg.ack(); }
catch { msg.retry(); }
}
}
Methods
| Method | Signature | Notes |
|---|---|---|
send |
(body, { delaySeconds? }) |
one message |
sendBatch |
(messages[]), each { body, delaySeconds? } |
multiple messages |
msg.ack() |
— | mark a message handled |
msg.retry() |
— | requeue a message |
Related
- The handler — the full
fetch/scheduled/queueexport shape