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 |
static java.lang.String |
SPRING_EMBEDDED_ZOOKEEPER_CONNECT |
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)
Deprecated.
|
void |
bounce(int index,
boolean waitForPropagation)
Deprecated.
|
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.
|
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)
Deprecated.
|
public static final java.lang.String BEAN_NAME
public static final java.lang.String SPRING_EMBEDDED_KAFKA_BROKERS
public static final java.lang.String SPRING_EMBEDDED_ZOOKEEPER_CONNECT
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).KafkaConfig
public void setKafkaPorts(int... kafkaPorts)
kafkaPorts
- the ports.public void afterPropertiesSet() throws java.lang.Exception
afterPropertiesSet
in interface org.springframework.beans.factory.InitializingBean
java.lang.Exception
public void before() throws java.lang.Exception
before
in class org.junit.rules.ExternalResource
java.lang.Exception
public void destroy() throws java.lang.Exception
destroy
in interface org.springframework.beans.factory.DisposableBean
java.lang.Exception
public void after()
after
in class org.junit.rules.ExternalResource
public java.util.List<kafka.server.KafkaServer> getKafkaServers()
getKafkaServers
in interface KafkaRule
public kafka.server.KafkaServer getKafkaServer(int id)
public kafka.zk.EmbeddedZookeeper getZookeeper()
public org.I0Itec.zkclient.ZkClient getZkClient()
getZkClient
in interface KafkaRule
public java.lang.String getZookeeperConnectionString()
getZookeeperConnectionString
in interface KafkaRule
public BrokerAddress getBrokerAddress(int i)
public BrokerAddress[] getBrokerAddresses()
getBrokerAddresses
in interface KafkaRule
public int getPartitionsPerTopic()
getPartitionsPerTopic
in interface KafkaRule
public void bounce(BrokerAddress brokerAddress)
public void startZookeeper()
@Deprecated public void bounce(int index, boolean waitForPropagation)
@Deprecated public void bounce(int index)
public void restart(int index) throws java.lang.Exception
java.lang.Exception
@Deprecated public void waitUntilSynced(java.lang.String topic, int brokerId)
public java.lang.String getBrokersAsString()
getBrokersAsString
in interface KafkaRule
public boolean isEmbedded()
isEmbedded
in interface KafkaRule
public 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.