public class KafkaEmbedded extends org.junit.rules.ExternalResource implements KafkaRule, org.springframework.beans.factory.InitializingBean, org.springframework.beans.factory.DisposableBean
KafkaRule implementation for the embedded Kafka Broker and Zookeeper.| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
BEAN_NAME |
static long |
METADATA_PROPAGATION_TIMEOUT |
static java.lang.String |
SPRING_EMBEDDED_KAFKA_BROKERS |
| Constructor and Description |
|---|
KafkaEmbedded(int count) |
KafkaEmbedded(int count,
boolean controlledShutdown,
int partitions,
java.lang.String... topics)
Create embedded Kafka brokers.
|
KafkaEmbedded(int count,
boolean controlledShutdown,
java.lang.String... topics)
Create embedded Kafka brokers.
|
| Modifier and Type | Method and Description |
|---|---|
void |
after() |
void |
afterPropertiesSet() |
void |
before() |
void |
bounce(BrokerAddress brokerAddress) |
void |
bounce(int index) |
void |
bounce(int index,
boolean waitForPropagation) |
KafkaEmbedded |
brokerProperties(java.util.Map<java.lang.String,java.lang.String> brokerProperties)
Specify the properties to configure Kafka Broker before start, e.g.
|
void |
consumeFromAllEmbeddedTopics(org.apache.kafka.clients.consumer.Consumer<?,?> consumer)
Subscribe a consumer to all the embedded topics.
|
void |
consumeFromAnEmbeddedTopic(org.apache.kafka.clients.consumer.Consumer<?,?> consumer,
java.lang.String topic)
Subscribe a consumer to one of the embedded topics.
|
void |
consumeFromEmbeddedTopics(org.apache.kafka.clients.consumer.Consumer<?,?> consumer,
java.lang.String... topics)
Subscribe a consumer to one or more of the embedded topics.
|
java.util.Properties |
createProperties(int i,
java.lang.Integer port) |
void |
destroy() |
BrokerAddress |
getBrokerAddress(int i) |
BrokerAddress[] |
getBrokerAddresses() |
java.lang.String |
getBrokersAsString() |
kafka.server.KafkaServer |
getKafkaServer(int id) |
java.util.List<kafka.server.KafkaServer> |
getKafkaServers() |
int |
getPartitionsPerTopic() |
org.I0Itec.zkclient.ZkClient |
getZkClient() |
kafka.zk.EmbeddedZookeeper |
getZookeeper() |
java.lang.String |
getZookeeperConnectionString() |
boolean |
isEmbedded() |
void |
restart(int index) |
void |
setKafkaPorts(int... kafkaPorts)
Set explicit ports on which the kafka brokers will listen.
|
void |
startZookeeper() |
void |
waitUntilSynced(java.lang.String topic,
int brokerId) |
public static final java.lang.String BEAN_NAME
public static final java.lang.String SPRING_EMBEDDED_KAFKA_BROKERS
public static final long METADATA_PROPAGATION_TIMEOUT
public KafkaEmbedded(int count)
public KafkaEmbedded(int count,
boolean controlledShutdown,
java.lang.String... topics)
count - the number of brokers.controlledShutdown - passed into TestUtils.createBrokerConfig.topics - the topics to create (2 partitions per).public KafkaEmbedded(int count,
boolean controlledShutdown,
int partitions,
java.lang.String... topics)
count - the number of brokers.controlledShutdown - passed into TestUtils.createBrokerConfig.partitions - partitions per topic.topics - the topics to create.public KafkaEmbedded brokerProperties(java.util.Map<java.lang.String,java.lang.String> brokerProperties)
auto.create.topics.enable, transaction.state.log.replication.factor etc.brokerProperties - the properties to use for configuring Kafka Broker(s).KafkaConfigpublic void setKafkaPorts(int... kafkaPorts)
kafkaPorts - the ports.public void afterPropertiesSet()
throws java.lang.Exception
afterPropertiesSet in interface org.springframework.beans.factory.InitializingBeanjava.lang.Exceptionpublic void before()
throws java.lang.Exception
before in class org.junit.rules.ExternalResourcejava.lang.Exceptionpublic java.util.Properties createProperties(int i,
java.lang.Integer port)
public void destroy()
throws java.lang.Exception
destroy in interface org.springframework.beans.factory.DisposableBeanjava.lang.Exceptionpublic void after()
after in class org.junit.rules.ExternalResourcepublic java.util.List<kafka.server.KafkaServer> getKafkaServers()
getKafkaServers in interface KafkaRulepublic kafka.server.KafkaServer getKafkaServer(int id)
public kafka.zk.EmbeddedZookeeper getZookeeper()
public org.I0Itec.zkclient.ZkClient getZkClient()
getZkClient in interface KafkaRulepublic java.lang.String getZookeeperConnectionString()
getZookeeperConnectionString in interface KafkaRulepublic BrokerAddress getBrokerAddress(int i)
public BrokerAddress[] getBrokerAddresses()
getBrokerAddresses in interface KafkaRulepublic int getPartitionsPerTopic()
getPartitionsPerTopic in interface KafkaRulepublic void bounce(BrokerAddress brokerAddress)
public void startZookeeper()
public void bounce(int index,
boolean waitForPropagation)
public void bounce(int index)
public void restart(int index)
throws java.lang.Exception
java.lang.Exceptionpublic void waitUntilSynced(java.lang.String topic,
int brokerId)
public java.lang.String getBrokersAsString()
getBrokersAsString in interface KafkaRulepublic boolean isEmbedded()
isEmbedded in interface KafkaRulepublic void consumeFromAllEmbeddedTopics(org.apache.kafka.clients.consumer.Consumer<?,?> consumer)
throws java.lang.Exception
consumer - the consumer.java.lang.Exception - an exception.public void consumeFromAnEmbeddedTopic(org.apache.kafka.clients.consumer.Consumer<?,?> consumer,
java.lang.String topic)
throws java.lang.Exception
consumer - the consumer.topic - the topic.java.lang.Exception - an exception.public void consumeFromEmbeddedTopics(org.apache.kafka.clients.consumer.Consumer<?,?> consumer,
java.lang.String... topics)
throws java.lang.Exception
consumer - the consumer.topics - the topics.java.lang.Exception - an exception.