Package org.springframework.kafka.config
Class StreamsBuilderFactoryBean
- java.lang.Object
-
- org.springframework.beans.factory.config.AbstractFactoryBean<org.apache.kafka.streams.StreamsBuilder>
-
- org.springframework.kafka.config.StreamsBuilderFactoryBean
-
- All Implemented Interfaces:
org.springframework.beans.factory.Aware,org.springframework.beans.factory.BeanClassLoaderAware,org.springframework.beans.factory.BeanFactoryAware,org.springframework.beans.factory.BeanNameAware,org.springframework.beans.factory.DisposableBean,org.springframework.beans.factory.FactoryBean<org.apache.kafka.streams.StreamsBuilder>,org.springframework.beans.factory.InitializingBean,org.springframework.context.Lifecycle,org.springframework.context.Phased,org.springframework.context.SmartLifecycle
public class StreamsBuilderFactoryBean extends org.springframework.beans.factory.config.AbstractFactoryBean<org.apache.kafka.streams.StreamsBuilder> implements org.springframework.context.SmartLifecycle, org.springframework.beans.factory.BeanNameAwareAnAbstractFactoryBeanfor theStreamsBuilderinstance and lifecycle control for the internalKafkaStreamsinstance.A fine grained control on
KafkaStreamscan be achieved byKafkaStreamsCustomizers.- Since:
- 1.1.4
- Author:
- Artem Bilan, Ivan Ursul, Soby Chacko, Zach Olauson, Nurettin Yilmaz, Denis Washington, Gary Russell
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceStreamsBuilderFactoryBean.ListenerCalled whenever aKafkaStreamsis added or removed.
-
Field Summary
Fields Modifier and Type Field Description static java.time.DurationDEFAULT_CLOSE_TIMEOUTThe defaultDurationof10 secondsfor close timeout.
-
Constructor Summary
Constructors Constructor Description StreamsBuilderFactoryBean()Default constructor that creates the factory without configurationProperties.StreamsBuilderFactoryBean(KafkaStreamsConfiguration streamsConfig)Construct an instance with the supplied streams configuration.StreamsBuilderFactoryBean(KafkaStreamsConfiguration streamsConfig, CleanupConfig cleanupConfig)Construct an instance with the supplied streams configuration and clean up configuration.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddListener(StreamsBuilderFactoryBean.Listener listener)Add aStreamsBuilderFactoryBean.Listenerwhich will be called after starting and stopping the streams.protected org.apache.kafka.streams.StreamsBuildercreateInstance()org.apache.kafka.streams.KafkaStreamsgetKafkaStreams()Get a managed by thisStreamsBuilderFactoryBeanKafkaStreamsinstance.java.util.List<StreamsBuilderFactoryBean.Listener>getListeners()Get the current list of listeners.java.lang.Class<?>getObjectType()intgetPhase()java.util.PropertiesgetStreamsConfiguration()org.apache.kafka.streams.TopologygetTopology()Providing access to the associatedTopologyof thisStreamsBuilderFactoryBean.booleanisAutoStartup()booleanisRunning()booleanremoveListener(StreamsBuilderFactoryBean.Listener listener)Remove a listener.voidsetAutoStartup(boolean autoStartup)voidsetBeanName(java.lang.String name)voidsetCleanupConfig(CleanupConfig cleanupConfig)voidsetClientSupplier(org.apache.kafka.streams.KafkaClientSupplier clientSupplier)voidsetCloseTimeout(int closeTimeout)Specify the timeout in seconds for theKafkaStreams.close(Duration)operation.voidsetInfrastructureCustomizer(KafkaStreamsInfrastructureCustomizer infrastructureCustomizer)Set a customizer to configure the builder and/or topology before creating the stream.voidsetKafkaStreamsCustomizer(KafkaStreamsCustomizer kafkaStreamsCustomizer)voidsetPhase(int phase)voidsetStateListener(org.apache.kafka.streams.KafkaStreams.StateListener stateListener)voidsetStateRestoreListener(org.apache.kafka.streams.processor.StateRestoreListener stateRestoreListener)voidsetStreamsConfiguration(java.util.Properties streamsConfig)Set the streams configurationPropertieson this factory.voidsetUncaughtExceptionHandler(java.lang.Thread.UncaughtExceptionHandler exceptionHandler)voidstart()voidstop()voidstop(java.lang.Runnable callback)
-
-
-
Constructor Detail
-
StreamsBuilderFactoryBean
public StreamsBuilderFactoryBean()
Default constructor that creates the factory without configurationProperties. It is the factory user's responsibility to properly setPropertiesusingsetStreamsConfiguration(Properties).- Since:
- 2.1.3.
-
StreamsBuilderFactoryBean
public StreamsBuilderFactoryBean(KafkaStreamsConfiguration streamsConfig, CleanupConfig cleanupConfig)
Construct an instance with the supplied streams configuration and clean up configuration.- Parameters:
streamsConfig- the streams configuration.cleanupConfig- the cleanup configuration.- Since:
- 2.2
-
StreamsBuilderFactoryBean
public StreamsBuilderFactoryBean(KafkaStreamsConfiguration streamsConfig)
Construct an instance with the supplied streams configuration.- Parameters:
streamsConfig- the streams configuration.- Since:
- 2.2
-
-
Method Detail
-
setBeanName
public void setBeanName(java.lang.String name)
- Specified by:
setBeanNamein interfaceorg.springframework.beans.factory.BeanNameAware
-
setStreamsConfiguration
public void setStreamsConfiguration(java.util.Properties streamsConfig)
Set the streams configurationPropertieson this factory.- Parameters:
streamsConfig- the streams configuration.- Since:
- 2.2
-
getStreamsConfiguration
@Nullable public java.util.Properties getStreamsConfiguration()
-
setClientSupplier
public void setClientSupplier(org.apache.kafka.streams.KafkaClientSupplier clientSupplier)
-
setInfrastructureCustomizer
public void setInfrastructureCustomizer(KafkaStreamsInfrastructureCustomizer infrastructureCustomizer)
Set a customizer to configure the builder and/or topology before creating the stream.- Parameters:
infrastructureCustomizer- the customizer- Since:
- 2.4.1
-
setKafkaStreamsCustomizer
public void setKafkaStreamsCustomizer(KafkaStreamsCustomizer kafkaStreamsCustomizer)
- Parameters:
kafkaStreamsCustomizer- theKafkaStreamsCustomizerto use.- Since:
- 2.1.5
-
setStateListener
public void setStateListener(org.apache.kafka.streams.KafkaStreams.StateListener stateListener)
-
setUncaughtExceptionHandler
public void setUncaughtExceptionHandler(java.lang.Thread.UncaughtExceptionHandler exceptionHandler)
-
setStateRestoreListener
public void setStateRestoreListener(org.apache.kafka.streams.processor.StateRestoreListener stateRestoreListener)
-
setCloseTimeout
public void setCloseTimeout(int closeTimeout)
Specify the timeout in seconds for theKafkaStreams.close(Duration)operation. Defaults toDEFAULT_CLOSE_TIMEOUTseconds.- Parameters:
closeTimeout- the timeout for close in seconds.- See Also:
KafkaStreams.close(Duration)
-
getTopology
public org.apache.kafka.streams.Topology getTopology()
Providing access to the associatedTopologyof thisStreamsBuilderFactoryBean.- Returns:
Topologyobject- Since:
- 2.4.4
-
getObjectType
public java.lang.Class<?> getObjectType()
- Specified by:
getObjectTypein interfaceorg.springframework.beans.factory.FactoryBean<org.apache.kafka.streams.StreamsBuilder>- Specified by:
getObjectTypein classorg.springframework.beans.factory.config.AbstractFactoryBean<org.apache.kafka.streams.StreamsBuilder>
-
setAutoStartup
public void setAutoStartup(boolean autoStartup)
-
setPhase
public void setPhase(int phase)
-
getPhase
public int getPhase()
- Specified by:
getPhasein interfaceorg.springframework.context.Phased- Specified by:
getPhasein interfaceorg.springframework.context.SmartLifecycle
-
setCleanupConfig
public void setCleanupConfig(CleanupConfig cleanupConfig)
-
getKafkaStreams
public org.apache.kafka.streams.KafkaStreams getKafkaStreams()
Get a managed by thisStreamsBuilderFactoryBeanKafkaStreamsinstance.- Returns:
- KafkaStreams managed instance;
may be null if this
StreamsBuilderFactoryBeanhasn't been started. - Since:
- 1.1.4
-
getListeners
public java.util.List<StreamsBuilderFactoryBean.Listener> getListeners()
Get the current list of listeners.- Returns:
- the listeners.
- Since:
- 2.5.3
-
addListener
public void addListener(StreamsBuilderFactoryBean.Listener listener)
Add aStreamsBuilderFactoryBean.Listenerwhich will be called after starting and stopping the streams.- Parameters:
listener- the listener.- Since:
- 2.5.3
-
removeListener
public boolean removeListener(StreamsBuilderFactoryBean.Listener listener)
Remove a listener.- Parameters:
listener- the listener.- Returns:
- true if removed.
- Since:
- 2.5.3
-
createInstance
protected org.apache.kafka.streams.StreamsBuilder createInstance()
- Specified by:
createInstancein classorg.springframework.beans.factory.config.AbstractFactoryBean<org.apache.kafka.streams.StreamsBuilder>
-
isAutoStartup
public boolean isAutoStartup()
- Specified by:
isAutoStartupin interfaceorg.springframework.context.SmartLifecycle
-
stop
public void stop(java.lang.Runnable callback)
- Specified by:
stopin interfaceorg.springframework.context.SmartLifecycle
-
start
public void start()
- Specified by:
startin interfaceorg.springframework.context.Lifecycle
-
stop
public void stop()
- Specified by:
stopin interfaceorg.springframework.context.Lifecycle
-
isRunning
public boolean isRunning()
- Specified by:
isRunningin interfaceorg.springframework.context.Lifecycle
-
-