Class EmbeddedKafkaBroker

java.lang.Object
io.smallrye.reactive.messaging.kafka.companion.test.EmbeddedKafkaBroker
All Implemented Interfaces:
Closeable, AutoCloseable

public class EmbeddedKafkaBroker extends Object implements Closeable
Embedded KRaft Broker, by default listens on localhost with random broker and controller ports.

  • Constructor Details

    • EmbeddedKafkaBroker

      public EmbeddedKafkaBroker()
  • Method Details

    • withNodeId

      public EmbeddedKafkaBroker withNodeId(int nodeId)
      Configure node id for the broker.
      Parameters:
      nodeId - the node id.
      Returns:
      this EmbeddedKafkaBroker
    • withAdditionalProperties

      public EmbeddedKafkaBroker withAdditionalProperties(Consumer<Properties> function)
      Configure properties for the broker.
      Parameters:
      function - the config modifier function.
      Returns:
      this EmbeddedKafkaBroker
    • withKafkaPort

      public EmbeddedKafkaBroker withKafkaPort(int port)
      Configure the port on which the broker will listen.
      Parameters:
      port - the port.
      Returns:
      this EmbeddedKafkaBroker
    • withControllerPort

      public EmbeddedKafkaBroker withControllerPort(int port)
      Configure the controller port for the broker.
      Parameters:
      port - the port.
      Returns:
      this EmbeddedKafkaBroker
    • withKafkaHost

      public EmbeddedKafkaBroker withKafkaHost(String host)
      Configure the hostname on which the broker will listen.
      Parameters:
      host - the host.
      Returns:
      this EmbeddedKafkaBroker
    • withClusterId

      public EmbeddedKafkaBroker withClusterId(String clusterId)
      Configure the cluster id for the broker storage dirs.
      Parameters:
      clusterId - the cluster id.
      Returns:
      this EmbeddedKafkaBroker
    • withDeleteLogDirsOnClose

      public EmbeddedKafkaBroker withDeleteLogDirsOnClose(boolean deleteDirsOnClose)
      Configure whether log directories will be deleted on broker shutdown.
      Parameters:
      deleteDirsOnClose - true
      Returns:
      this EmbeddedKafkaBroker
    • withAdvertisedListeners

      public EmbeddedKafkaBroker withAdvertisedListeners(org.apache.kafka.common.Endpoint... endpoints)
      Configure custom listeners for the broker.

      Note that this will override the default PLAINTEXT listener. A CONTROLLER listener will be added automatically.

      Returns:
      this EmbeddedKafkaBroker
    • withAdvertisedListeners

      public EmbeddedKafkaBroker withAdvertisedListeners(String advertisedListeners)
      Configure custom listeners for the broker.

      Note that this will override the default PLAINTEXT listener. A CONTROLLER listener will be added automatically.

      Returns:
      this EmbeddedKafkaBroker
    • start

      public EmbeddedKafkaBroker start()
      Create and start the broker.
      Returns:
      this EmbeddedKafkaBroker
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
    • isRunning

      public boolean isRunning()
    • getKafkaConfig

      public kafka.server.KafkaConfig getKafkaConfig()
    • getAdvertisedListeners

      public String getAdvertisedListeners()
    • getLogDirs

      public List<String> getLogDirs()
    • getNodeId

      public int getNodeId()
    • getClusterId

      public String getClusterId()
    • endpoint

      public static org.apache.kafka.common.Endpoint endpoint(org.apache.kafka.common.security.auth.SecurityProtocol protocol, int port)
    • endpoint

      public static org.apache.kafka.common.Endpoint endpoint(org.apache.kafka.common.security.auth.SecurityProtocol protocol, String host, int port)
    • endpoint

      public static org.apache.kafka.common.Endpoint endpoint(String listener, org.apache.kafka.common.security.auth.SecurityProtocol protocol, int port)
    • endpoint

      public static org.apache.kafka.common.Endpoint endpoint(String listener, org.apache.kafka.common.security.auth.SecurityProtocol protocol, String host, int port)
    • parseEndpoint

      public static org.apache.kafka.common.Endpoint parseEndpoint(org.apache.kafka.common.security.auth.SecurityProtocol protocol, String listenerStr)
    • parseEndpoint

      public static org.apache.kafka.common.Endpoint parseEndpoint(String listenerStr)
    • createDefaultBrokerConfig

      public static Properties createDefaultBrokerConfig(int nodeId, org.apache.kafka.common.Endpoint controller, org.apache.kafka.common.Endpoint internalEndpoint, List<org.apache.kafka.common.Endpoint> advertisedListeners)
    • formatStorageFromConfig

      public static kafka.server.KafkaConfig formatStorageFromConfig(Properties properties, String clusterId, boolean ignoreFormatted)
    • formatStorage

      public static void formatStorage(List<String> directories, String clusterId, int nodeId, boolean ignoreFormatted)
    • createServer

      public static kafka.server.KafkaRaftServer createServer(kafka.server.KafkaConfig config)
    • toListenerString

      public static String toListenerString(org.apache.kafka.common.Endpoint endpoint)