Class StreamsBuilderFactoryBean
java.lang.Object
org.springframework.beans.factory.config.AbstractFactoryBean<org.apache.kafka.streams.StreamsBuilder>
org.springframework.kafka.config.StreamsBuilderFactoryBean
- All Implemented Interfaces:
Aware,BeanClassLoaderAware,BeanFactoryAware,BeanNameAware,DisposableBean,FactoryBean<org.apache.kafka.streams.StreamsBuilder>,InitializingBean,SmartInitializingSingleton,Lifecycle,Phased,SmartLifecycle
public class StreamsBuilderFactoryBean
extends AbstractFactoryBean<org.apache.kafka.streams.StreamsBuilder>
implements SmartLifecycle, BeanNameAware, SmartInitializingSingleton
An
AbstractFactoryBean for the StreamsBuilder instance
and lifecycle control for the internal KafkaStreams instance.
A fine grained control on KafkaStreams can be achieved by
KafkaStreamsCustomizers.
- Since:
- 1.1.4
- Author:
- Artem Bilan, Ivan Ursul, Soby Chacko, Zach Olauson, Nurettin Yilmaz, Denis Washington, Gary Russell, Julien Wittouck, Sanghyeok An, Cédric Schaller, Almog Gavra
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceCalled whenever aKafkaStreamsis added or removed. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final DurationThe defaultDurationof10 secondsfor close timeout.Fields inherited from class org.springframework.beans.factory.config.AbstractFactoryBean
loggerFields inherited from interface org.springframework.beans.factory.FactoryBean
OBJECT_TYPE_ATTRIBUTEFields inherited from interface org.springframework.context.SmartLifecycle
DEFAULT_PHASE -
Constructor Summary
ConstructorsConstructorDescriptionDefault 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
Modifier and TypeMethodDescriptionvoidAdd aStreamsBuilderFactoryBean.Listenerwhich will be called after starting and stopping the streams.voidprotected org.apache.kafka.streams.StreamsBuilder@Nullable org.apache.kafka.streams.KafkaStreamsGet a managed by thisStreamsBuilderFactoryBeanKafkaStreamsinstance.Get the current list of listeners.Class<?> intgetPhase()@Nullable Properties@Nullable org.apache.kafka.streams.errors.StreamsUncaughtExceptionHandlerRetrieves the currentStreamsUncaughtExceptionHandlerset on this factory bean.org.apache.kafka.streams.TopologyProviding access to the associatedTopologyof thisStreamsBuilderFactoryBean.booleanbooleanbooleanRemove a listener.voidsetAutoStartup(boolean autoStartup) voidsetBeanName(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) voidsetLeaveGroupOnClose(boolean leaveGroupOnClose) Specify if the consumer should leave the group when stopping Kafka Streams.voidsetPhase(int phase) voidsetStateListener(org.apache.kafka.streams.KafkaStreams.StateListener stateListener) voidsetStateRestoreListener(org.apache.kafka.streams.processor.StateRestoreListener stateRestoreListener) voidsetStreamsConfiguration(Properties streamsConfig) Set the streams configurationPropertieson this factory.voidsetStreamsUncaughtExceptionHandler(org.apache.kafka.streams.errors.StreamsUncaughtExceptionHandler streamsUncaughtExceptionHandler) Set aStreamsUncaughtExceptionHandler.voidstart()voidstop()voidMethods inherited from class org.springframework.beans.factory.config.AbstractFactoryBean
afterPropertiesSet, destroy, destroyInstance, getBeanFactory, getBeanTypeConverter, getEarlySingletonInterfaces, getObject, isSingleton, setBeanClassLoader, setBeanFactory, setSingletonMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.context.SmartLifecycle
isPauseable
-
Field Details
-
DEFAULT_CLOSE_TIMEOUT
-
-
Constructor Details
-
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
Construct an instance with the supplied streams configuration.- Parameters:
streamsConfig- the streams configuration.- Since:
- 2.2
-
-
Method Details
-
setBeanName
- Specified by:
setBeanNamein interfaceBeanNameAware
-
setStreamsConfiguration
Set the streams configurationPropertieson this factory.- Parameters:
streamsConfig- the streams configuration.- Since:
- 2.2
-
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
- Parameters:
kafkaStreamsCustomizer- theKafkaStreamsCustomizerto use.- Since:
- 2.1.5
-
setStateListener
public void setStateListener(org.apache.kafka.streams.KafkaStreams.StateListener stateListener) -
setStreamsUncaughtExceptionHandler
public void setStreamsUncaughtExceptionHandler(org.apache.kafka.streams.errors.StreamsUncaughtExceptionHandler streamsUncaughtExceptionHandler) Set aStreamsUncaughtExceptionHandler.- Parameters:
streamsUncaughtExceptionHandler- the handler.- Since:
- 2.8
-
getStreamsUncaughtExceptionHandler
public @Nullable org.apache.kafka.streams.errors.StreamsUncaughtExceptionHandler getStreamsUncaughtExceptionHandler()Retrieves the currentStreamsUncaughtExceptionHandlerset on this factory bean.- Returns:
StreamsUncaughtExceptionHandler- Since:
- 2.8.4
-
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:
-
setLeaveGroupOnClose
public void setLeaveGroupOnClose(boolean leaveGroupOnClose) Specify if the consumer should leave the group when stopping Kafka Streams. Defaults to false.- Parameters:
leaveGroupOnClose- true to leave the group when stopping the Streams- Since:
- 3.2.0
-
getTopology
public org.apache.kafka.streams.Topology getTopology()Providing access to the associatedTopologyof thisStreamsBuilderFactoryBean.- Returns:
Topologyobject- Since:
- 2.4.4
-
getObjectType
- Specified by:
getObjectTypein interfaceFactoryBean<org.apache.kafka.streams.StreamsBuilder>- Specified by:
getObjectTypein classAbstractFactoryBean<org.apache.kafka.streams.StreamsBuilder>
-
setAutoStartup
public void setAutoStartup(boolean autoStartup) -
setPhase
public void setPhase(int phase) -
getPhase
public int getPhase()- Specified by:
getPhasein interfacePhased- Specified by:
getPhasein interfaceSmartLifecycle
-
setCleanupConfig
-
getKafkaStreams
public @Nullable 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
Get the current list of listeners.- Returns:
- the listeners.
- Since:
- 2.5.3
-
addListener
Add aStreamsBuilderFactoryBean.Listenerwhich will be called after starting and stopping the streams.- Parameters:
listener- the listener.- Since:
- 2.5.3
-
removeListener
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 classAbstractFactoryBean<org.apache.kafka.streams.StreamsBuilder>
-
isAutoStartup
public boolean isAutoStartup()- Specified by:
isAutoStartupin interfaceSmartLifecycle
-
stop
- Specified by:
stopin interfaceSmartLifecycle
-
start
-
stop
-
isRunning
-
afterSingletonsInstantiated
public void afterSingletonsInstantiated()- Specified by:
afterSingletonsInstantiatedin interfaceSmartInitializingSingleton
-