Package org.springframework.kafka.config
Class AbstractKafkaListenerContainerFactory<C extends AbstractMessageListenerContainer<K,V>,K,V>
java.lang.Object
org.springframework.kafka.config.AbstractKafkaListenerContainerFactory<C,K,V>
- Type Parameters:
C
- theAbstractMessageListenerContainer
implementation type.K
- the key type.V
- the value type.
- All Implemented Interfaces:
Aware
,InitializingBean
,ApplicationContextAware
,ApplicationEventPublisherAware
,KafkaListenerContainerFactory<C>
- Direct Known Subclasses:
ConcurrentKafkaListenerContainerFactory
public abstract class AbstractKafkaListenerContainerFactory<C extends AbstractMessageListenerContainer<K,V>,K,V>
extends Object
implements KafkaListenerContainerFactory<C>, ApplicationEventPublisherAware, InitializingBean, ApplicationContextAware
Base
KafkaListenerContainerFactory
for Spring's base container implementation.- Author:
- Stephane Nicoll, Gary Russell, Artem Bilan
- See Also:
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
createContainer
(String... topics) Create and configure a container without a listener; used to create containers that are not used for KafkaListener annotations.createContainer
(Pattern topicPattern) Create and configure a container without a listener; used to create containers that are not used for KafkaListener annotations.createContainer
(TopicPartitionOffset... topicsAndPartitions) Create and configure a container without a listener; used to create containers that are not used for KafkaListener annotations.protected abstract C
createContainerInstance
(KafkaListenerEndpoint endpoint) Create an empty container instance.createListenerContainer
(KafkaListenerEndpoint endpoint) Create aMessageListenerContainer
for the givenKafkaListenerEndpoint
.ConsumerFactory<? super K,
? super V> Obtain the properties template for this factory - set properties as needed and they will be copied to a final properties instance for the endpoint.protected void
initializeContainer
(C instance, KafkaListenerEndpoint endpoint) Further initialize the specified container.Return true if this endpoint creates a batch listener.void
setAckDiscarded
(Boolean ackDiscarded) Set to true to ack discards when a filter strategy is in use.void
setAfterRollbackProcessor
(AfterRollbackProcessor<? super K, ? super V> afterRollbackProcessor) Set a processor to invoke after a transaction rollback; typically will seek the unprocessed topic/partition to reprocess the records.void
setApplicationContext
(ApplicationContext applicationContext) void
setApplicationEventPublisher
(ApplicationEventPublisher applicationEventPublisher) void
setAutoStartup
(Boolean autoStartup) Specify anautoStartup boolean
flag.void
setBatchErrorHandler
(BatchErrorHandler errorHandler) Deprecated.void
setBatchInterceptor
(BatchInterceptor<K, V> batchInterceptor) Set a batch interceptor to be called before and after calling the listener.void
setBatchListener
(Boolean batchListener) Set to true if this endpoint should create a batch listener.void
setBatchToRecordAdapter
(BatchToRecordAdapter<K, V> batchToRecordAdapter) Set aBatchToRecordAdapter
.void
setCommonErrorHandler
(CommonErrorHandler commonErrorHandler) Set theCommonErrorHandler
which can handle errors for both record and batch listeners.void
setConsumerFactory
(ConsumerFactory<? super K, ? super V> consumerFactory) Specify aConsumerFactory
to use.void
setContainerCustomizer
(ContainerCustomizer<K, V, C> containerCustomizer) Set a customizer used to further configure a container after it has been created.void
setErrorHandler
(ErrorHandler errorHandler) Deprecated.in favor ofsetCommonErrorHandler(CommonErrorHandler)
void
setMessageConverter
(MessageConverter messageConverter) Set the message converter to use if dynamic argument type matching is needed.void
setMissingTopicsFatal
(boolean missingTopicsFatal) Set to false to allow the container to start even if any of the configured topics are not present on the broker.void
setPhase
(int phase) Specify aphase
to use.void
setRecordFilterStrategy
(RecordFilterStrategy<? super K, ? super V> recordFilterStrategy) Set the record filter strategy.void
setRecordInterceptor
(RecordInterceptor<K, V> recordInterceptor) Set an interceptor to be called before calling the listener.void
setRecoveryCallback
(org.springframework.retry.RecoveryCallback<? extends Object> recoveryCallback) Deprecated.since 2.8 - use a suitably configured error handler instead.void
setReplyHeadersConfigurer
(ReplyHeadersConfigurer replyHeadersConfigurer) Set a configurer which will be invoked when creating a reply message.void
setReplyTemplate
(KafkaTemplate<?, ?> replyTemplate) Set theKafkaTemplate
to use to send replies.void
setRetryTemplate
(org.springframework.retry.support.RetryTemplate retryTemplate) Deprecated.since 2.8 - use a suitably configured error handler instead.void
setStatefulRetry
(boolean statefulRetry) Deprecated.since 2.8 - use a suitably configured error handler instead.
-
Field Details
-
logger
-
-
Constructor Details
-
AbstractKafkaListenerContainerFactory
public AbstractKafkaListenerContainerFactory()
-
-
Method Details
-
setApplicationContext
- Specified by:
setApplicationContext
in interfaceApplicationContextAware
- Throws:
BeansException
-
setConsumerFactory
Specify aConsumerFactory
to use.- Parameters:
consumerFactory
- The consumer factory.
-
getConsumerFactory
-
setAutoStartup
Specify anautoStartup boolean
flag.- Parameters:
autoStartup
- true for auto startup.- See Also:
-
setPhase
public void setPhase(int phase) Specify aphase
to use.- Parameters:
phase
- The phase.- See Also:
-
setMessageConverter
Set the message converter to use if dynamic argument type matching is needed.- Parameters:
messageConverter
- the converter.
-
setRecordFilterStrategy
Set the record filter strategy.- Parameters:
recordFilterStrategy
- the strategy.
-
setAckDiscarded
Set to true to ack discards when a filter strategy is in use.- Parameters:
ackDiscarded
- the ackDiscarded.
-
setRetryTemplate
@Deprecated public void setRetryTemplate(org.springframework.retry.support.RetryTemplate retryTemplate) Deprecated.since 2.8 - use a suitably configured error handler instead.Set a retryTemplate.- Parameters:
retryTemplate
- the template.
-
setRecoveryCallback
@Deprecated public void setRecoveryCallback(org.springframework.retry.RecoveryCallback<? extends Object> recoveryCallback) Deprecated.since 2.8 - use a suitably configured error handler instead.Set a callback to be used with theretryTemplate
.- Parameters:
recoveryCallback
- the callback.
-
setStatefulRetry
Deprecated.since 2.8 - use a suitably configured error handler instead.When using aRetryTemplate
Set to true to enable stateful retry. Use in conjunction with aorg.springframework.kafka.listener.SeekToCurrentErrorHandler
when retry can take excessive time; each failure goes back to the broker, to keep the Consumer alive.- Parameters:
statefulRetry
- true to enable stateful retry.- Since:
- 2.1.3
-
isBatchListener
Return true if this endpoint creates a batch listener.- Returns:
- true for a batch listener.
- Since:
- 1.1
-
setBatchListener
Set to true if this endpoint should create a batch listener.- Parameters:
batchListener
- true for a batch listener.- Since:
- 1.1
-
setApplicationEventPublisher
- Specified by:
setApplicationEventPublisher
in interfaceApplicationEventPublisherAware
-
setReplyTemplate
Set theKafkaTemplate
to use to send replies.- Parameters:
replyTemplate
- the template.- Since:
- 2.0
-
setErrorHandler
Deprecated.in favor ofsetCommonErrorHandler(CommonErrorHandler)
Set the error handler to call when the listener throws an exception.- Parameters:
errorHandler
- the error handler.- Since:
- 2.2
- See Also:
-
setBatchErrorHandler
Deprecated.in favor ofsetCommonErrorHandler(CommonErrorHandler)
Set the batch error handler to call when the listener throws an exception.- Parameters:
errorHandler
- the error handler.- Since:
- 2.2
- See Also:
-
setCommonErrorHandler
Set theCommonErrorHandler
which can handle errors for both record and batch listeners. Replaces the use ofGenericErrorHandler
s.- Parameters:
commonErrorHandler
- the handler.- Since:
- 2.8
-
setAfterRollbackProcessor
public void setAfterRollbackProcessor(AfterRollbackProcessor<? super K, ? super V> afterRollbackProcessor) Set a processor to invoke after a transaction rollback; typically will seek the unprocessed topic/partition to reprocess the records. The default does so, including the failed record.- Parameters:
afterRollbackProcessor
- the processor.- Since:
- 1.3.5
-
setReplyHeadersConfigurer
Set a configurer which will be invoked when creating a reply message.- Parameters:
replyHeadersConfigurer
- the configurer.- Since:
- 2.2
-
setMissingTopicsFatal
public void setMissingTopicsFatal(boolean missingTopicsFatal) Set to false to allow the container to start even if any of the configured topics are not present on the broker. Does not apply when topic patterns are configured. Default true;- Parameters:
missingTopicsFatal
- the missingTopicsFatal.- Since:
- 2.3
-
getContainerProperties
Obtain the properties template for this factory - set properties as needed and they will be copied to a final properties instance for the endpoint.- Returns:
- the properties.
-
setRecordInterceptor
Set an interceptor to be called before calling the listener. Only used with record listeners.- Parameters:
recordInterceptor
- the interceptor.- Since:
- 2.2.7
- See Also:
-
setBatchInterceptor
Set a batch interceptor to be called before and after calling the listener. Only used with batch listeners.- Parameters:
batchInterceptor
- the interceptor.- Since:
- 2.7
- See Also:
-
setBatchToRecordAdapter
Set aBatchToRecordAdapter
.- Parameters:
batchToRecordAdapter
- the adapter.- Since:
- 2.4.2
-
setContainerCustomizer
Set a customizer used to further configure a container after it has been created.- Parameters:
containerCustomizer
- the customizer.- Since:
- 2.3.4
-
afterPropertiesSet
public void afterPropertiesSet()- Specified by:
afterPropertiesSet
in interfaceInitializingBean
-
createListenerContainer
Description copied from interface:KafkaListenerContainerFactory
Create aMessageListenerContainer
for the givenKafkaListenerEndpoint
. Containers created using this method are added to the listener endpoint registry.- Specified by:
createListenerContainer
in interfaceKafkaListenerContainerFactory<C extends AbstractMessageListenerContainer<K,
V>> - Parameters:
endpoint
- the endpoint to configure- Returns:
- the created container
-
createContainerInstance
Create an empty container instance.- Parameters:
endpoint
- the endpoint.- Returns:
- the new container instance.
-
initializeContainer
Further initialize the specified container.Subclasses can inherit from this method to apply extra configuration if necessary.
- Parameters:
instance
- the container instance to configure.endpoint
- the endpoint.
-
createContainer
Description copied from interface:KafkaListenerContainerFactory
Create and configure a container without a listener; used to create containers that are not used for KafkaListener annotations. Containers created using this method are not added to the listener endpoint registry.- Specified by:
createContainer
in interfaceKafkaListenerContainerFactory<C extends AbstractMessageListenerContainer<K,
V>> - Parameters:
topicsAndPartitions
- the topicPartitions to assign.- Returns:
- the container.
-
createContainer
Description copied from interface:KafkaListenerContainerFactory
Create and configure a container without a listener; used to create containers that are not used for KafkaListener annotations. Containers created using this method are not added to the listener endpoint registry.- Specified by:
createContainer
in interfaceKafkaListenerContainerFactory<C extends AbstractMessageListenerContainer<K,
V>> - Parameters:
topics
- the topics.- Returns:
- the container.
-
createContainer
Description copied from interface:KafkaListenerContainerFactory
Create and configure a container without a listener; used to create containers that are not used for KafkaListener annotations. Containers created using this method are not added to the listener endpoint registry.- Specified by:
createContainer
in interfaceKafkaListenerContainerFactory<C extends AbstractMessageListenerContainer<K,
V>> - Parameters:
topicPattern
- the topicPattern.- Returns:
- the container.
-
setCommonErrorHandler(CommonErrorHandler)