KafkaRouter
faststream.kafka.shared.router.KafkaRouter #
KafkaRouter(
prefix: str = "",
handlers: Sequence[
BrokerRoute[ConsumerRecord, SendableMessage]
] = (),
**kwargs: Any
)
Bases: BrokerRouter[str, ConsumerRecord]
A class to represent a Kafka router.
METHOD | DESCRIPTION |
---|---|
subscriber | decorator for subscribing to topics and handling messages |
Initialize the class.
PARAMETER | DESCRIPTION |
---|---|
prefix | Prefix string. TYPE: |
handlers | Sequence of KafkaRoute objects. TYPE: |
**kwargs | Additional keyword arguments. TYPE: |
Source code in faststream/kafka/shared/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 #
subscriber(
*topics: str, **broker_kwargs: Any
) -> Callable[
[Callable[P_HandlerParams, T_HandlerReturn]],
HandlerCallWrapper[
ConsumerRecord, P_HandlerParams, T_HandlerReturn
],
]
A function to subscribe to topics.
PARAMETER | DESCRIPTION |
---|---|
*topics | variable number of topic names DEFAULT: |
**broker_kwargs | keyword arguments for the broker DEFAULT: |
RETURNS | DESCRIPTION |
---|---|
Callable[[Callable[P_HandlerParams, T_HandlerReturn]], HandlerCallWrapper[ConsumerRecord, P_HandlerParams, T_HandlerReturn]] | A callable function that wraps the handler function |