Package org.mockserver.async.publish
Class KafkaAvroMessagePublisher
java.lang.Object
org.mockserver.async.publish.KafkaAvroMessagePublisher
- All Implemented Interfaces:
MessagePublisher
A
MessagePublisher that publishes Avro messages to Kafka in the
Confluent Schema Registry wire format (magic byte + schema id + Avro binary),
so real Confluent Avro consumers can read them.
MockServer's example payloads are JSON; this publisher encodes each JSON payload
to Avro binary (AvroPayloadCodec), resolves the schema id, and frames it
(ConfluentWireFormat). Two modes:
- Registry-backed (a
SchemaRegistryClientis supplied): the schema is registered under<topic>-valueand its returned id is embedded — exactly what the Confluent serializers do. - Registry-less (no client): a fixed, configured schema id is embedded. Useful for closed round-trips where the same inline schema is used on both ends.
-
Constructor Summary
ConstructorsConstructorDescriptionKafkaAvroMessagePublisher(String bootstrapServers, KafkaSecurity security, String schemaJson, SchemaRegistryClient registryClient, int fixedSchemaId) -
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(String channel, String payload, PublishOptions options) Publish the given payload with per-message options derived from AsyncAPI bindings.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.mockserver.async.publish.MessagePublisher
publish
-
Constructor Details
-
KafkaAvroMessagePublisher
public KafkaAvroMessagePublisher(String bootstrapServers, KafkaSecurity security, String schemaJson, SchemaRegistryClient registryClient, int fixedSchemaId) - Parameters:
bootstrapServers- comma-separated host:port pairssecurity- Kafka security (may be null for plaintext)schemaJson- the Avro schema JSON used to encode payloads (required)registryClient- the Schema Registry client, or null for registry-less modefixedSchemaId- the schema id to embed in registry-less mode
-
-
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
Description copied from interface:MessagePublisherPublish the given payload with per-message options derived from AsyncAPI bindings. Default implementation delegates toMessagePublisher.publish(String, String), ignoring the options — implementations that support them override this.- Specified by:
publishin interfaceMessagePublisher- Parameters:
channel- the channel / topic namepayload- the message payload (typically JSON)options- per-message publish options (may be null)
-
close
public void close()Description copied from interface:MessagePublisherRelease any resources held by this publisher (producer connections, etc.).- Specified by:
closein interfaceMessagePublisher
-