Skip to content

KafkaFakePublisher

faststream.kafka.publisher.fake.KafkaFakePublisher #

KafkaFakePublisher(producer, topic)

Bases: FakePublisher

Publisher Interface implementation to use as RPC or REPLY TO answer publisher.

Source code in faststream/kafka/publisher/fake.py
def __init__(
    self,
    producer: "ProducerProto[KafkaPublishCommand]",
    topic: str,
) -> None:
    super().__init__(producer=producer)
    self.topic = topic

topic instance-attribute #

topic = topic

patch_command #

patch_command(cmd)
Source code in faststream/kafka/publisher/fake.py
def patch_command(
    self,
    cmd: Union["PublishCommand", "KafkaPublishCommand"],
) -> "KafkaPublishCommand":
    cmd = super().patch_command(cmd)
    real_cmd = KafkaPublishCommand.from_cmd(cmd)
    real_cmd.destination = self.topic
    return real_cmd

publish async #

publish(message, /, *, correlation_id=None)
Source code in faststream/_internal/endpoint/publisher/fake.py
async def publish(
    self,
    message: SendableMessage,
    /,
    *,
    correlation_id: str | None = None,
) -> Any | None:
    msg = (
        f"`{self.__class__.__name__}` can be used only to publish "
        "a response for `reply-to` or `RPC` messages."
    )
    raise NotImplementedError(msg)

request async #

request(message, /, *, correlation_id=None)
Source code in faststream/_internal/endpoint/publisher/fake.py
async def request(
    self,
    message: "SendableMessage",
    /,
    *,
    correlation_id: str | None = None,
) -> Any:
    msg = (
        f"`{self.__class__.__name__}` can be used only to publish "
        "a response for `reply-to` or `RPC` messages."
    )
    raise NotImplementedError(msg)