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, include_in_schema: Optional[bool] = 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 |
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: |
include_in_schema | Whether to include the object in the schema. |
Source code in faststream/broker/router.py
include_router #
include_router(router: BrokerRouter[PublisherKeyType, 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/router.py
include_routers #
include_routers(*routers: BrokerRouter[PublisherKeyType, MsgType]) -> None
Includes routers in the object.
PARAMETER | DESCRIPTION |
---|---|
*routers | Variable length argument list of routers to include. TYPE: |
RETURNS | DESCRIPTION |
---|---|
None | None |
Source code in faststream/broker/router.py
publisher abstractmethod
#
publisher(subj: str, *args: Any, **kwargs: Any) -> BasePublisher[MsgType]
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 |
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, include_in_schema: Optional[bool] = 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: |
include_in_schema | whether to include the object in the schema 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 |