LogicHandler
faststream.kafka.handler.LogicHandler #
LogicHandler(
*topics: str,
log_context_builder: Callable[
[StreamMessage[Any]], Dict[str, str]
],
graceful_timeout: Optional[float] = None,
group_id: Optional[str] = None,
client_id: str = "faststream-" + __version__,
builder: Callable[..., AIOKafkaConsumer],
is_manual: bool = False,
batch: bool = False,
batch_timeout_ms: int = 200,
max_records: Optional[int] = None,
title: Optional[str] = None,
description: Optional[str] = None,
include_in_schema: bool = True
)
Bases: AsyncHandler[ConsumerRecord]
A class to handle logic for consuming messages from Kafka.
METHOD | DESCRIPTION |
---|---|
__init__ | constructor method for the LogicHandler class |
start | method to start consuming messages from Kafka |
close | method to close the Kafka consumer and cancel the consuming task |
add_call | method to add a handler call for processing consumed messages |
_consume | method to consume messages from Kafka and call the appropriate handler |
Initialize a Kafka consumer for the specified topics.
PARAMETER | DESCRIPTION |
---|---|
*topics | Variable length argument list of topics to consume from. TYPE: |
group_id | Optional group ID for the consumer. |
client_id | Client ID for the consumer. TYPE: |
builder | Callable that constructs an AIOKafkaConsumer instance. TYPE: |
batch | Flag indicating whether to consume messages in batches. TYPE: |
batch_timeout_ms | Timeout in milliseconds for batch consumption. TYPE: |
max_records | Maximum number of records to consume in a batch. |
title | Optional title for the consumer. |
description | Optional description for the consumer. |
RAISES | DESCRIPTION |
---|---|
NotImplementedError | If silent animals are not supported. |
Source code in faststream/kafka/handler.py
calls instance-attribute
#
calls: List[
Tuple[
HandlerCallWrapper[MsgType, Any, SendableMessage],
Callable[[StreamMessage[MsgType]], Awaitable[bool]],
AsyncParser[MsgType, Any],
AsyncDecoder[StreamMessage[MsgType]],
Sequence[Callable[[Any], BaseMiddleware]],
CallModel[Any, SendableMessage],
]
]
global_middlewares instance-attribute
#
add_call #
add_call(
*,
handler: HandlerCallWrapper[
ConsumerRecord, P_HandlerParams, T_HandlerReturn
],
dependant: CallModel[P_HandlerParams, T_HandlerReturn],
parser: CustomParser[
Union[ConsumerRecord, Tuple[ConsumerRecord, ...]],
KafkaMessage,
],
decoder: Optional[CustomDecoder[KafkaMessage]],
filter: Union[
Filter[KafkaMessage],
Filter[StreamMessage[Tuple[ConsumerRecord, ...]]],
],
middlewares: Optional[
Sequence[Callable[[ConsumerRecord], BaseMiddleware]]
]
) -> None
Adds a call to the handler.
PARAMETER | DESCRIPTION |
---|---|
handler | The handler function to be called. TYPE: |
dependant | The dependant model. TYPE: |
parser | Optional custom parser for parsing the input. TYPE: |
decoder | Optional custom decoder for decoding the input. TYPE: |
filter | The filter for filtering the input. TYPE: |
middlewares | Optional sequence of middlewares to be applied. TYPE: |
RETURNS | DESCRIPTION |
---|---|
None | None |
Source code in faststream/kafka/handler.py
close async
#
consume async
#
Consume a message asynchronously.
PARAMETER | DESCRIPTION |
---|---|
msg | The message to be consumed. TYPE: |
RETURNS | DESCRIPTION |
---|---|
SendableMessage | The sendable message. |
RAISES | DESCRIPTION |
---|---|
StopConsume | If the consumption needs to be stopped. |
RAISES | DESCRIPTION |
---|---|
Exception | If an error occurs during consumption. |
Source code in faststream/broker/handler.py
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 |
|
get_payloads #
Source code in faststream/broker/handler.py
get_routing_hash staticmethod
#
name #
schema #
start async
#
Start the consumer.
PARAMETER | DESCRIPTION |
---|---|
**consumer_kwargs | Additional keyword arguments to pass to the consumer. TYPE: |
RETURNS | DESCRIPTION |
---|---|
None | None |