K
- the key type.V
- the value type.public abstract class AbstractMessageListenerContainer<K,V> extends java.lang.Object implements GenericMessageListenerContainer<K,V>, org.springframework.beans.factory.BeanNameAware, org.springframework.context.ApplicationEventPublisherAware, org.springframework.context.ApplicationContextAware
MessageListenerContainer
.Modifier and Type | Field and Description |
---|---|
protected ConsumerFactory<K,V> |
consumerFactory |
static int |
DEFAULT_PHASE
The default
SmartLifecycle phase for listener
containers 2147483547. |
protected java.lang.Object |
lifecycleMonitor |
protected org.springframework.core.log.LogAccessor |
logger |
Modifier | Constructor and Description |
---|---|
protected |
AbstractMessageListenerContainer(ConsumerFactory<? super K,? super V> consumerFactory,
ContainerProperties containerProperties)
Construct an instance with the provided factory and properties.
|
Modifier and Type | Method and Description |
---|---|
void |
checkGroupId() |
protected void |
checkTopics() |
protected org.apache.kafka.clients.consumer.ConsumerRebalanceListener |
createSimpleLoggingConsumerRebalanceListener()
Return default implementation of
ConsumerRebalanceListener instance. |
protected abstract void |
doStart() |
protected abstract void |
doStop(java.lang.Runnable callback) |
AfterRollbackProcessor<? super K,? super V> |
getAfterRollbackProcessor()
Return the currently configured
AfterRollbackProcessor . |
protected org.springframework.context.ApplicationContext |
getApplicationContext() |
org.springframework.context.ApplicationEventPublisher |
getApplicationEventPublisher() |
java.lang.String |
getBeanName() |
ContainerProperties |
getContainerProperties()
Return the container properties for this container.
|
GenericErrorHandler<?> |
getGenericErrorHandler()
Get the configured error handler.
|
java.lang.String |
getGroupId()
Return the
group.id property for this container whether specifically set on the
container or via a consumer property on the consumer factory. |
java.lang.String |
getListenerId()
The 'id' attribute of a
@KafkaListener or the bean name for spring-managed
containers. |
int |
getPhase() |
protected RecordInterceptor<K,V> |
getRecordInterceptor() |
boolean |
isAutoStartup() |
protected boolean |
isInterceptBeforeTx() |
protected boolean |
isPaused() |
boolean |
isPauseRequested()
Return true if
MessageListenerContainer.pause() has been called; the container might not have actually
paused yet. |
boolean |
isRunning() |
protected AbstractMessageListenerContainer<?,?> |
parentOrThis()
Return this or a parent container if this has a parent.
|
void |
pause()
Pause this container before the next poll().
|
protected void |
publishContainerStoppedEvent() |
void |
resume()
Resume this container, if paused, after the next poll().
|
void |
setAfterRollbackProcessor(AfterRollbackProcessor<? super K,? super V> afterRollbackProcessor)
Set a processor to perform seeks on unprocessed records after a rollback.
|
void |
setApplicationContext(org.springframework.context.ApplicationContext applicationContext) |
void |
setApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher applicationEventPublisher) |
void |
setAutoStartup(boolean autoStartup)
Set the autoStartup.
|
void |
setBatchErrorHandler(BatchErrorHandler errorHandler)
Set the batch error handler to call when the listener throws an exception.
|
void |
setBeanName(java.lang.String name) |
void |
setErrorHandler(ErrorHandler errorHandler)
Set the error handler to call when the listener throws an exception.
|
void |
setGenericErrorHandler(GenericErrorHandler<?> errorHandler)
Set the error handler to call when the listener throws an exception.
|
void |
setInterceptBeforeTx(boolean interceptBeforeTx)
When true, invoke the interceptor before the transaction starts.
|
void |
setPhase(int phase) |
void |
setRecordInterceptor(RecordInterceptor<K,V> recordInterceptor)
Set an interceptor to be called before calling the listener.
|
protected void |
setRunning(boolean running) |
void |
setTopicCheckTimeout(int topicCheckTimeout)
How long to wait for
Admin.describeTopics(Collection) result
futures to complete. |
void |
setupMessageListener(java.lang.Object messageListener)
Setup the message listener to use.
|
void |
start() |
void |
stop() |
void |
stop(boolean wait)
Stop the container.
|
void |
stop(java.lang.Runnable callback) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getAssignedPartitions, getAssignmentsByClientId, isContainerPaused, metrics
public static final int DEFAULT_PHASE
SmartLifecycle
phase for listener
containers 2147483547.protected final org.springframework.core.log.LogAccessor logger
protected final ConsumerFactory<K,V> consumerFactory
protected final java.lang.Object lifecycleMonitor
protected AbstractMessageListenerContainer(ConsumerFactory<? super K,? super V> consumerFactory, ContainerProperties containerProperties)
consumerFactory
- the factory.containerProperties
- the properties.public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext) throws org.springframework.beans.BeansException
setApplicationContext
in interface org.springframework.context.ApplicationContextAware
org.springframework.beans.BeansException
protected org.springframework.context.ApplicationContext getApplicationContext()
public void setBeanName(java.lang.String name)
setBeanName
in interface org.springframework.beans.factory.BeanNameAware
public java.lang.String getBeanName()
public void setApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher applicationEventPublisher)
setApplicationEventPublisher
in interface org.springframework.context.ApplicationEventPublisherAware
public org.springframework.context.ApplicationEventPublisher getApplicationEventPublisher()
public void setErrorHandler(ErrorHandler errorHandler)
errorHandler
- the error handler.public void setGenericErrorHandler(GenericErrorHandler<?> errorHandler)
errorHandler
- the error handler.public void setBatchErrorHandler(BatchErrorHandler errorHandler)
errorHandler
- the error handler.public GenericErrorHandler<?> getGenericErrorHandler()
public boolean isAutoStartup()
isAutoStartup
in interface org.springframework.context.SmartLifecycle
public void setAutoStartup(boolean autoStartup)
MessageListenerContainer
setAutoStartup
in interface MessageListenerContainer
autoStartup
- the autoStartup to set.SmartLifecycle
protected void setRunning(boolean running)
public boolean isRunning()
isRunning
in interface org.springframework.context.Lifecycle
protected boolean isPaused()
public boolean isPauseRequested()
MessageListenerContainer
MessageListenerContainer.pause()
has been called; the container might not have actually
paused yet.isPauseRequested
in interface MessageListenerContainer
public void setPhase(int phase)
public int getPhase()
getPhase
in interface org.springframework.context.Phased
getPhase
in interface org.springframework.context.SmartLifecycle
public AfterRollbackProcessor<? super K,? super V> getAfterRollbackProcessor()
AfterRollbackProcessor
.public void setAfterRollbackProcessor(AfterRollbackProcessor<? super K,? super V> afterRollbackProcessor)
afterRollbackProcessor
- the processor.public ContainerProperties getContainerProperties()
MessageListenerContainer
getContainerProperties
in interface MessageListenerContainer
public java.lang.String getGroupId()
MessageListenerContainer
group.id
property for this container whether specifically set on the
container or via a consumer property on the consumer factory.getGroupId
in interface MessageListenerContainer
@Nullable public java.lang.String getListenerId()
MessageListenerContainer
@KafkaListener
or the bean name for spring-managed
containers.getListenerId
in interface MessageListenerContainer
public void setTopicCheckTimeout(int topicCheckTimeout)
Admin.describeTopics(Collection)
result
futures to complete.topicCheckTimeout
- the timeout in seconds; default 30.protected RecordInterceptor<K,V> getRecordInterceptor()
public void setRecordInterceptor(RecordInterceptor<K,V> recordInterceptor)
recordInterceptor
- the interceptor.setInterceptBeforeTx(boolean)
protected boolean isInterceptBeforeTx()
public void setInterceptBeforeTx(boolean interceptBeforeTx)
interceptBeforeTx
- true to intercept before the transaction.setRecordInterceptor(RecordInterceptor)
public void setupMessageListener(java.lang.Object messageListener)
MessageListenerContainer
IllegalArgumentException
if that message listener type is not supported.setupMessageListener
in interface MessageListenerContainer
messageListener
- the object
to wrapped to the MessageListener
.public final void start()
start
in interface org.springframework.context.Lifecycle
protected void checkTopics()
public void checkGroupId()
protected abstract void doStart()
public final void stop()
stop
in interface org.springframework.context.Lifecycle
public final void stop(boolean wait)
wait
- wait for the listener to terminate.public void pause()
MessageListenerContainer
pause
in interface MessageListenerContainer
public void resume()
MessageListenerContainer
resume
in interface MessageListenerContainer
public void stop(java.lang.Runnable callback)
stop
in interface org.springframework.context.SmartLifecycle
protected abstract void doStop(java.lang.Runnable callback)
protected final org.apache.kafka.clients.consumer.ConsumerRebalanceListener createSimpleLoggingConsumerRebalanceListener()
ConsumerRebalanceListener
instance.ConsumerRebalanceListener
currently assigned to this container.protected void publishContainerStoppedEvent()
protected AbstractMessageListenerContainer<?,?> parentOrThis()