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
ATestRule
wrapper around anEmbeddedKafkaBroker
.- Since:
- 2.2
- Author:
- Artem Bilan
- See Also:
EmbeddedKafkaBroker
-
-
Constructor Summary
Constructors Constructor Description EmbeddedKafkaRule(int count)
EmbeddedKafkaRule(int count, boolean controlledShutdown, int partitions, java.lang.String... topics)
Create embedded Kafka brokers listening on random ports.EmbeddedKafkaRule(int count, boolean controlledShutdown, java.lang.String... topics)
Create embedded Kafka brokers.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
after()
void
before()
EmbeddedKafkaRule
brokerProperties(java.util.Map<java.lang.String,java.lang.String> brokerProperties)
Specify the properties to configure Kafka Broker before start, e.g.EmbeddedKafkaRule
brokerProperty(java.lang.String property, java.lang.Object value)
Specify a broker property.EmbeddedKafkaBroker
getEmbeddedKafka()
Return an underlying delegatorEmbeddedKafkaBroker
instance.EmbeddedKafkaRule
kafkaPorts(int... kafkaPorts)
Set explicit ports on which the kafka brokers will listen.EmbeddedKafkaRule
zkPort(int port)
-
-
-
Constructor Detail
-
EmbeddedKafkaRule
public EmbeddedKafkaRule(int count)
-
EmbeddedKafkaRule
public EmbeddedKafkaRule(int count, boolean controlledShutdown, java.lang.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, java.lang.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 Detail
-
brokerProperties
public EmbeddedKafkaRule brokerProperties(java.util.Map<java.lang.String,java.lang.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(java.lang.String property, java.lang.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 delegatorEmbeddedKafkaBroker
instance.- Returns:
- the
EmbeddedKafkaBroker
instance.
-
before
public void before()
- Overrides:
before
in classorg.junit.rules.ExternalResource
-
after
public void after()
- Overrides:
after
in classorg.junit.rules.ExternalResource
-
-