Skip to content

FakePublisher

faststream.broker.wrapper.FakePublisher #

FakePublisher(
    method: Callable[..., Awaitable[SendableMessage]]
)

A class to represent a fake publisher.

METHOD DESCRIPTION
publish

asynchronously publishes a message with optional correlation ID and additional keyword arguments

Note

The above docstring is autogenerated by docstring-gen library (https://docstring-gen.airt.ai)

Initialize an object.

PARAMETER DESCRIPTION
method

A callable that takes any number of arguments and returns an awaitable sendable message.

TYPE: Callable[..., Awaitable[SendableMessage]]

Note

The above docstring is autogenerated by docstring-gen library (https://docstring-gen.airt.ai)

Source code in faststream/broker/wrapper.py
def __init__(self, method: Callable[..., Awaitable[SendableMessage]]) -> None:
    """Initialize an object.

    Args:
        method: A callable that takes any number of arguments and returns an awaitable sendable message.
    !!! note

        The above docstring is autogenerated by docstring-gen library (https://docstring-gen.airt.ai)
    """
    self.method = method

method instance-attribute #

method = method

publish async #

publish(
    message: SendableMessage,
    correlation_id: Optional[str] = None,
    **kwargs: Any
) -> Optional[SendableMessage]

Publish a message.

PARAMETER DESCRIPTION
message

The message to be published.

TYPE: SendableMessage

correlation_id

Optional correlation ID for the message.

TYPE: Optional[str] DEFAULT: None

**kwargs

Additional keyword arguments.

TYPE: Any DEFAULT: {}

RETURNS DESCRIPTION
Optional[SendableMessage]

The published message.

Note

The above docstring is autogenerated by docstring-gen library (https://docstring-gen.airt.ai)

Source code in faststream/broker/wrapper.py
async def publish(
    self,
    message: SendableMessage,
    correlation_id: Optional[str] = None,
    **kwargs: Any,
) -> Optional[SendableMessage]:
    """Publish a message.

    Args:
        message: The message to be published.
        correlation_id: Optional correlation ID for the message.
        **kwargs: Additional keyword arguments.

    Returns:
        The published message.
    !!! note

        The above docstring is autogenerated by docstring-gen library (https://docstring-gen.airt.ai)
    """
    return await self.method(message, correlation_id=correlation_id, **kwargs)

Last update: 2023-11-13