Interface EmbeddedKafkaBroker

All Superinterfaces:
DisposableBean, InitializingBean
All Known Implementing Classes:
EmbeddedKafkaKraftBroker, EmbeddedKafkaZKBroker

public interface EmbeddedKafkaBroker extends InitializingBean, DisposableBean
Since:
3.1
Author:
Gary Russell
  • Field Details

  • Method Details

    • kafkaPorts

      EmbeddedKafkaBroker kafkaPorts(int... ports)
      Set explicit ports on which the kafka brokers will listen. Useful when running an embedded broker that you want to access from other processes.
      Parameters:
      ports - the ports.
      Returns:
      the EmbeddedKafkaBroker.
    • getTopics

      Set<String> getTopics()
      Get the topics.
      Returns:
      the topics.
    • destroy

      default void destroy()
      Specified by:
      destroy in interface DisposableBean
    • afterPropertiesSet

      default void afterPropertiesSet()
      Specified by:
      afterPropertiesSet in interface InitializingBean
    • brokerProperties

      EmbeddedKafkaBroker brokerProperties(Map<String,String> properties)
      Specify the properties to configure Kafka Broker before start, e.g. auto.create.topics.enable, transaction.state.log.replication.factor etc.
      Parameters:
      properties - the properties to use for configuring Kafka Broker(s).
      Returns:
      this for chaining configuration.
      See Also:
      • KafkaConfig
    • brokerListProperty

      EmbeddedKafkaBroker brokerListProperty(String brokerListProperty)
      Set the system property with this name to the list of broker addresses. Defaults to spring.kafka.bootstrap-servers for Spring Boot compatibility.
      Parameters:
      brokerListProperty - the brokerListProperty to set
      Returns:
      this broker.
    • adminTimeout

      EmbeddedKafkaBroker adminTimeout(int adminTimeout)
      Set the timeout in seconds for admin operations (e.g. topic creation, close).
      Parameters:
      adminTimeout - the timeout.
      Returns:
      the EmbeddedKafkaBroker
      Since:
      2.8.5
    • getBrokersAsString

      String getBrokersAsString()
      Get the bootstrap server addresses as a String.
      Returns:
      the bootstrap servers.
    • addTopics

      void addTopics(String... topicsToAdd)
      Add topics to the existing broker(s) using the configured number of partitions. The broker(s) must be running.
      Parameters:
      topicsToAdd - the topics.
    • addTopics

      void addTopics(org.apache.kafka.clients.admin.NewTopic... topicsToAdd)
      Add topics to the existing broker(s). The broker(s) must be running.
      Parameters:
      topicsToAdd - the topics.
    • addTopicsWithResults

      Map<String,Exception> addTopicsWithResults(org.apache.kafka.clients.admin.NewTopic... topicsToAdd)
      Add topics to the existing broker(s) and returning a map of results. The broker(s) must be running.
      Parameters:
      topicsToAdd - the topics.
      Returns:
      the results; null values indicate success.
    • addTopicsWithResults

      Map<String,Exception> addTopicsWithResults(String... topicsToAdd)
      Add topics to the existing broker(s) using the configured number of partitions. The broker(s) must be running.
      Parameters:
      topicsToAdd - the topics.
      Returns:
      the results; null values indicate success.
    • consumeFromEmbeddedTopics

      void consumeFromEmbeddedTopics(org.apache.kafka.clients.consumer.Consumer<?,?> consumer, boolean seekToEnd, String... topicsToConsume)
      Subscribe a consumer to one or more of the embedded topics.
      Parameters:
      consumer - the consumer.
      topicsToConsume - the topics.
      seekToEnd - true to seek to the end instead of the beginning.
      Throws:
      IllegalStateException - if you attempt to consume from a topic that is not in the list of embedded topics.
    • consumeFromEmbeddedTopics

      void consumeFromEmbeddedTopics(org.apache.kafka.clients.consumer.Consumer<?,?> consumer, String... topicsToConsume)
      Subscribe a consumer to one or more of the embedded topics.
      Parameters:
      consumer - the consumer.
      topicsToConsume - the topics.
      Throws:
      IllegalStateException - if you attempt to consume from a topic that is not in the list of embedded topics.
    • consumeFromAnEmbeddedTopic

      void consumeFromAnEmbeddedTopic(org.apache.kafka.clients.consumer.Consumer<?,?> consumer, boolean seekToEnd, String topic)
      Subscribe a consumer to one of the embedded topics.
      Parameters:
      consumer - the consumer.
      seekToEnd - true to seek to the end instead of the beginning.
      topic - the topic.
    • consumeFromAnEmbeddedTopic

      void consumeFromAnEmbeddedTopic(org.apache.kafka.clients.consumer.Consumer<?,?> consumer, String topic)
      Subscribe a consumer to one of the embedded topics.
      Parameters:
      consumer - the consumer.
      topic - the topic.
    • consumeFromAllEmbeddedTopics

      void consumeFromAllEmbeddedTopics(org.apache.kafka.clients.consumer.Consumer<?,?> consumer, boolean seekToEnd)
      Subscribe a consumer to all the embedded topics.
      Parameters:
      seekToEnd - true to seek to the end instead of the beginning.
      consumer - the consumer.
    • consumeFromAllEmbeddedTopics

      void consumeFromAllEmbeddedTopics(org.apache.kafka.clients.consumer.Consumer<?,?> consumer)
      Subscribe a consumer to all the embedded topics.
      Parameters:
      consumer - the consumer.
    • getPartitionsPerTopic

      int getPartitionsPerTopic()
      Get the configured number of partitions per topic.
      Returns:
      the partition count.