This document is for Kombu's development version, which can be significantly different from previous releases. Get the stable docs here: 5.3.
PGMQ Transport - kombu.transport.pgmq¶
Added in version 5.7.0.
PGMQ Transport module for Kombu.
Uses the PostgreSQL Message Queue (PGMQ) extension as the message store.
PGMQ provides SQS-like semantics: messages are read with a visibility timeout, must be explicitly deleted to acknowledge, and become visible again automatically if not deleted before the timeout expires.
PGMQ Features supported by this transport¶
Long Polling¶
Long polling is enabled by setting the wait_time_seconds transport
option to a value greater than 0 (default 10). When set,
drain_events / _get_bulk use PGMQ’s read_with_poll and block
up to that many seconds before returning empty. Direct gets
(basic_get, SimpleQueue.get_nowait) always use read or
pop and do not long-poll.
Polling Interval¶
The polling_interval transport option (default: 1 second) controls
the client-side delay between consecutive polls when a poll returns no
messages. After a successful (non-empty) poll the next poll is
scheduled immediately; after an empty poll the transport waits
polling_interval seconds before trying again.
Batch Reads¶
Like the SQS transport, drain_events uses _get_bulk to request up
to prefetch_count messages per queue on each poll, which improves
throughput when tasks are short-lived.
Topic Routing¶
PGMQ’s native topic routing is used for fanout and topic exchanges.
Bindings are namespaced by exchange name so fanout and topic traffic do
not interfere. Fanout queues bind to kombu.fanout.<exchange>;
topic queues bind to kombu.topic.<exchange>.<pattern>. The exchange
name is encoded as one PGMQ routing-key segment ([A-Za-z0-9_-] only).
Routing keys keep ., * and #. Publishing to fanout or topic
exchanges calls send_topic once and PGMQ delivers copies to every
matching queue.
Direct exchanges continue to use Kombu’s standard virtual routing
(_put per queue). PGMQ topic patterns use the same * and
# wildcards as AMQP topic exchanges.
Delayed Delivery¶
Per-message delay is supported via the DelaySeconds message property
(seconds). This maps to PGMQ’s delay parameter on send and
send_topic. Kombu expiration/TTL is not supported.
FIFO Reads¶
Set fifo_mode to grouped or round_robin to use PGMQ’s
read_grouped or read_grouped_rr read paths. Create a FIFO index
with the x-pgmq-fifo-index queue argument or by enabling fifo_mode
on a transport that creates new queues.
NOTIFY / LISTEN¶
Set use_notify to True to enable PGMQ queue notifications and
use PostgreSQL LISTEN/NOTIFY as a wake-up signal between polls
instead of sleeping for the full polling_interval.
Partitioned Queues¶
Declare a queue with queue_arguments={'x-pgmq-partitioned': True} to
create a partitioned PGMQ queue. Optional x-pgmq-partition-interval
and x-pgmq-retention-interval arguments control partition sizing.
Connection String¶
pgmq://USERNAME:PASSWORD@HOST:PORT/DATABASE
pgmq://postgres:postgres@localhost:5432/postgres
Transport Options¶
queue_name_prefix: String prefix prepended to queue names.visibility_timeout: Seconds a message stays invisible after read (default1800).wait_time_seconds: Long-poll duration in seconds (default10).poll_interval_ms: Poll interval for long-poll reads (default100).init_extension: Create the PGMQ extension on connect (defaultTrue).pool_size: Connection pool size (default10).pool_timeout: Seconds to wait for a pooled connection (default is the psycopg pool default,30).conn_string: Optional full PostgreSQL connection string. When set, it overrides host/port/database/username/password from the URL.fifo_mode:groupedorround_robinto enable FIFO-ordered reads.use_notify: Enable PGMQNOTIFY/LISTENwake-ups (defaultFalse).notify_throttle_interval_ms: Throttle interval forenable_notify(default250).
Transport¶
- class kombu.transport.pgmq.Transport(client, **kwargs)[source]¶
PGMQ transport.
- class Channel(*args, **kwargs)¶
PGMQ channel.
- basic_ack(delivery_tag, multiple=False)¶
Acknowledge message.
- basic_cancel(consumer_tag)¶
Cancel consumer by consumer tag.
- basic_consume(queue, no_ack, callback, consumer_tag, *args, **kwargs)¶
Consume from queue.
- basic_get(queue, no_ack=False, **kwargs)¶
Get message by direct access (synchronous).
- basic_reject(delivery_tag, requeue=False)¶
Reject message.
- property conninfo¶
- default_init_extension = True¶
- default_notify_throttle_interval_ms = 250¶
- default_poll_interval_ms = 100¶
- default_pool_size = 10¶
- default_visibility_timeout = 1800¶
- default_wait_time_seconds = 10¶
- drain_events(timeout=None, callback=None, **kwargs)¶
Return payload message(s) from one of our queues.
- entity_name(name, table={33: 95, 34: 95, 35: 95, 36: 95, 37: 95, 38: 95, 39: 95, 40: 95, 41: 95, 42: 95, 43: 95, 44: 95, 45: 95, 46: 95, 47: 95, 58: 95, 59: 95, 60: 95, 61: 95, 62: 95, 63: 95, 64: 95, 91: 95, 92: 95, 93: 95, 94: 95, 96: 95, 123: 95, 124: 95, 125: 95, 126: 95}) str¶
Format an AMQP queue name into a valid PGMQ queue name.
- exchange_types = {'direct': <class 'kombu.transport.virtual.exchange.DirectExchange'>, 'fanout': <class 'kombu.transport.virtual.exchange.FanoutExchange'>, 'topic': <class 'kombu.transport.pgmq.PGMQTopicExchange'>}¶
mapping of exchange types and corresponding classes.
- queue_unbind(queue, exchange=None, routing_key='', arguments=None, **kwargs)¶
- supports_fanout = True¶
flag set if the channel supports fanout exchanges.
- property transport_options¶
- classmethod as_uri(uri: str, include_password: bool = False, mask: str = '**') str[source]¶
Customise the display format of the URI.
- can_parse_url = False¶
Set to True if
Connectionshould pass the URL unmodified.
- default_port = 5432¶
port number used when no port is specified.
- driver_name = 'pgmq'¶
Name of driver library (e.g. ‘py-amqp’, ‘redis’).
- driver_type = 'pgmq'¶
Type of driver, can be used to separate transports using the AMQP protocol (driver_type: ‘amqp’), Redis (driver_type: ‘redis’), etc…
- implements = {'asynchronous': False, 'batch_publish': False, 'exchange_type': frozenset({'direct', 'fanout', 'topic'}), 'heartbeats': False}¶
Channel¶
- class kombu.transport.pgmq.Channel(*args, **kwargs)[source]¶
PGMQ channel.
- property conninfo¶
- default_init_extension = True¶
- default_notify_throttle_interval_ms = 250¶
- default_poll_interval_ms = 100¶
- default_pool_size = 10¶
- default_visibility_timeout = 1800¶
- default_wait_time_seconds = 10¶
- drain_events(timeout=None, callback=None, **kwargs)[source]¶
Return payload message(s) from one of our queues.
- entity_name(name, table={33: 95, 34: 95, 35: 95, 36: 95, 37: 95, 38: 95, 39: 95, 40: 95, 41: 95, 42: 95, 43: 95, 44: 95, 45: 95, 46: 95, 47: 95, 58: 95, 59: 95, 60: 95, 61: 95, 62: 95, 63: 95, 64: 95, 91: 95, 92: 95, 93: 95, 94: 95, 96: 95, 123: 95, 124: 95, 125: 95, 126: 95}) str[source]¶
Format an AMQP queue name into a valid PGMQ queue name.
- exchange_types = {'direct': <class 'kombu.transport.virtual.exchange.DirectExchange'>, 'fanout': <class 'kombu.transport.virtual.exchange.FanoutExchange'>, 'topic': <class 'kombu.transport.pgmq.PGMQTopicExchange'>}¶
mapping of exchange types and corresponding classes.
- supports_fanout = True¶
flag set if the channel supports fanout exchanges.
- property transport_options¶