Package org.mockserver.async.subscribe
Class KafkaAvroMessageSubscriber
java.lang.Object
org.mockserver.async.subscribe.KafkaAvroMessageSubscriber
- All Implemented Interfaces:
MessageSubscriber
A
MessageSubscriber that consumes Confluent wire-format Avro
messages from Kafka and records them as JSON — the consume/verify counterpart of
KafkaAvroMessagePublisher.
For each consumed record the wire-format header (ConfluentWireFormat) is
stripped to recover the schema id and Avro binary, the schema is resolved (from the
SchemaRegistryClient by id, or the configured inline schema in registry-less
mode), and the Avro binary is decoded back to JSON (AvroPayloadCodec). The
recorded payload is therefore JSON, so the existing substring / JSON-path
verification works unchanged.
Mirrors KafkaMessageSubscriber's poll-thread confinement: all
KafkaConsumer access happens on the single background poll thread.
-
Constructor Summary
ConstructorsConstructorDescriptionKafkaAvroMessageSubscriber(String bootstrapServers, String groupId, int maxRecordedMessages, KafkaSecurity security, SchemaRegistryClient registryClient, String inlineSchemaJson) -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Clear all recorded messages and stop all subscriptions.Return all messages recorded across all channels.getRecordedMessages(String channel) Return all messages recorded on the given channel since subscription started (or since the last reset).booleanvoidStart subscribing to the given channel.voidunsubscribe(String channel) Stop subscribing to the given channel.
-
Constructor Details
-
KafkaAvroMessageSubscriber
public KafkaAvroMessageSubscriber(String bootstrapServers, String groupId, int maxRecordedMessages, KafkaSecurity security, SchemaRegistryClient registryClient, String inlineSchemaJson) - Parameters:
bootstrapServers- comma-separated host:port pairsgroupId- the consumer group idmaxRecordedMessages- max recorded messages per channelsecurity- Kafka security (may be null)registryClient- Schema Registry client, or null for registry-less modeinlineSchemaJson- inline Avro schema for registry-less decoding (may be null when a registry is used)
-
-
Method Details
-
subscribe
Description copied from interface:MessageSubscriberStart subscribing to the given channel. Messages will be recorded internally and are retrievable viaMessageSubscriber.getRecordedMessages(String).- Specified by:
subscribein interfaceMessageSubscriber- Parameters:
channel- the channel/topic to subscribe to
-
unsubscribe
Description copied from interface:MessageSubscriberStop subscribing to the given channel.- Specified by:
unsubscribein interfaceMessageSubscriber
-
getRecordedMessages
Description copied from interface:MessageSubscriberReturn all messages recorded on the given channel since subscription started (or since the last reset).- Specified by:
getRecordedMessagesin interfaceMessageSubscriber
-
getAllRecordedMessages
Description copied from interface:MessageSubscriberReturn all messages recorded across all channels.- Specified by:
getAllRecordedMessagesin interfaceMessageSubscriber
-
close
public void close()Description copied from interface:MessageSubscriberClear all recorded messages and stop all subscriptions.- Specified by:
closein interfaceMessageSubscriber
-
isHealthy
public boolean isHealthy()
-