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: {prefix}.{alias}. Also, it affects the subscription name. A subscription will be {prefix}.{subscription_name}.
TYPE:
|
project_id
|
An alternative project id to the router's project id. All the publishers and subscriber created with this router will use this attribute instead of the project id set at router-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 for 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
|
Automatically creates the topic and subscription if they do not exists.
TYPE:
|
autoupdate
|
Automatically updates 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
|
Enables message ordering. It can only be set when creating the subscription.
TYPE:
|
enable_exactly_once_delivery
|
Enables exactly-once delivery. It can only be set when creating the subscription.
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 at a time.
TYPE:
|
middlewares
|
A sequence of middlewares to apply to the subscriber. It is subscriber specific, not application-wide.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
SubscribedCallable
|
A decorator that registers the function as a subscriber. |
Source code in fastpubsub/router.py
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 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 | |
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
|
Automatically creates 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 middleware instantiation.
TYPE:
|
kwargs
|
The keyword arguments used on middleware instantiation.
TYPE:
|