Interface EmbeddedKafkaBroker
- All Superinterfaces:
- DisposableBean,- InitializingBean
- All Known Implementing Classes:
- EmbeddedKafkaKraftBroker,- EmbeddedKafkaZKBroker
- Since:
- 3.1
- Author:
- Gary Russell
- 
Field SummaryFieldsModifier 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 SummaryModifier 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.adminTimeout(int adminTimeout) Set the timeout in seconds for admin operations (e.g.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_TIMEOUTstatic final int DEFAULT_ADMIN_TIMEOUT- See Also:
 
- 
BEAN_NAME- See Also:
 
- 
BROKER_LIST_PROPERTYSet 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- 
kafkaPortsSet 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
- 
destroydefault void destroy()- Specified by:
- destroyin interface- DisposableBean
 
- 
afterPropertiesSetdefault void afterPropertiesSet()- Specified by:
- afterPropertiesSetin interface- InitializingBean
 
- 
brokerPropertiesSpecify 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:
 
- 
brokerListPropertySet 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.
 
- 
adminTimeoutSet the timeout in seconds for admin operations (e.g. topic creation, close).- Parameters:
- adminTimeout- the timeout.
- Returns:
- the EmbeddedKafkaBroker
- Since:
- 2.8.5
 
- 
getBrokersAsStringString getBrokersAsString()Get the bootstrap server addresses as a String.- Returns:
- the bootstrap servers.
 
- 
addTopicsAdd topics to the existing broker(s) using the configured number of partitions. The broker(s) must be running.- Parameters:
- topicsToAdd- the topics.
 
- 
addTopicsvoid 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
- 
addTopicsWithResults
- 
consumeFromEmbeddedTopicsvoid 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.
- seekToEnd- true to seek to the end instead of the beginning.
- topicsToConsume- the topics.
- Throws:
- IllegalStateException- if you attempt to consume from a topic that is not in the list of embedded topics.
 
- 
consumeFromEmbeddedTopicsvoid 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.
 
- 
consumeFromAnEmbeddedTopicvoid 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.
 
- 
consumeFromAnEmbeddedTopicvoid 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.
 
- 
consumeFromAllEmbeddedTopicsvoid consumeFromAllEmbeddedTopics(org.apache.kafka.clients.consumer.Consumer<?, ?> consumer, boolean seekToEnd) Subscribe a consumer to all the embedded topics.- Parameters:
- consumer- the consumer.
- seekToEnd- true to seek to the end instead of the beginning.
 
- 
consumeFromAllEmbeddedTopicsvoid consumeFromAllEmbeddedTopics(org.apache.kafka.clients.consumer.Consumer<?, ?> consumer) Subscribe a consumer to all the embedded topics.- Parameters:
- consumer- the consumer.
 
- 
getPartitionsPerTopicint getPartitionsPerTopic()Get the configured number of partitions per topic.- Returns:
- the partition count.
 
 
-