Consumer API¶
The Consumer API allows you to process messages from queues. pgqrs provides both high-level (ephemeral) and low-level (managed) APIs for consuming messages.
Quick Start¶
Process messages with automatic lifecycle management (dequeue -> process -> archive).
Managed Consumers¶
For long-running workers that need tracking and monitoring.
Dequeue Options¶
Batch Fetch¶
Visibility Timeout¶
Set custom lock duration for retrieved messages.
Message Lifecycle¶
Archive (Success)¶
Mark message as successfully processed.
Delete (Permanent Removal)¶
Permanently remove message (not recommended for most cases).
Extend Visibility¶
Extend the lock on a message processing takes longer than expected.
Worker Lifecycle¶
Managed consumers implement the Worker trait (Rust) for lifecycle management.
Not Supported
Explicit lifecycle management (heartbeat, suspend, shutdown) is not exposed on Python consumer objects.
Cleanup happens automatically when the object is garbage collected or the script exits.
Iterator Pattern¶
Python provides a convenient async iterator pattern not directly mirrored in the Rust high-level API.
API Reference¶
Constructor / Builder¶
pgqrs::consumer(hostname, port, queue) -> ConsumerBuilder
store.consumer(queue) -> Consumer
Methods¶
| Method | Rust | Python | Description |
|---|---|---|---|
| Dequeue | .fetch_all() |
dequeue(batch_size) |
Fetch messages |
| Archive | .archive(id) |
archive(msg) |
Success/Done |
| Delete | .delete(id) |
delete(msg) |
Remove/Discard |
| Extend | .extend_visibility() |
extend_vt() |
Extend lock |