FakeProducer
faststream.kafka.test.FakeProducer #
FakeProducer(broker: KafkaBroker)
Bases: AioKafkaFastProducer
A fake Kafka producer for testing purposes.
This class extends AioKafkaFastProducer and is used to simulate Kafka message publishing during tests.
Initialize the FakeProducer.
PARAMETER | DESCRIPTION |
---|---|
broker | The KafkaBroker instance to associate with this FakeProducer. TYPE: |
Source code in faststream/kafka/test.py
publish async
#
publish(
message: SendableMessage,
topic: str,
key: Optional[bytes] = None,
partition: Optional[int] = None,
timestamp_ms: Optional[int] = None,
headers: Optional[Dict[str, str]] = None,
correlation_id: Optional[str] = None,
*,
reply_to: str = "",
rpc: bool = False,
rpc_timeout: Optional[float] = None,
raise_timeout: bool = False
) -> Optional[SendableMessage]
Publish a message to the Kafka broker.
PARAMETER | DESCRIPTION |
---|---|
message | The message to be published. TYPE: |
topic | The Kafka topic to publish the message to. TYPE: |
key | The message key. Defaults to None. |
partition | The Kafka partition to use. Defaults to None. |
timestamp_ms | The message timestamp in milliseconds. Defaults to None. |
headers | Additional headers for the message. Defaults to None. |
correlation_id | The correlation ID for the message. Defaults to None. |
reply_to | The topic to which responses should be sent. Defaults to "". TYPE: |
rpc | If True, treat the message as an RPC request. Defaults to False. TYPE: |
rpc_timeout | Timeout for RPC requests. Defaults to None. |
raise_timeout | If True, raise an exception on timeout. Defaults to False. TYPE: |
RETURNS | DESCRIPTION |
---|---|
Optional[SendableMessage] | Optional[SendableMessage]: The response message, if this was an RPC request, otherwise None. |
Source code in faststream/kafka/test.py
publish_batch async
#
publish_batch(
*msgs: SendableMessage,
topic: str,
partition: Optional[int] = None,
timestamp_ms: Optional[int] = None,
headers: Optional[Dict[str, str]] = None
) -> None
Publish a batch of messages to the Kafka broker.
PARAMETER | DESCRIPTION |
---|---|
*msgs | Variable number of messages to be published. TYPE: |
topic | The Kafka topic to publish the messages to. TYPE: |
partition | The Kafka partition to use. Defaults to None. |
timestamp_ms | The message timestamp in milliseconds. Defaults to None. |
headers | Additional headers for the messages. Defaults to None. |
RETURNS | DESCRIPTION |
---|---|
None | This method does not return a value. TYPE: |