RabbitBroker
faststream.rabbit.RabbitBroker #
RabbitBroker(url: str | URL | None = 'amqp://guest:guest@localhost:5672/', *, host: str = None, port: int = None, login: str = None, password: str = None, virtualhost: str = None, ssl_options: SSLOptions | None = None, client_properties: FieldTable | None = None, max_consumers: int | None = None, protocol: str = None, protocol_version: str | None = '0.9.1', security: BaseSecurity | None = None, **kwargs: Any)
Bases: RabbitLoggingMixin
, BrokerAsyncUsecase[IncomingMessage, RobustConnection]
A RabbitMQ broker for FastAPI applications.
This class extends the base BrokerAsyncUsecase
and provides asynchronous support for RabbitMQ as a message broker.
PARAMETER | DESCRIPTION |
---|---|
url | The RabbitMQ connection URL. Defaults to "amqp://guest:guest@localhost:5672/". TYPE: |
max_consumers | Maximum number of consumers to limit message consumption. Defaults to None. |
protocol | The protocol to use (e.g., "amqp"). Defaults to "amqp". TYPE: |
protocol_version | The protocol version to use (e.g., "0.9.1"). Defaults to "0.9.1". |
**kwargs | Additional keyword arguments. TYPE: |
Initialize the RabbitBroker.
PARAMETER | DESCRIPTION |
---|---|
url | The RabbitMQ connection URL. Defaults to "amqp://guest:guest@localhost:5672/". TYPE: |
host | The RabbitMQ host. Defaults to None. |
port | The RabbitMQ port. Defaults to None. |
login | The RabbitMQ login. Defaults to None. |
password | The RabbitMQ password. Defaults to None. |
virtualhost | The RabbitMQ virtual host. Defaults to None. |
ssl_options | The RabbitMQ SSL options. Defaults to None. TYPE: |
client_properties | The RabbitMQ client properties. Defaults to None. TYPE: |
max_consumers | Maximum number of consumers to limit message consumption. Defaults to None. |
protocol | The protocol to use (e.g., "amqp"). Defaults to "amqp". TYPE: |
protocol_version | The protocol version to use (e.g., "0.9.1"). Defaults to "0.9.1". |
security | The security mechanism to use. Defaults to None. TYPE: |
**kwargs | Additional keyword arguments. TYPE: |
Source code in faststream/rabbit/broker.py
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 |
|
close async
#
close(exc_type: Optional[Type[BaseException]] = None, exc_val: Optional[BaseException] = None, exec_tb: Optional[TracebackType] = None) -> None
Closes the object.
PARAMETER | DESCRIPTION |
---|---|
exc_type | The type of the exception being handled, if any. TYPE: |
exc_val | The exception instance being handled, if any. TYPE: |
exec_tb | The traceback of the exception being handled, if any. TYPE: |
RETURNS | DESCRIPTION |
---|---|
None | None |
RAISES | DESCRIPTION |
---|---|
NotImplementedError | If the method is not implemented. |
Source code in faststream/broker/core/asynchronous.py
connect async
#
Connect to the RabbitMQ server.
PARAMETER | DESCRIPTION |
---|---|
*args | Additional positional arguments. TYPE: |
**kwargs | Additional keyword arguments. TYPE: |
RETURNS | DESCRIPTION |
---|---|
RobustConnection | aio_pika.RobustConnection: The RabbitMQ connection instance. |
Source code in faststream/rabbit/broker.py
declare_exchange async
#
declare_exchange(exchange: RabbitExchange) -> RobustExchange
Declare a RabbitMQ exchange.
PARAMETER | DESCRIPTION |
---|---|
exchange | The RabbitMQ exchange to declare. TYPE: |
RETURNS | DESCRIPTION |
---|---|
RobustExchange | aio_pika.RobustExchange: The declared RabbitMQ exchange. |
RAISES | DESCRIPTION |
---|---|
RuntimeError | If the declarer is not initialized in the |
Source code in faststream/rabbit/broker.py
declare_queue async
#
declare_queue(queue: RabbitQueue) -> RobustQueue
Declare a RabbitMQ queue.
PARAMETER | DESCRIPTION |
---|---|
queue | The RabbitMQ queue to declare. TYPE: |
RETURNS | DESCRIPTION |
---|---|
RobustQueue | aio_pika.RobustQueue: The declared RabbitMQ queue. |
RAISES | DESCRIPTION |
---|---|
RuntimeError | If the declarer is not initialized in the |
Source code in faststream/rabbit/broker.py
include_router #
include_router(router: BrokerRouter[Any, MsgType]) -> None
Includes a router in the current object.
PARAMETER | DESCRIPTION |
---|---|
router | The router to be included. TYPE: |
RETURNS | DESCRIPTION |
---|---|
None | None |
Source code in faststream/broker/core/abc.py
include_routers #
include_routers(*routers: BrokerRouter[Any, MsgType]) -> None
Includes routers in the current object.
PARAMETER | DESCRIPTION |
---|---|
*routers | Variable length argument list of routers to include. TYPE: |
RETURNS | DESCRIPTION |
---|---|
None | None |
Source code in faststream/broker/core/abc.py
publish async
#
Publish a message to the RabbitMQ broker.
PARAMETER | DESCRIPTION |
---|---|
*args | Additional positional arguments. TYPE: |
**kwargs | Additional keyword arguments. TYPE: |
RETURNS | DESCRIPTION |
---|---|
ConfirmationFrameType | SendableMessage | Union[aiormq.abc.ConfirmationFrameType, SendableMessage]: The confirmation frame or the response message. |
Source code in faststream/rabbit/broker.py
publisher #
publisher(queue: RabbitQueue | str = '', exchange: RabbitExchange | str | None = None, *, routing_key: str = '', mandatory: bool = True, immediate: bool = False, timeout: TimeoutType = None, persist: bool = False, reply_to: str | None = None, title: str | None = None, description: str | None = None, schema: Any | None = None, include_in_schema: bool = True, priority: int | None = None, **message_kwargs: Any) -> Publisher
Define a message publisher.
PARAMETER | DESCRIPTION |
---|---|
queue | The name of the RabbitMQ queue. Defaults to "". TYPE: |
exchange | The name of the RabbitMQ exchange. Defaults to None. TYPE: |
routing_key | The routing key for messages. Defaults to "". TYPE: |
mandatory | Whether the message is mandatory. Defaults to True. TYPE: |
immediate | Whether the message should be sent immediately. Defaults to False. TYPE: |
timeout | Timeout for message publishing. Defaults to None. TYPE: |
persist | Whether to persist messages. Defaults to False. TYPE: |
reply_to | The reply-to queue name. Defaults to None. |
title | Title for AsyncAPI docs. |
description | Description for AsyncAPI docs. |
schema | Schema for AsyncAPI docs. |
include_in_schema | Whether to include the publisher in AsyncAPI docs. TYPE: |
priority | Priority for the message. |
**message_kwargs | Additional message properties and content. TYPE: |
RETURNS | DESCRIPTION |
---|---|
Publisher | A message publisher instance. TYPE: |
Source code in faststream/rabbit/broker.py
start async
#
Start the RabbitMQ broker.
RAISES | DESCRIPTION |
---|---|
RuntimeError | If the declarer is not initialized in the |
Source code in faststream/rabbit/broker.py
subscriber #
subscriber(queue: str | RabbitQueue, exchange: str | RabbitExchange | None = None, *, consume_args: AnyDict | None = None, reply_config: ReplyConfig | None = None, dependencies: Sequence[Depends] = (), parser: CustomParser[IncomingMessage, RabbitMessage] | None = None, decoder: CustomDecoder[RabbitMessage] | None = None, middlewares: Sequence[Callable[[IncomingMessage], BaseMiddleware]] | None = None, filter: Filter[RabbitMessage] = default_filter, no_ack: bool = False, title: str | None = None, description: str | None = None, include_in_schema: bool = True, **original_kwargs: Any) -> Callable[[Callable[P_HandlerParams, T_HandlerReturn]], HandlerCallWrapper[IncomingMessage, P_HandlerParams, T_HandlerReturn]]
Decorator to define a message subscriber.
PARAMETER | DESCRIPTION |
---|---|
queue | The name of the RabbitMQ queue. TYPE: |
exchange | The name of the RabbitMQ exchange. Defaults to None. TYPE: |
consume_args | Additional arguments for message consumption. TYPE: |
reply_config | The reply configuration for the message. TYPE: |
dependencies | Additional dependencies for the handler function. Defaults to (). TYPE: |
parser | Optional custom parser for parsing the input. Defaults to None. TYPE: |
decoder | Optional custom decoder for decoding the input. Defaults to None. TYPE: |
middlewares | Optional sequence of middlewares to be applied. Defaults to None. TYPE: |
filter | Optional filter for filtering messages. Defaults to default_filter. TYPE: |
no_ack | Whether not to ack/nack/reject messages. TYPE: |
title | Title for AsyncAPI docs. |
description | Description for AsyncAPI docs. |
include_in_schema | Whether to include the handler in AsyncAPI docs. TYPE: |
**original_kwargs | Additional keyword arguments. TYPE: |
RETURNS | DESCRIPTION |
---|---|
Callable | A decorator function for defining message subscribers. TYPE: |
Source code in faststream/rabbit/broker.py
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 384 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 |
|