Class EmbeddedKafkaRule

java.lang.Object
org.junit.rules.ExternalResource
org.springframework.kafka.test.rule.EmbeddedKafkaRule
All Implemented Interfaces:
org.junit.rules.TestRule

public class EmbeddedKafkaRule extends org.junit.rules.ExternalResource
A TestRule wrapper around an EmbeddedKafkaBroker.
Since:
2.2
Author:
Artem Bilan
See Also:
  • Constructor Details

    • EmbeddedKafkaRule

      public EmbeddedKafkaRule(int count)
    • EmbeddedKafkaRule

      public EmbeddedKafkaRule(int count, boolean controlledShutdown, String... topics)
      Create embedded Kafka brokers.
      Parameters:
      count - the number of brokers.
      controlledShutdown - passed into TestUtils.createBrokerConfig.
      topics - the topics to create (2 partitions per).
    • EmbeddedKafkaRule

      public EmbeddedKafkaRule(int count, boolean controlledShutdown, int partitions, String... topics)
      Create embedded Kafka brokers listening on random ports.
      Parameters:
      count - the number of brokers.
      controlledShutdown - passed into TestUtils.createBrokerConfig.
      partitions - partitions per topic.
      topics - the topics to create.
  • Method Details

    • brokerProperties

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

      public EmbeddedKafkaRule brokerProperty(String property, Object value)
      Specify a broker property.
      Parameters:
      property - the property name.
      value - the value.
      Returns:
      the EmbeddedKafkaRule.
      Since:
      2.1.4
    • kafkaPorts

      public EmbeddedKafkaRule kafkaPorts(int... kafkaPorts)
      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:
      kafkaPorts - the ports.
      Returns:
      the rule.
    • zkPort

      public EmbeddedKafkaRule zkPort(int port)
    • getEmbeddedKafka

      public EmbeddedKafkaBroker getEmbeddedKafka()
      Return an underlying delegator EmbeddedKafkaBroker instance.
      Returns:
      the EmbeddedKafkaBroker instance.
    • before

      public void before()
      Overrides:
      before in class org.junit.rules.ExternalResource
    • after

      public void after()
      Overrides:
      after in class org.junit.rules.ExternalResource