PubSubBroker class¶
fastpubsub.PubSubBroker
¶
Manages the connection with PubSub Broker.
Initializes the PubSubBroker.
| PARAMETER | DESCRIPTION |
|---|---|
project_id
|
The Google Cloud project ID.
TYPE:
|
shutdown_timeout
|
Maximum time to wait for in-flight messages per subscription during shutdown (seconds). Defaults to 30 seconds.
TYPE:
|
routers
|
A sequence of routers to include.
TYPE:
|
middlewares
|
A sequence of middlewares to apply to all messages incoming to subscribers and publishers.
TYPE:
|
Source code in fastpubsub/broker.py
router
instance-attribute
¶
router = PubSubRouter(
routers=routers,
project_id=project_id,
middlewares=middlewares,
)
subscriber
¶
subscriber(
alias,
*,
topic_name,
subscription_name,
project_id="",
autocreate=True,
autoupdate=False,
filter_expression="",
dead_letter_topic="",
max_delivery_attempts=5,
ack_deadline_seconds=60,
enable_message_ordering=False,
enable_exactly_once_delivery=False,
min_backoff_delay_secs=10,
max_backoff_delay_secs=600,
max_messages=1000,
middlewares=(),
)
Decorator to register a function as a subscriber.
| PARAMETER | DESCRIPTION |
|---|---|
alias
|
A unique name for the subscriber. You can use this alias to select which subscription to use on the CLI.
TYPE:
|
topic_name
|
The name of the topic to subscribe to.
TYPE:
|
subscription_name
|
The name of the subscription attached to the topic.
TYPE:
|
project_id
|
An alternative project id to create a subscription and consume messages from. If set the broker project id will be ignored.
TYPE:
|
autocreate
|
Whether to automatically create the topic and subscription if they do not exists.
TYPE:
|
autoupdate
|
Whether to automatically update the subscription.
TYPE:
|
filter_expression
|
A filter expression to apply to the subscription to filter messages.
TYPE:
|
dead_letter_topic
|
The name of the dead-letter topic.
TYPE:
|
max_delivery_attempts
|
The maximum number of delivery attempts before sending the message to the dead-letter.
TYPE:
|
ack_deadline_seconds
|
The acknowledgment deadline in seconds.
TYPE:
|
enable_message_ordering
|
Whether the message must be delivered in order.
TYPE:
|
enable_exactly_once_delivery
|
Whether to enable exactly-once delivery.
TYPE:
|
min_backoff_delay_secs
|
The minimum backoff delay in seconds.
TYPE:
|
max_backoff_delay_secs
|
The maximum backoff delay in seconds.
TYPE:
|
max_messages
|
The maximum number of messages to fetch from the broker.
TYPE:
|
middlewares
|
A sequence of middlewares to apply only to the subscriber.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
SubscribedCallable
|
A decorator that registers the function as a subscriber. |
Source code in fastpubsub/broker.py
publisher
¶
Returns a publisher for the given topic.
| PARAMETER | DESCRIPTION |
|---|---|
topic_name
|
The name of the topic.
TYPE:
|
project_id
|
An alternative project id to publish messages. If set the broker's project id will be ignored.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Publisher
|
A publisher for the given topic. |
Source code in fastpubsub/broker.py
publish
async
¶
Publishes a message to the given topic.
| PARAMETER | DESCRIPTION |
|---|---|
topic_name
|
The name of the topic.
TYPE:
|
data
|
The message data. |
project_id
|
An alternative project id to publish messages. If set the broker's project id will be ignored.
TYPE:
|
ordering_key
|
The ordering key for the message.
TYPE:
|
attributes
|
A dictionary of message attributes. |
autocreate
|
Whether to automatically create the topic if it does not exists.
TYPE:
|
Source code in fastpubsub/broker.py
include_router
¶
Includes a router in the broker.
| PARAMETER | DESCRIPTION |
|---|---|
router
|
The router to include.
TYPE:
|
include_middleware
¶
Includes a middleware in the broker.
| PARAMETER | DESCRIPTION |
|---|---|
middleware
|
The middleware to include.
TYPE:
|
args
|
The positional arguments used on the middleware instantiation.
TYPE:
|
kwargs
|
The keyword arguments used on the middleware instantiation.
TYPE:
|
Source code in fastpubsub/broker.py
start
async
¶
Starts the broker.
Source code in fastpubsub/broker.py
alive
¶
Checks if the message consumer tasks are alive.
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if they are alive, False otherwise. |
Source code in fastpubsub/broker.py
ready
¶
Checks if the message consumer tasks are ready.
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if they are ready, False otherwise. |