RabbitBroker
faststream.rabbit.broker.RabbitBroker #
RabbitBroker(
url: Union[
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: Optional[aio_pika.abc.SSLOptions] = None,
client_properties: Optional[FieldTable] = None,
max_consumers: Optional[int] = None,
protocol: str = None,
protocol_version: Optional[str] = "0.9.1",
security: Optional[BaseSecurity] = 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: |
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: |
Source code in faststream/rabbit/broker.py
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. |
Note
The above docstring is autogenerated by docstring-gen library (https://docstring-gen.airt.ai)
Source code in faststream/broker/core/asyncronous.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 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 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 #
Includes a router in the current object.
PARAMETER | DESCRIPTION |
---|---|
router | The router to be included. TYPE: |
RETURNS | DESCRIPTION |
---|---|
None | None |
Note
The above docstring is autogenerated by docstring-gen library (https://docstring-gen.airt.ai)
Source code in faststream/broker/core/abc.py
include_routers #
Includes routers in the current object.
PARAMETER | DESCRIPTION |
---|---|
*routers | Variable length argument list of routers to include. TYPE: |
RETURNS | DESCRIPTION |
---|---|
None | None |
Note
The above docstring is autogenerated by docstring-gen library (https://docstring-gen.airt.ai)
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 |
---|---|
Union[ConfirmationFrameType, SendableMessage] | Union[aiormq.abc.ConfirmationFrameType, SendableMessage]: The confirmation frame or the response message. |
Source code in faststream/rabbit/broker.py
publisher #
publisher(
queue: Union[RabbitQueue, str] = "",
exchange: Union[RabbitExchange, str, None] = None,
*,
routing_key: str = "",
mandatory: bool = True,
immediate: bool = False,
timeout: TimeoutType = None,
persist: bool = False,
reply_to: Optional[str] = None,
title: Optional[str] = None,
description: Optional[str] = None,
schema: Optional[Any] = None,
priority: Optional[int] = 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. |
**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: Union[str, RabbitQueue],
exchange: Union[str, RabbitExchange, None] = None,
*,
consume_args: Optional[AnyDict] = None,
dependencies: Sequence[Depends] = (),
parser: Optional[
CustomParser[
aio_pika.IncomingMessage, RabbitMessage
]
] = None,
decoder: Optional[CustomDecoder[RabbitMessage]] = None,
middlewares: Optional[
Sequence[
Callable[
[aio_pika.IncomingMessage], BaseMiddleware
]
]
] = None,
filter: Filter[RabbitMessage] = default_filter,
title: Optional[str] = None,
description: Optional[str] = None,
**original_kwargs: Any
) -> Callable[
[Callable[P_HandlerParams, T_HandlerReturn]],
HandlerCallWrapper[
aio_pika.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: |
title | Title for AsyncAPI docs. |
description | Description for AsyncAPI docs. |
RETURNS | DESCRIPTION |
---|---|
Callable | A decorator function for defining message subscribers. TYPE: |
Source code in faststream/rabbit/broker.py
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 384 385 386 |
|