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.).voidflush()Block until every message published so far has been acknowledged by the broker, throwing if any of them failed to be delivered.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)
-
flush
public void flush()Block until every message published so far has been acknowledged by the broker, throwing if any of them failed to be delivered.Implementations that send asynchronously (notably Kafka) would otherwise let a caller report a successful publish before the broker has accepted — or rejected — the message. Callers that report publish success to a user must call this first.
The default implementation is a no-op, for publishers that deliver synchronously.
Blocks until every in-flight send has been acknowledged, then rethrows the first delivery failure seen since the last flush.
- Specified by:
flushin interfaceMessagePublisher
-
close
public void close()Description copied from interface:MessagePublisherRelease any resources held by this publisher (producer connections, etc.).- Specified by:
closein interfaceMessagePublisher
-