Interface MessageListenerContainer
- All Superinterfaces:
org.springframework.beans.factory.DisposableBean,org.springframework.context.Lifecycle,org.springframework.context.Phased,org.springframework.context.SmartLifecycle
- All Known Subinterfaces:
GenericMessageListenerContainer<K,V>
- All Known Implementing Classes:
AbstractMessageListenerContainer,ConcurrentMessageListenerContainer,KafkaMessageListenerContainer
public interface MessageListenerContainer
extends org.springframework.context.SmartLifecycle, org.springframework.beans.factory.DisposableBean
Internal abstraction used by the framework representing a message
listener container. Not meant to be implemented externally.
-
Field Summary
Fields inherited from interface org.springframework.context.SmartLifecycle
DEFAULT_PHASE -
Method Summary
Modifier and TypeMethodDescriptiondefault voiddestroy()default Collection<org.apache.kafka.common.TopicPartition>Return the assigned topics/partitions for this container.default Map<String,Collection<org.apache.kafka.common.TopicPartition>> Return the assigned topics/partitions for this container, by client.id.default MessageListenerContainergetContainerFor(String topic, int partition) If this container has child containers, return the child container that is assigned the topic/partition.default ContainerPropertiesReturn the container properties for this container.default StringReturn thegroup.idproperty for this container whether specifically set on the container or via a consumer property on the consumer factory.default StringThe 'id' attribute of a@KafkaListeneror the bean name for spring-managed containers.default byte[]Get arbitrary static information that will be added to theKafkaHeaders.LISTENER_INFOheader of all records.default StringThe 'id' attribute of the main@KafkaListenercontainer, if this container is for a retry topic; null otherwise.default booleanIf this container has child containers, return true if at least one child is running.default booleanReturn true ifpause()has been called; and all consumers in this container have actually paused.default booleanReturn true if the container is running, has never been started, or has been stopped.default booleanisPartitionPaused(org.apache.kafka.common.TopicPartition topicPartition) Whether or not this topic's partition is currently paused.default booleanisPartitionPauseRequested(org.apache.kafka.common.TopicPartition topicPartition) Whether or not this topic's partition pause has been requested.default booleanReturn true ifpause()has been called; the container might not have actually paused yet.metrics()Return metrics kept by this container's consumer(s), grouped byclient-id.default voidpause()Pause this container before the next poll().default voidpausePartition(org.apache.kafka.common.TopicPartition topicPartition) Pause this partition before the next poll().default voidresume()Resume this container, if paused, after the next poll().default voidresumePartition(org.apache.kafka.common.TopicPartition topicPartition) Resume this partition, if paused, after the next poll().default voidsetAutoStartup(boolean autoStartup) Set the autoStartup.voidsetupMessageListener(Object messageListener) Setup the message listener to use.default voidstopAbnormally(Runnable callback) Stop the container after some exception so thatisInExpectedState()will return false.Methods inherited from interface org.springframework.context.Lifecycle
isRunning, start, stopMethods inherited from interface org.springframework.context.SmartLifecycle
getPhase, isAutoStartup, stop
-
Method Details
-
setupMessageListener
Setup the message listener to use. Throws anIllegalArgumentExceptionif that message listener type is not supported.- Parameters:
messageListener- theobjectto wrapped to theMessageListener.
-
metrics
Map<String,Map<org.apache.kafka.common.MetricName, metrics()? extends org.apache.kafka.common.Metric>> Return metrics kept by this container's consumer(s), grouped byclient-id.- Returns:
- the consumer(s) metrics grouped by
client-id - Since:
- 1.3
- See Also:
-
Consumer.metrics()
-
getContainerProperties
Return the container properties for this container.- Returns:
- the properties.
- Since:
- 2.1.3
-
getAssignedPartitions
Return the assigned topics/partitions for this container.- Returns:
- the topics/partitions.
- Since:
- 2.1.3
-
getAssignmentsByClientId
@Nullable default Map<String,Collection<org.apache.kafka.common.TopicPartition>> getAssignmentsByClientId()Return the assigned topics/partitions for this container, by client.id.- Returns:
- the topics/partitions.
- Since:
- 2.5
-
pause
default void pause()Pause this container before the next poll(). This is a thread-safe operation, the actual pause is processed by the consumer thread.- Since:
- 2.1.3
- See Also:
-
KafkaConsumer.pause(Collection)
-
resume
default void resume()Resume this container, if paused, after the next poll(). This is a thread-safe operation, the actual resume is processed by the consumer thread.- Since:
- 2.1.3
- See Also:
-
KafkaConsumer.resume(Collection)
-
pausePartition
default void pausePartition(org.apache.kafka.common.TopicPartition topicPartition) Pause this partition before the next poll(). This is a thread-safe operation, the actual pause is processed by the consumer thread.- Parameters:
topicPartition- the topicPartition to pause.- Since:
- 2.7
-
resumePartition
default void resumePartition(org.apache.kafka.common.TopicPartition topicPartition) Resume this partition, if paused, after the next poll(). This is a thread-safe operation, the actual pause is processed by the consumer thread.- Parameters:
topicPartition- the topicPartition to resume.- Since:
- 2.7
-
isPartitionPauseRequested
default boolean isPartitionPauseRequested(org.apache.kafka.common.TopicPartition topicPartition) Whether or not this topic's partition pause has been requested.- Parameters:
topicPartition- the topic partition to check- Returns:
- true if pause for this TopicPartition has been requested
- Since:
- 2.7
-
isPartitionPaused
default boolean isPartitionPaused(org.apache.kafka.common.TopicPartition topicPartition) Whether or not this topic's partition is currently paused.- Parameters:
topicPartition- the topic partition to check- Returns:
- true if this partition has been paused.
- Since:
- 2.7
-
isPauseRequested
default boolean isPauseRequested()Return true ifpause()has been called; the container might not have actually paused yet.- Returns:
- true if pause has been requested.
- Since:
- 2.1.5
-
isContainerPaused
default boolean isContainerPaused()Return true ifpause()has been called; and all consumers in this container have actually paused.- Returns:
- true if the container is paused.
- Since:
- 2.1.5
-
setAutoStartup
default void setAutoStartup(boolean autoStartup) Set the autoStartup.- Parameters:
autoStartup- the autoStartup to set.- Since:
- 2.2
- See Also:
-
SmartLifecycle
-
getGroupId
Return thegroup.idproperty for this container whether specifically set on the container or via a consumer property on the consumer factory.- Returns:
- the group id.
- Since:
- 2.2.5
-
getListenerId
The 'id' attribute of a@KafkaListeneror the bean name for spring-managed containers.- Returns:
- the id or bean name.
- Since:
- 2.2.5
-
getMainListenerId
The 'id' attribute of the main@KafkaListenercontainer, if this container is for a retry topic; null otherwise.- Returns:
- the id.
- Since:
- 3.0
-
getListenerInfo
@Nullable default byte[] getListenerInfo()Get arbitrary static information that will be added to theKafkaHeaders.LISTENER_INFOheader of all records.- Returns:
- the info.
- Since:
- 2.8.6
-
isChildRunning
default boolean isChildRunning()If this container has child containers, return true if at least one child is running. If there are not child containers, returnsLifecycle.isRunning().- Returns:
- true if a child is running.
- Since:
- 2.7.3
-
isInExpectedState
default boolean isInExpectedState()Return true if the container is running, has never been started, or has been stopped.- Returns:
- true if the state is as expected.
- Since:
- 2.8
- See Also:
-
stopAbnormally
Stop the container after some exception so thatisInExpectedState()will return false.- Parameters:
callback- the callback.- Since:
- 2.8
- See Also:
-
getContainerFor
If this container has child containers, return the child container that is assigned the topic/partition. Return this when there are no child containers.- Parameters:
topic- the topic.partition- the partition.- Returns:
- the container.
-
destroy
default void destroy()- Specified by:
destroyin interfaceorg.springframework.beans.factory.DisposableBean
-