BrokerRouter
faststream.broker.router.BrokerRouter #
BrokerRouter(
prefix: str = "",
handlers: Sequence[
BrokerRoute[MsgType, SendableMessage]
] = (),
dependencies: Sequence[Depends] = (),
middlewares: Optional[
Sequence[
Callable[
[StreamMessage[MsgType]],
AsyncContextManager[None],
]
]
] = None,
parser: Optional[
CustomParser[MsgType, StreamMessage[MsgType]]
] = None,
decoder: Optional[
CustomDecoder[StreamMessage[MsgType]]
] = None,
)
Bases: Generic[PublisherKeyType, MsgType]
A generic class representing a broker router.
METHOD | DESCRIPTION |
---|---|
_get_publisher_key | abstract method to get the publisher key |
_update_publisher_prefix | abstract method to update the publisher prefix |
__init__ | constructor method |
subscriber | abstract method to define a subscriber |
_wrap_subscriber | method to wrap a subscriber function |
publisher | abstract method to define a publisher |
include_router | method to include a router |
include_routers | method to include multiple routers |
Note
The above docstring is autogenerated by docstring-gen library (https://docstring-gen.airt.ai)
Initialize a class object.
PARAMETER | DESCRIPTION |
---|---|
prefix | Prefix for the object. TYPE: |
handlers | Handlers for the object. TYPE: |
dependencies | Dependencies for the object. TYPE: |
middlewares | Middlewares for the object. TYPE: |
parser | Parser for the object. TYPE: |
decoder | Decoder for the object. TYPE: |
Note
The above docstring is autogenerated by docstring-gen library (https://docstring-gen.airt.ai)
Source code in faststream/broker/router.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/router.py
include_routers #
Includes routers in the 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/router.py
publisher abstractmethod
#
Publishes a message.
PARAMETER | DESCRIPTION |
---|---|
subj | Subject of the message TYPE: |
*args | Additional arguments TYPE: |
**kwargs | Additional keyword arguments TYPE: |
RETURNS | DESCRIPTION |
---|---|
BasePublisher[MsgType] | The published message |
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/router.py
subscriber abstractmethod
#
subscriber(
subj: str,
*args: Any,
dependencies: Sequence[Depends] = (),
middlewares: Optional[
Sequence[
Callable[
[StreamMessage[MsgType]],
AsyncContextManager[None],
]
]
] = None,
parser: Optional[
CustomParser[MsgType, StreamMessage[MsgType]]
] = None,
decoder: Optional[
CustomDecoder[StreamMessage[MsgType]]
] = None,
**kwargs: Any
) -> Callable[
[Callable[P_HandlerParams, T_HandlerReturn]],
HandlerCallWrapper[
MsgType, P_HandlerParams, T_HandlerReturn
],
]
A function to subscribe to a subject.
PARAMETER | DESCRIPTION |
---|---|
subj | subject to subscribe to
|
*args | additional arguments DEFAULT: |
dependencies | sequence of dependencies DEFAULT: |
middlewares | optional sequence of middlewares DEFAULT: |
parser | optional custom parser DEFAULT: |
decoder | optional custom decoder DEFAULT: |
**kwargs | additional keyword arguments DEFAULT: |
RETURNS | DESCRIPTION |
---|---|
Callable[[Callable[P_HandlerParams, T_HandlerReturn]], HandlerCallWrapper[MsgType, P_HandlerParams, T_HandlerReturn]] | A callable handler function |
RAISES | DESCRIPTION |
---|---|
NotImplementedError | If the function is not implemented |
Note
The above docstring is autogenerated by docstring-gen library (https://docstring-gen.airt.ai)