RabbitRouter
faststream.rabbit.RabbitRouter #
RabbitRouter(
prefix: str = "",
handlers: Iterable[RabbitRoute] = (),
*,
dependencies: Iterable[Dependant] = (),
middlewares: Sequence[BrokerMiddleware[Any, Any]] = (),
routers: Iterable[RabbitRegistrator] = (),
parser: Optional[CustomCallable] = None,
decoder: Optional[CustomCallable] = None,
include_in_schema: bool | None = None,
ack_policy: AckPolicy = EMPTY,
)
Bases: RabbitRegistrator, BrokerRouter[IncomingMessage]
Includable to RabbitBroker router.
Initialized RabbitRouter.
| PARAMETER | DESCRIPTION |
|---|---|
prefix | String prefix to add to all subscribers queues. TYPE: |
handlers | Route object to include. TYPE: |
dependencies | Dependencies list ( TYPE: |
middlewares | Router middlewares to apply to all routers' publishers/subscribers. Defaults to (). TYPE: |
routers | Routers to apply to broker. Defaults to (). TYPE: |
parser | Parser to map original IncomingMessage Msg to FastStream one. Defaults to None. TYPE: |
decoder | Function to decode FastStream msg bytes body to python objects. Defaults to None. TYPE: |
include_in_schema | Whetever to include operation in AsyncAPI schema or not. TYPE: |
ack_policy | Default acknowledgement policy for all subscribers in this router. Can be overridden at the subscriber level. Defaults to None. TYPE: |
Source code in faststream/rabbit/broker/router.py
config instance-attribute #
add_middleware #
add_middleware(
middleware: BrokerMiddleware[Any, Any],
) -> None
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_middleware(
middleware: BrokerMiddleware[Any, Any],
) -> None
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: Union[str, RabbitQueue],
exchange: Union[str, RabbitExchange, None] = None,
*,
channel: Optional[Channel] = None,
consume_args: dict[str, Any] | None = None,
ack_policy: AckPolicy = EMPTY,
dependencies: Iterable[Dependant] = (),
parser: Optional[CustomCallable] = None,
decoder: Optional[CustomCallable] = None,
no_reply: bool = False,
persistent: bool = True,
title: str | None = None,
description: str | None = None,
include_in_schema: bool = True,
) -> RabbitSubscriber
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: |
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: |
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: 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: str | None = None,
priority: int | None = None,
persistent: bool = True,
title: str | None = None,
description: str | None = None,
schema: Any | None = None,
include_in_schema: bool = True,
headers: Optional[HeadersType] = None,
content_type: str | None = None,
content_encoding: str | None = None,
expiration: Optional[DateType] = None,
message_type: str | None = None,
user_id: str | None = None,
) -> RabbitPublisher
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: |
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
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 | |
include_router #
include_router(
router: RabbitRegistrator,
*,
prefix: str = "",
dependencies: Iterable[Dependant] = (),
middlewares: Sequence[BrokerMiddleware[Any, Any]] = (),
include_in_schema: bool | None = None,
) -> None