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 Summary
ConstructorsConstructorDescriptionEmbeddedKafkaRule
(int count) EmbeddedKafkaRule
(int count, boolean controlledShutdown, int partitions, String... topics) Create embedded Kafka brokers listening on random ports.EmbeddedKafkaRule
(int count, boolean controlledShutdown, String... topics) Create embedded Kafka brokers. -
Method Summary
Modifier and TypeMethodDescriptionvoid
after()
void
before()
brokerProperties
(Map<String, String> brokerProperties) Specify the properties to configure Kafka Broker before start, e.g.brokerProperty
(String property, Object value) Specify a broker property.Return an underlying delegatorEmbeddedKafkaBroker
instance.kafkaPorts
(int... kafkaPorts) Set explicit ports on which the kafka brokers will listen.zkPort
(int port) Methods inherited from class org.junit.rules.ExternalResource
apply
-
Constructor Details
-
EmbeddedKafkaRule
public EmbeddedKafkaRule(int count) -
EmbeddedKafkaRule
Create embedded Kafka brokers.- Parameters:
count
- the number of brokers.controlledShutdown
- passed into TestUtils.createBrokerConfig.topics
- the topics to create (2 partitions per).
-
EmbeddedKafkaRule
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
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
Specify a broker property.- Parameters:
property
- the property name.value
- the value.- Returns:
- the
EmbeddedKafkaRule
. - Since:
- 2.1.4
-
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
-
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
-