Class KafkaMessageSubscriber

java.lang.Object
org.mockserver.async.subscribe.KafkaMessageSubscriber
All Implemented Interfaces:
MessageSubscriber

public class KafkaMessageSubscriber extends Object implements MessageSubscriber
A MessageSubscriber that uses a Kafka KafkaConsumer to subscribe to topics and record received messages. Runs a background poll loop on a daemon thread.

All KafkaConsumer access is confined to the single poll thread to avoid ConcurrentModificationException. Subscribe and unsubscribe requests are queued and drained at the top of each poll iteration.

Recorded messages are stored in a bounded BoundedMessageStore per channel to prevent unbounded memory growth.

  • Constructor Details

    • KafkaMessageSubscriber

      public KafkaMessageSubscriber(String bootstrapServers, String groupId)
      Create a subscriber connected to the given Kafka bootstrap servers using plaintext (no security). Backward-compatible entry point.
      Parameters:
      bootstrapServers - comma-separated list of host:port pairs
      groupId - the consumer group ID
    • KafkaMessageSubscriber

      public KafkaMessageSubscriber(String bootstrapServers, String groupId, int maxRecordedMessages)
      Create a subscriber with a custom recorded-message cap per channel.
    • KafkaMessageSubscriber

      public KafkaMessageSubscriber(String bootstrapServers, String groupId, int maxRecordedMessages, KafkaSecurity security)
      Create a subscriber with optional security configuration.
      Parameters:
      bootstrapServers - comma-separated list of host:port pairs
      groupId - the consumer group ID
      maxRecordedMessages - maximum recorded messages per channel
      security - security configuration (may be null for plaintext)
  • Method Details