RabbitBroker
faststream.rabbit.broker.RabbitBroker
#
RabbitBroker(
url="amqp://guest:guest@localhost:5672/",
*,
host=None,
port=None,
virtualhost=None,
ssl_options=None,
client_properties=None,
timeout=None,
fail_fast=True,
reconnect_interval=5.0,
default_channel=None,
app_id=SERVICE_NAME,
graceful_timeout=None,
decoder=None,
parser=None,
dependencies=(),
middlewares=(),
routers=(),
security=None,
specification_url=None,
protocol=None,
protocol_version="0.9.1",
description=None,
tags=(),
logger=EMPTY,
log_level=INFO,
apply_types=True,
serializer=EMPTY,
provider=None,
context=None,
)
Bases: RabbitRegistrator
, BrokerUsecase[IncomingMessage, RobustConnection]
A class to represent a RabbitMQ broker.
Initialize the RabbitBroker.
PARAMETER | DESCRIPTION |
---|---|
url
|
RabbitMQ destination location to connect.
TYPE:
|
host
|
Destination host. This option overrides
TYPE:
|
port
|
Destination port. This option overrides
TYPE:
|
virtualhost
|
RabbitMQ virtual host to use in the current broker connection.
TYPE:
|
ssl_options
|
Extra ssl options to establish connection.
TYPE:
|
client_properties
|
Add custom client capability.
TYPE:
|
timeout
|
Connection establishment timeout.
TYPE:
|
fail_fast
|
Broker startup raises
TYPE:
|
reconnect_interval
|
Time to sleep between reconnection attempts.
TYPE:
|
default_channel
|
Default channel settings to use.
TYPE:
|
app_id
|
Application name to mark outgoing messages by.
TYPE:
|
graceful_timeout
|
Graceful shutdown timeout. Broker waits for all running subscribers completion before shut down.
TYPE:
|
decoder
|
Custom decoder object.
TYPE:
|
parser
|
Custom parser object.
TYPE:
|
dependencies
|
Dependencies to apply to all broker subscribers.
TYPE:
|
middlewares
|
Middlewares to apply to all broker publishers/subscribers.
TYPE:
|
routers
|
RabbitRouters to build a broker with.
TYPE:
|
security
|
Security options to connect broker and generate AsyncAPI server security information.
TYPE:
|
specification_url
|
AsyncAPI hardcoded server addresses. Use
TYPE:
|
protocol
|
AsyncAPI server protocol.
TYPE:
|
protocol_version
|
AsyncAPI server protocol version.
TYPE:
|
description
|
AsyncAPI server description.
TYPE:
|
tags
|
AsyncAPI server tags. |
logger
|
User-specified logger to pass into Context and log service messages.
TYPE:
|
log_level
|
Service messages log level.
TYPE:
|
apply_types
|
Whether to use FastDepends or not.
TYPE:
|
serializer
|
FastDepends-compatible serializer to validate incoming messages.
TYPE:
|
provider
|
Provider for FastDepends.
TYPE:
|
context
|
Context for FastDepends.
TYPE:
|
Source code in faststream/rabbit/broker/broker.py
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 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 |
|
publish_batch
async
#
add_middleware
#
Append BrokerMiddleware to the end of middlewares list.
Current middleware will be used as a most inner of the stack.
Source code in faststream/_internal/broker/registrator.py
insert_middleware
#
Insert BrokerMiddleware to the start of middlewares list.
Current middleware will be used as a most outer of the stack.
Source code in faststream/_internal/broker/registrator.py
subscriber
#
subscriber(
queue,
exchange=None,
*,
channel=None,
consume_args=None,
no_ack=EMPTY,
ack_policy=EMPTY,
dependencies=(),
parser=None,
decoder=None,
middlewares=(),
no_reply=False,
persistent=True,
title=None,
description=None,
include_in_schema=True,
)
Subscribe a handler to a RabbitMQ queue.
PARAMETER | DESCRIPTION |
---|---|
queue
|
RabbitMQ queue to listen. FastStream declares and binds queue object to
TYPE:
|
exchange
|
RabbitMQ exchange to bind queue to. Uses default exchange if not presented. FastStream declares exchange object automatically by default.
TYPE:
|
channel
|
Channel to use for consuming messages.
TYPE:
|
consume_args
|
Extra consumer arguments to use in
TYPE:
|
no_ack
|
Whether to disable FastStream auto acknowledgement logic or not.
TYPE:
|
ack_policy
|
Acknowledgement policy for message processing.
TYPE:
|
dependencies
|
Dependencies list (
TYPE:
|
parser
|
Parser to map original IncomingMessage Msg to FastStream one.
TYPE:
|
decoder
|
Function to decode FastStream msg bytes body to python objects.
TYPE:
|
middlewares
|
Subscriber middlewares to wrap incoming message processing.
TYPE:
|
no_reply
|
Whether to disable FastStream RPC and Reply To auto responses or not.
TYPE:
|
title
|
AsyncAPI subscriber object title.
TYPE:
|
description
|
AsyncAPI subscriber object description. Uses decorated docstring as default.
TYPE:
|
include_in_schema
|
Whether to include operation in AsyncAPI schema or not.
TYPE:
|
persistent
|
Whether to make the subscriber persistent or not.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
RabbitSubscriber
|
The subscriber specification object.
TYPE:
|
Source code in faststream/rabbit/broker/registrator.py
publisher
#
publisher(
queue="",
exchange=None,
*,
routing_key="",
mandatory=True,
immediate=False,
timeout=None,
persist=False,
reply_to=None,
priority=None,
persistent=True,
middlewares=(),
title=None,
description=None,
schema=None,
include_in_schema=True,
headers=None,
content_type=None,
content_encoding=None,
expiration=None,
message_type=None,
user_id=None,
)
Creates long-living and AsyncAPI-documented publisher object.
You can use it as a handler decorator (handler should be decorated by @broker.subscriber(...)
too) - @broker.publisher(...)
.
In such case publisher will publish your handler return value.
Or you can create a publisher object to call it lately - broker.publisher(...).publish(...)
.
PARAMETER | DESCRIPTION |
---|---|
queue
|
Default message routing key to publish with.
TYPE:
|
exchange
|
Target exchange to publish message to.
TYPE:
|
routing_key
|
Default message routing key to publish with.
TYPE:
|
mandatory
|
Client waits for confirmation that the message is placed to some queue. RabbitMQ returns message to client if there is no suitable queue.
TYPE:
|
immediate
|
Client expects that there is a consumer ready to take the message to work. RabbitMQ returns message to client if there is no suitable consumer.
TYPE:
|
timeout
|
Send confirmation time from RabbitMQ.
TYPE:
|
persist
|
Restore the message on RabbitMQ reboot.
TYPE:
|
reply_to
|
Reply message routing key to send with (always sending to default exchange).
TYPE:
|
priority
|
The message priority (0 by default).
TYPE:
|
middlewares
|
Publisher middlewares to wrap outgoing messages.
TYPE:
|
title
|
AsyncAPI publisher object title.
TYPE:
|
description
|
AsyncAPI publisher object description.
TYPE:
|
schema
|
AsyncAPI publishing message type. Should be any python-native
object annotation or
TYPE:
|
include_in_schema
|
Whether to include operation in AsyncAPI schema or not.
TYPE:
|
headers
|
Message headers to store meta-information. Can be overridden
by
TYPE:
|
content_type
|
Message content-type header. Used by application, not core RabbitMQ. Will be set automatically if not specified.
TYPE:
|
content_encoding
|
Message body content encoding, e.g. gzip.
TYPE:
|
expiration
|
Message expiration (lifetime) in seconds (or datetime or timedelta).
TYPE:
|
message_type
|
Application-specific message type, e.g. orders.created.
TYPE:
|
user_id
|
Publisher connection User ID, validated if set.
TYPE:
|
persistent
|
Whether to make the publisher persistent or not.
TYPE:
|
Source code in faststream/rabbit/broker/registrator.py
120 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 |
|
include_router
#
Source code in faststream/rabbit/broker/registrator.py
include_routers
#
connect
async
#
stop
async
#
Source code in faststream/rabbit/broker/broker.py
close
async
#
Source code in faststream/rabbit/broker/broker.py
start
async
#
publish
async
#
publish(
message=None,
queue="",
exchange=None,
*,
routing_key="",
mandatory=True,
immediate=False,
timeout=None,
persist=False,
reply_to=None,
correlation_id=None,
headers=None,
content_type=None,
content_encoding=None,
expiration=None,
message_id=None,
timestamp=None,
message_type=None,
user_id=None,
priority=None,
)
Publish message directly.
This method allows you to publish message in not AsyncAPI-documented way. You can use it in another frameworks applications or to publish messages from time to time.
Please, use @broker.publisher(...)
or broker.publisher(...).publish(...)
instead in a regular way.
PARAMETER | DESCRIPTION |
---|---|
message
|
Message body to send.
TYPE:
|
queue
|
Message routing key to publish with.
TYPE:
|
exchange
|
Target exchange to publish message to.
TYPE:
|
routing_key
|
Message routing key to publish with. Overrides
TYPE:
|
mandatory
|
Client waits for confirmation that the message is placed to some queue. RabbitMQ returns message to client if there is no suitable queue.
TYPE:
|
immediate
|
Client expects that there is consumer ready to take the message to work. RabbitMQ returns message to client if there is no suitable consumer.
TYPE:
|
timeout
|
Send confirmation time from RabbitMQ.
TYPE:
|
persist
|
Restore the message on RabbitMQ reboot.
TYPE:
|
reply_to
|
Reply message routing key to send with (always sending to default exchange).
TYPE:
|
correlation_id
|
Manual message correlation_id setter. correlation_id is a useful option to trace messages.
TYPE:
|
headers
|
Message headers to store metainformation.
TYPE:
|
content_type
|
Message content-type header. Used by application, not core RabbitMQ. Will be set automatically if not specified.
TYPE:
|
content_encoding
|
Message body content encoding, e.g. gzip.
TYPE:
|
expiration
|
Message expiration (lifetime) in seconds (or datetime or timedelta).
TYPE:
|
message_id
|
Arbitrary message id. Generated automatically if not present.
TYPE:
|
timestamp
|
Message publish timestamp. Generated automatically if not presented.
TYPE:
|
message_type
|
Application-specific message type, e.g. orders.created.
TYPE:
|
user_id
|
Publisher connection User ID, validated if set.
TYPE:
|
priority
|
The message priority (0 by default).
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Optional[ConfirmationFrameType]
|
An optional |
Source code in faststream/rabbit/broker/broker.py
280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 |
|
request
async
#
request(
message=None,
queue="",
exchange=None,
*,
routing_key="",
mandatory=True,
immediate=False,
timeout=None,
persist=False,
correlation_id=None,
headers=None,
content_type=None,
content_encoding=None,
expiration=None,
message_id=None,
timestamp=None,
message_type=None,
user_id=None,
priority=None,
)
Make a synchronous request to RabbitMQ.
This method uses Direct Reply-To pattern to send a message and wait for a reply. It is a blocking call and will wait for a reply until timeout.
PARAMETER | DESCRIPTION |
---|---|
message
|
Message body to send.
TYPE:
|
queue
|
Message routing key to publish with.
TYPE:
|
exchange
|
Target exchange to publish message to.
TYPE:
|
routing_key
|
Message routing key to publish with. Overrides
TYPE:
|
mandatory
|
Client waits for confirmation that the message is placed to some queue.
TYPE:
|
immediate
|
Client expects that there is a consumer ready to take the message to work.
TYPE:
|
timeout
|
Send confirmation time from RabbitMQ.
TYPE:
|
persist
|
Restore the message on RabbitMQ reboot.
TYPE:
|
correlation_id
|
Manual message correlation_id setter. correlation_id is a useful option to trace messages.
TYPE:
|
headers
|
Message headers to store metainformation.
TYPE:
|
content_type
|
Message content-type header. Used by application, not core RabbitMQ.
TYPE:
|
content_encoding
|
Message body content encoding, e.g. gzip.
TYPE:
|
expiration
|
Message expiration (lifetime) in seconds (or datetime or timedelta).
TYPE:
|
message_id
|
Arbitrary message id. Generated automatically if not present.
TYPE:
|
timestamp
|
Message publish timestamp. Generated automatically if not present.
TYPE:
|
message_type
|
Application-specific message type, e.g. orders.created.
TYPE:
|
user_id
|
Publisher connection User ID, validated if set.
TYPE:
|
priority
|
The message priority (0 by default).
TYPE:
|
Source code in faststream/rabbit/broker/broker.py
385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 |
|
declare_queue
async
#
Declares queue object in RabbitMQ.
declare_exchange
async
#
Declares exchange object in RabbitMQ.