Class 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 Detail

      • EmbeddedKafkaBroker

        public EmbeddedKafkaBroker()
    • Method Detail

      • withControllerPort

        public EmbeddedKafkaBroker withControllerPort​(int port)
        Configure the controller port for the broker.
        Parameters:
        port - the port.
        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
      • isRunning

        public boolean isRunning()
      • getKafkaConfig

        public kafka.server.KafkaConfig getKafkaConfig()
      • getAdvertisedListeners

        public String getAdvertisedListeners()
      • 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)