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
public class KafkaAdmin extends KafkaResourceFactory implements org.springframework.context.ApplicationContextAware, org.springframework.beans.factory.SmartInitializingSingleton
An admin that delegates to anAdminClient
to create topics defined in the application context.- Since:
- 1.3
- Author:
- Gary Russell, Artem Bilan
-
-
Field Summary
Fields Modifier and Type Field Description static java.time.Duration
DEFAULT_CLOSE_TIMEOUT
The default close timeout duration as 10 seconds.
-
Constructor Summary
Constructors Constructor Description KafkaAdmin(java.util.Map<java.lang.String,java.lang.Object> config)
Create an instance with anAdminClient
based on the supplied configuration.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
afterSingletonsInstantiated()
java.util.Map<java.lang.String,java.lang.Object>
getConfigurationProperties()
Get an unmodifiable copy of this admin's configuration.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, andfatalIfBrokerNotAvailable
is false, orautoCreate
was set to false.void
setApplicationContext(org.springframework.context.ApplicationContext applicationContext)
void
setAutoCreate(boolean autoCreate)
Set to false to suppress auto creation of topics during context initialization.void
setCloseTimeout(int closeTimeout)
Set the close timeout in seconds.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.void
setOperationTimeout(int operationTimeout)
Set the operation timeout in seconds.-
Methods inherited from class org.springframework.kafka.core.KafkaResourceFactory
checkBootstrap, getBootstrapServers, setBootstrapServersSupplier
-
-
-
-
Method Detail
-
setApplicationContext
public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext) throws org.springframework.beans.BeansException
- Specified by:
setApplicationContext
in interfaceorg.springframework.context.ApplicationContextAware
- Throws:
org.springframework.beans.BeansException
-
setCloseTimeout
public void setCloseTimeout(int closeTimeout)
Set the close timeout in seconds. Defaults toDEFAULT_CLOSE_TIMEOUT
seconds.- Parameters:
closeTimeout
- the timeout.
-
setOperationTimeout
public void setOperationTimeout(int operationTimeout)
Set the operation timeout in seconds. Defaults to 30 seconds.- Parameters:
operationTimeout
- the timeout.
-
setFatalIfBrokerNotAvailable
public 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.
-
setAutoCreate
public 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()
-
getConfigurationProperties
public java.util.Map<java.lang.String,java.lang.Object> getConfigurationProperties()
Get an unmodifiable copy of this admin's configuration.- Returns:
- the configuration map.
-
afterSingletonsInstantiated
public void afterSingletonsInstantiated()
- Specified by:
afterSingletonsInstantiated
in interfaceorg.springframework.beans.factory.SmartInitializingSingleton
-
initialize
public 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, andfatalIfBrokerNotAvailable
is false, orautoCreate
was set to false.- Returns:
- true if successful.
- See Also:
setFatalIfBrokerNotAvailable(boolean)
,setAutoCreate(boolean)
-
-