Package org.springframework.kafka.test
Interface EmbeddedKafkaBroker
- All Superinterfaces:
DisposableBean,InitializingBean
- All Known Implementing Classes:
EmbeddedKafkaKraftBroker,EmbeddedKafkaZKBroker
- Since:
- 3.1
- Author:
- Gary Russell
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringstatic final StringSet the value of this property to a property name that should be set to the list of embedded broker addresses instead of "spring.embedded.kafka.brokers".static final Stringstatic final intstatic final Stringstatic final String -
Method Summary
Modifier and TypeMethodDescriptionvoidAdd topics to the existing broker(s) using the configured number of partitions.voidaddTopics(org.apache.kafka.clients.admin.NewTopic... topicsToAdd) Add topics to the existing broker(s).addTopicsWithResults(String... topicsToAdd) Add topics to the existing broker(s) using the configured number of partitions.addTopicsWithResults(org.apache.kafka.clients.admin.NewTopic... topicsToAdd) Add topics to the existing broker(s) and returning a map of results.default voidbrokerListProperty(String brokerListProperty) Set the system property with this name to the list of broker addresses.brokerProperties(Map<String, String> properties) Specify the properties to configure Kafka Broker before start, e.g.voidconsumeFromAllEmbeddedTopics(org.apache.kafka.clients.consumer.Consumer<?, ?> consumer) Subscribe a consumer to all the embedded topics.voidconsumeFromAllEmbeddedTopics(org.apache.kafka.clients.consumer.Consumer<?, ?> consumer, boolean seekToEnd) Subscribe a consumer to all the embedded topics.voidconsumeFromAnEmbeddedTopic(org.apache.kafka.clients.consumer.Consumer<?, ?> consumer, boolean seekToEnd, String topic) Subscribe a consumer to one of the embedded topics.voidconsumeFromAnEmbeddedTopic(org.apache.kafka.clients.consumer.Consumer<?, ?> consumer, String topic) Subscribe a consumer to one of the embedded topics.voidconsumeFromEmbeddedTopics(org.apache.kafka.clients.consumer.Consumer<?, ?> consumer, boolean seekToEnd, String... topicsToConsume) Subscribe a consumer to one or more of the embedded topics.voidconsumeFromEmbeddedTopics(org.apache.kafka.clients.consumer.Consumer<?, ?> consumer, String... topicsToConsume) Subscribe a consumer to one or more of the embedded topics.default voiddestroy()Get the bootstrap server addresses as a String.intGet the configured number of partitions per topic.Get the topics.kafkaPorts(int... ports) Set explicit ports on which the kafka brokers will listen.
-
Field Details
-
DEFAULT_ADMIN_TIMEOUT
static final int DEFAULT_ADMIN_TIMEOUT- See Also:
-
BEAN_NAME
- See Also:
-
BROKER_LIST_PROPERTY
Set the value of this property to a property name that should be set to the list of embedded broker addresses instead of "spring.embedded.kafka.brokers".- See Also:
-
SPRING_EMBEDDED_KAFKA_BROKERS
- See Also:
-
BROKER_NEEDED
- See Also:
-
LOOPBACK
- See Also:
-
-
Method Details
-
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:
ports- the ports.- Returns:
- the
EmbeddedKafkaBroker.
-
getTopics
Get the topics.- Returns:
- the topics.
-
destroy
default void destroy()- Specified by:
destroyin interfaceDisposableBean
-
afterPropertiesSet
default void afterPropertiesSet()- Specified by:
afterPropertiesSetin interfaceInitializingBean
-
brokerProperties
Specify the properties to configure Kafka Broker before start, e.g.auto.create.topics.enable,transaction.state.log.replication.factoretc.- Parameters:
properties- the properties to use for configuring Kafka Broker(s).- Returns:
- this for chaining configuration.
- See Also:
-
KafkaConfig
-
brokerListProperty
Set the system property with this name to the list of broker addresses. Defaults tospring.kafka.bootstrap-serversfor Spring Boot compatibility.- Parameters:
brokerListProperty- the brokerListProperty to set- Returns:
- this broker.
-
getBrokersAsString
String getBrokersAsString()Get the bootstrap server addresses as a String.- Returns:
- the bootstrap servers.
-
addTopics
Add topics to the existing broker(s) using the configured number of partitions. The broker(s) must be running.- Parameters:
topicsToAdd- the topics.
-
addTopics
void addTopics(org.apache.kafka.clients.admin.NewTopic... topicsToAdd) Add topics to the existing broker(s). The broker(s) must be running.- Parameters:
topicsToAdd- the topics.
-
addTopicsWithResults
Add topics to the existing broker(s) and returning a map of results. The broker(s) must be running.- Parameters:
topicsToAdd- the topics.- Returns:
- the results; null values indicate success.
-
addTopicsWithResults
Add topics to the existing broker(s) using the configured number of partitions. The broker(s) must be running.- Parameters:
topicsToAdd- the topics.- Returns:
- the results; null values indicate success.
-
consumeFromEmbeddedTopics
void consumeFromEmbeddedTopics(org.apache.kafka.clients.consumer.Consumer<?, ?> consumer, boolean seekToEnd, String... topicsToConsume) Subscribe a consumer to one or more of the embedded topics.- Parameters:
consumer- the consumer.topicsToConsume- the topics.seekToEnd- true to seek to the end instead of the beginning.- Throws:
IllegalStateException- if you attempt to consume from a topic that is not in the list of embedded topics.
-
consumeFromEmbeddedTopics
void consumeFromEmbeddedTopics(org.apache.kafka.clients.consumer.Consumer<?, ?> consumer, String... topicsToConsume) Subscribe a consumer to one or more of the embedded topics.- Parameters:
consumer- the consumer.topicsToConsume- the topics.- Throws:
IllegalStateException- if you attempt to consume from a topic that is not in the list of embedded topics.
-
consumeFromAnEmbeddedTopic
void consumeFromAnEmbeddedTopic(org.apache.kafka.clients.consumer.Consumer<?, ?> consumer, boolean seekToEnd, String topic) Subscribe a consumer to one of the embedded topics.- Parameters:
consumer- the consumer.seekToEnd- true to seek to the end instead of the beginning.topic- the topic.
-
consumeFromAnEmbeddedTopic
void consumeFromAnEmbeddedTopic(org.apache.kafka.clients.consumer.Consumer<?, ?> consumer, String topic) Subscribe a consumer to one of the embedded topics.- Parameters:
consumer- the consumer.topic- the topic.
-
consumeFromAllEmbeddedTopics
void consumeFromAllEmbeddedTopics(org.apache.kafka.clients.consumer.Consumer<?, ?> consumer, boolean seekToEnd) Subscribe a consumer to all the embedded topics.- Parameters:
seekToEnd- true to seek to the end instead of the beginning.consumer- the consumer.
-
consumeFromAllEmbeddedTopics
void consumeFromAllEmbeddedTopics(org.apache.kafka.clients.consumer.Consumer<?, ?> consumer) Subscribe a consumer to all the embedded topics.- Parameters:
consumer- the consumer.
-
getPartitionsPerTopic
int getPartitionsPerTopic()Get the configured number of partitions per topic.- Returns:
- the partition count.
-