Consumer acknowledgements
Acknowledgement completes one message's delivery in one queue. Receiving a message only reserves it; an acknowledgement tells PostgreMQ that this queue no longer needs another attempt. Other subscribed queues retain their own deliveries.
Acknowledge after the required effects succeed. If those effects are database changes in the same database, transactional acknowledgement can commit both together.
Complete a stream delivery
These snippets use message, a delivery obtained from the stream consumer, after its application work has succeeded. Go uses an operation context named ctx.
- Go
- Rust
- TypeScript
- SQL
if err := message.Ack(ctx); err != nil { return err }
message.ack().await?;
await message.ack();
-- Replace these values with the queue, ID, and token returned by consume_message.
SELECT postgremq.ack_message('jobs', 123, 'returned-consumer-token');
The acknowledgement becomes durable when its transaction commits. Standalone SDK calls manage that transaction; transaction-scoped APIs leave commit and rollback to the caller. Completed rows may remain visible until retention, but they are no longer ordinary delivery candidates.
Return failed or unattempted work
Use negative acknowledgement for attempted work that did not complete. A delay keeps it from immediately consuming worker capacity again:
- Go
- Rust
- TypeScript
- SQL
if err := message.Nack(ctx,
postgremq.WithDelayUntil(time.Now().Add(10*time.Second))); err != nil {
return err
}
message.nack(Some(std::time::Duration::from_secs(10))).await?;
await message.nack({ delaySeconds: 10 });
SELECT postgremq.nack_message('jobs', 123, 'returned-consumer-token',
clock_timestamp() + interval '10 seconds');
On the final allowed attempt, nack moves the delivery to the DLQ instead of scheduling another attempt. The delay does not override the attempt limit.
Release is for work fetched but never attempted. Go message.Release(ctx), Rust message.release().await, and TypeScript message.release() return it immediately and refund the claim's attempt increment. The SDK uses this for buffered work abandoned during orderly shutdown. Do not use release as a way to make actual processing failures retry forever.
| Outcome | Settlement |
|---|---|
| Required effects completed | Ack. |
| Processing was attempted and failed | Nack, optionally delayed. |
| Claimed work was never attempted | Release. |
| Ownership was lost | Stop further effects; do not treat stale settlement as success. |
Handler settlement
Handler consumers normally acknowledge a successful callback return. Rust Err, TypeScript throws, and handler panics are failure paths. Go callbacks do not return errors: explicitly nack a business failure rather than logging it and returning normally.
An explicit terminal settlement prevents a second automatic settlement. Returning normally after cancellation without explicitly acknowledging completed effects follows the handler's cancellation path and returns unfinished work. See Consuming and Graceful shutdown for the language-specific signals.
Ownership and uncertain outcomes
Treat each delivery object as having one terminal settlement attempt: tracking and automatic extension end even on failure. Do not reuse it as a recovery strategy. A transport error can mean the database settled successfully but the response was lost.
SQL ack, nack, and release require a matching processing delivery and token. They do not reject solely because time elapsed if no newer claim or retirement changed that state. Manual lease extension is stricter: it also requires an unexpired lease. Application code must still honor the SDK's lost-ownership signal.
If an external effect completed before acknowledgement became uncertain, let redelivery reach an idempotent processing path. For database-only effects, use one short transaction for the effect and acknowledgement. Never acknowledge first and assume later work cannot fail.