Handler
faststream.confluent.asyncapi.Handler dataclass
#
Handler(*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[..., AsyncConfluentConsumer], 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: LogicHandler
, AsyncAPIOperation
A class to handle logic and async API operations.
METHOD | DESCRIPTION |
---|---|
schema | Returns a dictionary of channels. |
Initialize a Kafka consumer for the specified topics.
PARAMETER | DESCRIPTION |
---|---|
*topics | Variable length argument list of topics to consume from. TYPE: |
log_context_builder | Callable that builds a log context from a message. |
graceful_timeout | Optional timeout in seconds for graceful shutdown. |
group_id | Optional group ID for the consumer. |
client_id | Client ID for the consumer. TYPE: |
builder | Callable that constructs an AsyncConfluentConsumer instance. TYPE: |
is_manual | Flag indicating whether to manually commit offsets. 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. |
include_in_schema | Flag indicating whether to include the consumer in the schema. TYPE: |
RAISES | DESCRIPTION |
---|---|
ValueError | If the topics are not specified. |
Source code in faststream/confluent/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
#
global_middlewares: Sequence[Callable[[Any], BaseMiddleware]] = []
add_call #
add_call(*, handler: HandlerCallWrapper[Message, P_HandlerParams, T_HandlerReturn], dependant: CallModel[P_HandlerParams, T_HandlerReturn], parser: CustomParser[Union[Message, Tuple[Message, ...]], KafkaMessage], decoder: Optional[CustomDecoder[KafkaMessage]], filter: Union[Filter[KafkaMessage], Filter[StreamMessage[Tuple[Message, ...]]]], middlewares: Optional[Sequence[Callable[[Message], 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/confluent/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
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 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 |
|
get_payloads #
Get the payloads of the handler.
Source code in faststream/broker/handler.py
get_routing_hash staticmethod
#
schema #
Source code in faststream/confluent/asyncapi.py
start async
#
start(**consumer_kwargs: Unpack[ConsumerConnectionParams]) -> None
Start the consumer.
PARAMETER | DESCRIPTION |
---|---|
**consumer_kwargs | Additional keyword arguments to pass to the consumer. TYPE: |
RETURNS | DESCRIPTION |
---|---|
None | None |