Class ShareKafkaMessageListenerContainer<K,V>

java.lang.Object
org.springframework.kafka.listener.AbstractShareKafkaMessageListenerContainer<K,V>
org.springframework.kafka.listener.ShareKafkaMessageListenerContainer<K,V>
Type Parameters:
K - the key type
V - the value type
All Implemented Interfaces:
Aware, BeanNameAware, DisposableBean, ApplicationContextAware, ApplicationEventPublisherAware, Lifecycle, Phased, SmartLifecycle, GenericMessageListenerContainer<K,V>, MessageListenerContainer

public class ShareKafkaMessageListenerContainer<K,V> extends AbstractShareKafkaMessageListenerContainer<K,V>
ShareKafkaMessageListenerContainer is a message listener container for Kafka's share consumer model.

This container manages a single-threaded consumer loop using a ShareConsumerFactory. It is designed for use cases where Kafka's cooperative sharing protocol is desired, and provides a simple polling loop with per-record dispatch and acknowledgement.

Since:
4.0
Author:
Soby Chacko
  • Constructor Details

    • ShareKafkaMessageListenerContainer

      public ShareKafkaMessageListenerContainer(ShareConsumerFactory<? super K, ? super V> shareConsumerFactory, ContainerProperties containerProperties)
      Construct an instance with the supplied configuration properties.
      Parameters:
      shareConsumerFactory - the share consumer factory
      containerProperties - the container properties
  • Method Details

    • getClientId

      public @Nullable String getClientId()
      Get the client.id for the consumer.
      Returns:
      the client id, or null if not set
    • setClientId

      public void setClientId(String clientId)
      Set the client.id to use for the consumer.
      Parameters:
      clientId - the client id to set
    • isInExpectedState

      public boolean isInExpectedState()
      Description copied from interface: MessageListenerContainer
      Return true if the container is running, has never been started, or has been stopped.
      Returns:
      true if the state is as expected.
      See Also:
    • metrics

      public Map<String, Map<org.apache.kafka.common.MetricName, ? extends org.apache.kafka.common.Metric>> metrics()
      Description copied from interface: MessageListenerContainer
      Return metrics kept by this container's consumer(s), grouped by client-id.
      Returns:
      the consumer(s) metrics grouped by client-id
      See Also:
      • Consumer.metrics()
    • doStart

      protected void doStart()
      Specified by:
      doStart in class AbstractShareKafkaMessageListenerContainer<K,V>
    • doStop

      protected void doStop()
      Specified by:
      doStop in class AbstractShareKafkaMessageListenerContainer<K,V>