PubSubRouter class¶
fastpubsub.PubSubRouter
¶
A router for organizing publishers and subscribers.
Initializes the PubSubRouter.
| PARAMETER | DESCRIPTION |
|---|---|
prefix
|
A prefix to apply to all subscribers and publishers in the
router. If set, the subscriber alias will be:
TYPE:
|
project_id
|
An alternative project id to the broker's project id. All the publishers and subscriber created with this router will use this attribute instead of the project id set at broker-level.
TYPE:
|
routers
|
A sequence of children routers to include.
TYPE:
|
middlewares
|
A sequence of middlewares to apply to all subscribers in this router and its children.
TYPE:
|
Source code in fastpubsub/router.py
include_router
¶
Includes a child router in the current router.
| PARAMETER | DESCRIPTION |
|---|---|
router
|
The router to include.
TYPE:
|
Source code in fastpubsub/router.py
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 router 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/router.py
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 | |
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 router project id will be ignored.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Publisher
|
A publisher for the given topic. |
Source code in fastpubsub/router.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 router 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/router.py
include_middleware
¶
Includes a middleware in the router.
| 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:
|