Package org.mockserver.async.publish
Class KafkaMessagePublisher
java.lang.Object
org.mockserver.async.publish.KafkaMessagePublisher
- All Implemented Interfaces:
MessagePublisher
A
MessagePublisher that delegates to a Kafka KafkaProducer.
The channel name maps directly to a Kafka topic.
Supports configurable record keys and message headers in addition to the basic payload publishing.
-
Constructor Summary
ConstructorsConstructorDescriptionKafkaMessagePublisher(String bootstrapServers) Create a publisher connected to the given Kafka bootstrap servers using plaintext (no security).KafkaMessagePublisher(String bootstrapServers, KafkaSecurity security) Create a publisher connected to the given Kafka bootstrap servers with optional security configuration. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Release any resources held by this publisher (producer connections, etc.).voidPublish the given payload to the specified channel with no key or headers.voidPublish a message with a specific key and optional headers.voidpublish(String channel, String payload, PublishOptions options) Publish a message with per-message options from AsyncAPI bindings.
-
Constructor Details
-
KafkaMessagePublisher
Create a publisher connected to the given Kafka bootstrap servers using plaintext (no security). Backward-compatible entry point.- Parameters:
bootstrapServers- comma-separated list of host:port pairs
-
KafkaMessagePublisher
Create a publisher connected to the given Kafka bootstrap servers with optional security configuration.- Parameters:
bootstrapServers- comma-separated list of host:port pairssecurity- security configuration (may be null for plaintext)
-
-
Method Details
-
publish
Description copied from interface:MessagePublisherPublish the given payload to the specified channel with no key or headers.- Specified by:
publishin interfaceMessagePublisher- Parameters:
channel- the channel / topic namepayload- the message payload (typically JSON)
-
publish
Publish a message with per-message options from AsyncAPI bindings. ThePublishOptions.getKey()sets the Kafka record key andPublishOptions.getHeaders()are added as Kafka record headers. MQTT-specific fields (QoS, retain) are ignored.- Specified by:
publishin interfaceMessagePublisher- Parameters:
channel- the Kafka topic namepayload- the message payload (typically JSON)options- per-message publish options (may be null)
-
publish
Publish a message with a specific key and optional headers.- Specified by:
publishin interfaceMessagePublisher- Parameters:
channel- the Kafka topic namekey- the record key (may be null)payload- the message payload (typically JSON)headers- optional headers (may be null or empty)
-
close
public void close()Description copied from interface:MessagePublisherRelease any resources held by this publisher (producer connections, etc.).- Specified by:
closein interfaceMessagePublisher
-