BaseMiddleware
faststream.broker.middlewares.BaseMiddleware #
A base middleware class.
| METHOD | DESCRIPTION |
|---|---|
on_receive | Called when a message is received. |
after_processed | Optional[Type[BaseException]] = None, exc_val: Optional[BaseException] = None, exec_tb: Optional[TracebackType] = None) -> Optional[bool]: Called after processing a message. |
__aenter__ | Called when entering a context. |
__aexit__ | Optional[Type[BaseException]] = None, exc_val: Optional[BaseException] = None, exec_tb: Optional[TracebackType] = None) -> Optional[bool]: Called when exiting a context. |
on_consume | DecodedMessage) -> DecodedMessage: Called before consuming a message. |
after_consume | Optional[Exception]) -> None: Called after consuming a message. |
consume_scope | DecodedMessage) -> AsyncIterator[DecodedMessage]: Context manager for consuming a message. |
on_publish | SendableMessage) -> SendableMessage: Called before publishing a message. |
after_publish | Optional[Exception]) -> None: Asynchronous function to handle the after publish event. |
Initialize the class.
| PARAMETER | DESCRIPTION |
|---|---|
msg | Any message to be stored. TYPE: |
Source code in faststream/broker/middlewares.py
after_consume async #
A function to handle the result of consuming a resource asynchronously.
| PARAMETER | DESCRIPTION |
|---|---|
err | Optional exception that occurred during consumption
|
| RAISES | DESCRIPTION |
|---|---|
err | If an exception occurred during consumption |
Source code in faststream/broker/middlewares.py
after_processed async #
after_processed(
exc_type: Optional[Type[BaseException]] = None,
exc_val: Optional[BaseException] = None,
exec_tb: Optional[TracebackType] = None,
) -> Optional[bool]
Asynchronously called after processing.
| PARAMETER | DESCRIPTION |
|---|---|
exc_type | Optional exception type TYPE: |
exc_val | Optional exception value TYPE: |
exec_tb | Optional traceback TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
Optional[bool] | Optional boolean value indicating whether the processing was successful or not. |
Source code in faststream/broker/middlewares.py
after_publish async #
Asynchronous function to handle the after publish event.
| PARAMETER | DESCRIPTION |
|---|---|
err | Optional exception that occurred during the publish |
| RETURNS | DESCRIPTION |
|---|---|
None | None |
| RAISES | DESCRIPTION |
|---|---|
Exception | If an error occurred during the publish |
Source code in faststream/broker/middlewares.py
consume_scope async #
Asynchronously consumes a message and returns an asynchronous iterator of decoded messages.
| PARAMETER | DESCRIPTION |
|---|---|
msg | The decoded message to consume. TYPE: |
| YIELDS | DESCRIPTION |
|---|---|
AsyncIterator[DecodedMessage] | An asynchronous iterator of decoded messages. |
| RETURNS | DESCRIPTION |
|---|---|
AsyncIterator[DecodedMessage] | An asynchronous iterator of decoded messages. |
| RAISES | DESCRIPTION |
|---|---|
Exception | If an error occurs while consuming the message. |
AsyncIterator
An asynchronous iterator that yields decoded messages.
Note
This function is an async function.
Source code in faststream/broker/middlewares.py
on_consume async #
Asynchronously consumes a message.
| PARAMETER | DESCRIPTION |
|---|---|
msg | The message to be consumed. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
DecodedMessage | The consumed message. |
on_publish async #
Asynchronously handle a publish event.
| PARAMETER | DESCRIPTION |
|---|---|
msg | The message to be published. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
SendableMessage | The published message. |
on_receive async #
publish_scope async #
Publish a message and return an async iterator.
| PARAMETER | DESCRIPTION |
|---|---|
msg | The message to be published. TYPE: |
| YIELDS | DESCRIPTION |
|---|---|
AsyncIterator[SendableMessage] | A sendable message. |
| RETURNS | DESCRIPTION |
|---|---|
AsyncIterator[SendableMessage] | An async iterator of sendable messages. |
| RAISES | DESCRIPTION |
|---|---|
Exception | If an error occurs during publishing. |