BrokerUsecase
faststream.broker.core.abc.BrokerUsecase #
BrokerUsecase(
url: Union[str, List[str]],
*args: Any,
protocol: str,
protocol_version: Optional[str] = None,
description: Optional[str] = None,
tags: Optional[
Sequence[Union[asyncapi.Tag, asyncapi.TagDict]]
] = None,
asyncapi_url: Union[str, List[str], None] = None,
apply_types: bool = True,
logger: Optional[logging.Logger] = access_logger,
log_level: int = logging.INFO,
log_fmt: Optional[
str
] = "%(asctime)s %(levelname)s - %(message)s",
dependencies: Sequence[Depends] = (),
middlewares: Optional[
Sequence[Callable[[MsgType], BaseMiddleware]]
] = None,
decoder: Optional[
CustomDecoder[StreamMessage[MsgType]]
] = None,
parser: Optional[
CustomParser[MsgType, StreamMessage[MsgType]]
] = None,
security: Optional[BaseSecurity] = None,
**kwargs: Any
)
Bases: ABC
, Generic[MsgType, ConnectionType]
, LoggingMixin
A class representing a broker use case.
METHOD | DESCRIPTION |
---|---|
__init__ | constructor method |
include_router | include a router in the broker |
include_routers | include multiple routers in the broker |
_resolve_connection_kwargs | resolve connection kwargs |
_wrap_handler | wrap a handler function |
_abc_start | start the broker |
_abc_close | close the broker |
_abc__close | close the broker connection |
_process_message | process a message |
subscriber | decorator to register a subscriber |
publisher | register a publisher |
_wrap_decode_message | wrap a message decoding function |
Note
The above docstring is autogenerated by docstring-gen library (https://docstring-gen.airt.ai)
Initialize a broker.
PARAMETER | DESCRIPTION |
---|---|
url | The URL or list of URLs to connect to. |
*args | Additional arguments. TYPE: |
protocol | The protocol to use for the connection. TYPE: |
protocol_version | The version of the protocol. |
description | A description of the broker. |
tags | Tags associated with the broker. |
apply_types | Whether to apply types to messages. TYPE: |
logger | The logger to use. |
log_level | The log level to use. |
log_fmt | The log format to use. TYPE: |
dependencies | Dependencies of the broker. TYPE: |
middlewares | Middlewares to use. TYPE: |
decoder | Custom decoder for messages. TYPE: |
parser | Custom parser for messages. TYPE: |
**kwargs | Additional keyword arguments. TYPE: |
Note
The above docstring is autogenerated by docstring-gen library (https://docstring-gen.airt.ai)
Source code in faststream/broker/core/abc.py
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 |
|
middlewares instance-attribute
#
middlewares: Sequence[Callable[[Any], BaseMiddleware]] = [
CriticalLogMiddleware(logger, log_level),
*midd_args,
]
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
publisher abstractmethod
#
Publishes a publisher.
PARAMETER | DESCRIPTION |
---|---|
key | The key associated with the publisher. TYPE: |
publisher | The publisher to be published. TYPE: |
RETURNS | DESCRIPTION |
---|---|
BasePublisher[MsgType] | The published publisher. |
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/abc.py
subscriber abstractmethod
#
subscriber(
*broker_args: Any,
retry: Union[bool, int] = False,
dependencies: Sequence[Depends] = (),
decoder: Optional[
CustomDecoder[StreamMessage[MsgType]]
] = None,
parser: Optional[
CustomParser[MsgType, StreamMessage[MsgType]]
] = None,
middlewares: Optional[
Sequence[
Callable[
[StreamMessage[MsgType]], BaseMiddleware
]
]
] = None,
filter: Filter[
StreamMessage[MsgType]
] = lambda: not m.processed,
_raw: bool = False,
_get_dependant: Optional[Any] = None,
**broker_kwargs: Any
) -> Callable[
[
Union[
Callable[P_HandlerParams, T_HandlerReturn],
HandlerCallWrapper[
MsgType, P_HandlerParams, T_HandlerReturn
],
]
],
HandlerCallWrapper[
MsgType, P_HandlerParams, T_HandlerReturn
],
]
This is a function decorator for subscribing to a message broker.
PARAMETER | DESCRIPTION |
---|---|
*broker_args | Positional arguments to be passed to the broker. TYPE: |
retry | Whether to retry the subscription if it fails. Can be a boolean or an integer specifying the number of retries. |
dependencies | Sequence of dependencies to be injected into the handler function. TYPE: |
decoder | Custom decoder function to decode the message. TYPE: |
parser | Custom parser function to parse the decoded message. TYPE: |
middlewares | Sequence of middleware functions to be applied to the message. TYPE: |
filter | Filter function to filter the messages to be processed. TYPE: |
_raw | Whether to return the raw message instead of the processed message. TYPE: |
_get_dependant | Optional parameter to get the dependant object. |
**broker_kwargs | Keyword arguments to be passed to the broker. TYPE: |
RETURNS | DESCRIPTION |
---|---|
Callable[[Union[Callable[P_HandlerParams, T_HandlerReturn], HandlerCallWrapper[MsgType, P_HandlerParams, T_HandlerReturn]]], HandlerCallWrapper[MsgType, P_HandlerParams, T_HandlerReturn]] | A callable object that can be used as a decorator for a handler function. |
RAISES | DESCRIPTION |
---|---|
RuntimeWarning | If the broker is already running. |
Note
The above docstring is autogenerated by docstring-gen library (https://docstring-gen.airt.ai)