Package org.springframework.kafka.core
Class KafkaAdmin
- java.lang.Object
- 
- org.springframework.kafka.core.KafkaResourceFactory
- 
- org.springframework.kafka.core.KafkaAdmin
 
 
- 
- All Implemented Interfaces:
- org.springframework.beans.factory.Aware,- org.springframework.beans.factory.SmartInitializingSingleton,- org.springframework.context.ApplicationContextAware,- KafkaAdminOperations
 
 public class KafkaAdmin extends KafkaResourceFactory implements org.springframework.context.ApplicationContextAware, org.springframework.beans.factory.SmartInitializingSingleton, KafkaAdminOperations An admin that delegates to anAdminClientto create topics defined in the application context.- Since:
- 1.3
- Author:
- Gary Russell, Artem Bilan
 
- 
- 
Nested Class SummaryNested Classes Modifier and Type Class Description static classKafkaAdmin.NewTopicsWrapper for a collection ofNewTopicto facilitated declaring multiple topics as as single bean.
 - 
Field SummaryFields Modifier and Type Field Description static java.time.DurationDEFAULT_CLOSE_TIMEOUTThe default close timeout duration as 10 seconds.
 - 
Constructor SummaryConstructors Constructor Description KafkaAdmin(java.util.Map<java.lang.String,java.lang.Object> config)Create an instance with anAdminClientbased on the supplied configuration.
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description voidafterSingletonsInstantiated()voidcreateOrModifyTopics(org.apache.kafka.clients.admin.NewTopic... topics)Create topics if they don't exist or increase the number of partitions if needed.java.util.Map<java.lang.String,org.apache.kafka.clients.admin.TopicDescription>describeTopics(java.lang.String... topicNames)ObtainTopicDescriptions for these topics.java.util.Map<java.lang.String,java.lang.Object>getConfigurationProperties()Get an unmodifiable copy of this admin's configuration.booleaninitialize()Call this method to check/add topics; this might be needed if the broker was not available when the application context was initialized, andfatalIfBrokerNotAvailableis false, orautoCreatewas set to false.voidsetApplicationContext(org.springframework.context.ApplicationContext applicationContext)voidsetAutoCreate(boolean autoCreate)Set to false to suppress auto creation of topics during context initialization.voidsetCloseTimeout(int closeTimeout)Set the close timeout in seconds.voidsetFatalIfBrokerNotAvailable(boolean fatalIfBrokerNotAvailable)Set to true if you want the application context to fail to load if we are unable to connect to the broker during initialization, to check/add topics.voidsetOperationTimeout(int operationTimeout)Set the operation timeout in seconds.- 
Methods inherited from class org.springframework.kafka.core.KafkaResourceFactorycheckBootstrap, getBootstrapServers, setBootstrapServersSupplier
 
- 
 
- 
- 
- 
Method Detail- 
setApplicationContextpublic void setApplicationContext(org.springframework.context.ApplicationContext applicationContext) throws org.springframework.beans.BeansException- Specified by:
- setApplicationContextin interface- org.springframework.context.ApplicationContextAware
- Throws:
- org.springframework.beans.BeansException
 
 - 
setCloseTimeoutpublic void setCloseTimeout(int closeTimeout) Set the close timeout in seconds. Defaults toDEFAULT_CLOSE_TIMEOUTseconds.- Parameters:
- closeTimeout- the timeout.
 
 - 
setOperationTimeoutpublic void setOperationTimeout(int operationTimeout) Set the operation timeout in seconds. Defaults to 30 seconds.- Parameters:
- operationTimeout- the timeout.
 
 - 
setFatalIfBrokerNotAvailablepublic void setFatalIfBrokerNotAvailable(boolean fatalIfBrokerNotAvailable) Set to true if you want the application context to fail to load if we are unable to connect to the broker during initialization, to check/add topics.- Parameters:
- fatalIfBrokerNotAvailable- true to fail.
 
 - 
setAutoCreatepublic void setAutoCreate(boolean autoCreate) Set to false to suppress auto creation of topics during context initialization.- Parameters:
- autoCreate- boolean flag to indicate creating topics or not during context initialization
- See Also:
- initialize()
 
 - 
getConfigurationPropertiespublic java.util.Map<java.lang.String,java.lang.Object> getConfigurationProperties() Description copied from interface:KafkaAdminOperationsGet an unmodifiable copy of this admin's configuration.- Specified by:
- getConfigurationPropertiesin interface- KafkaAdminOperations
- Returns:
- the configuration map.
 
 - 
afterSingletonsInstantiatedpublic void afterSingletonsInstantiated() - Specified by:
- afterSingletonsInstantiatedin interface- org.springframework.beans.factory.SmartInitializingSingleton
 
 - 
initializepublic final boolean initialize() Call this method to check/add topics; this might be needed if the broker was not available when the application context was initialized, andfatalIfBrokerNotAvailableis false, orautoCreatewas set to false.- Returns:
- true if successful.
- See Also:
- setFatalIfBrokerNotAvailable(boolean),- setAutoCreate(boolean)
 
 - 
createOrModifyTopicspublic void createOrModifyTopics(org.apache.kafka.clients.admin.NewTopic... topics) Description copied from interface:KafkaAdminOperationsCreate topics if they don't exist or increase the number of partitions if needed.- Specified by:
- createOrModifyTopicsin interface- KafkaAdminOperations
- Parameters:
- topics- the topics.
 
 - 
describeTopicspublic java.util.Map<java.lang.String,org.apache.kafka.clients.admin.TopicDescription> describeTopics(java.lang.String... topicNames) Description copied from interface:KafkaAdminOperationsObtainTopicDescriptions for these topics.- Specified by:
- describeTopicsin interface- KafkaAdminOperations
- Parameters:
- topicNames- the topic names.
- Returns:
- a map of name:topicDescription.
 
 
- 
 
-