Class KafkaShareMessageDrivenChannelAdapter<K,V>

java.lang.Object
org.springframework.integration.context.IntegrationObjectSupport
org.springframework.integration.endpoint.AbstractEndpoint
org.springframework.integration.endpoint.MessageProducerSupport
org.springframework.integration.kafka.inbound.KafkaShareMessageDrivenChannelAdapter<K,V>
Type Parameters:
K - the key type.
V - the value type.
All Implemented Interfaces:
org.springframework.beans.factory.Aware, org.springframework.beans.factory.BeanFactoryAware, org.springframework.beans.factory.BeanNameAware, org.springframework.beans.factory.DisposableBean, org.springframework.beans.factory.InitializingBean, org.springframework.beans.factory.SmartInitializingSingleton, org.springframework.context.ApplicationContextAware, org.springframework.context.Lifecycle, org.springframework.context.Phased, org.springframework.context.SmartLifecycle, org.springframework.integration.context.ComponentSourceAware, org.springframework.integration.context.ExpressionCapable, org.springframework.integration.context.OrderlyShutdownCapable, org.springframework.integration.core.MessageProducer, org.springframework.integration.IntegrationPattern, KafkaInboundEndpoint, org.springframework.integration.support.context.NamedComponent, org.springframework.integration.support.management.IntegrationInboundManagement, org.springframework.integration.support.management.IntegrationManagement, org.springframework.integration.support.management.ManageableLifecycle, org.springframework.integration.support.management.ManageableSmartLifecycle, org.springframework.integration.support.management.TrackableComponent

public class KafkaShareMessageDrivenChannelAdapter<K,V> extends org.springframework.integration.endpoint.MessageProducerSupport implements KafkaInboundEndpoint, org.springframework.integration.context.OrderlyShutdownCapable
Message-driven channel adapter for Kafka share groups (KIP-932 queues), backed by a AbstractShareKafkaMessageListenerContainer.

Share consumers support only explicit topics (no topic patterns or partition assignment), no batch listeners, and no consumer seeks; this adapter therefore has no ListenerMode and no retry template, and does not implement Pausable. It also has no flag to leave a RecordFilterStrategy-discarded record unacknowledged (unlike KafkaMessageDrivenChannelAdapter.setAckDiscarded(boolean)): a discarded record is always terminally acknowledged, since an unacknowledged record in a share group is simply redelivered to another consumer rather than left uncommitted.

The behavior depends on the container's ContainerProperties.ShareAckMode:

  • ContainerProperties.ShareAckMode.EXPLICIT (the default) and ContainerProperties.ShareAckMode.IMPLICIT - the listener receives no ShareAcknowledgment; the container itself sends AcknowledgeType.ACCEPT after the flow returns normally, and consults the container's ShareConsumerRecordRecoverer (default: reject) when the flow throws.
  • ContainerProperties.ShareAckMode.MANUAL - the ShareAcknowledgment is provided in the KafkaHeaders.ACKNOWLEDGMENT message header (together with the KafkaHeaders.CONSUMER header), and whichever flow receives the message is responsible for calling exactly one of ShareAcknowledgment.acknowledge(), ShareAcknowledgment.release(), or ShareAcknowledgment.reject() on it. The container will not poll again - and will not stop - until every record from the current poll has been terminally acknowledged, so a flow that never acknowledges (or hands the message off without acknowledging) stalls the consumer thread permanently. This adapter acknowledges on the flow's behalf only when no flow ever received the message: it rejects a record that failed conversion, and accepts a record discarded by a RecordFilterStrategy.
Since:
7.2
See Also:
  • AbstractShareKafkaMessageListenerContainer
  • ShareAcknowledgment
  • Nested Class Summary

    Nested classes/interfaces inherited from interface org.springframework.integration.support.management.IntegrationManagement

    org.springframework.integration.support.management.IntegrationManagement.ManagementOverrides

    Nested classes/interfaces inherited from interface KafkaInboundEndpoint

    KafkaInboundEndpoint.RetryContext
  • Field Summary

    Fields inherited from class org.springframework.integration.endpoint.AbstractEndpoint

    lifecycleLock

    Fields inherited from class org.springframework.integration.context.IntegrationObjectSupport

    EXPRESSION_PARSER, logger

    Fields inherited from interface org.springframework.integration.support.management.IntegrationManagement

    METER_PREFIX, RECEIVE_COUNTER_NAME, SEND_TIMER_NAME

    Fields inherited from interface org.springframework.context.SmartLifecycle

    DEFAULT_PHASE
  • Constructor Summary

    Constructors
    Constructor
    Description
    KafkaShareMessageDrivenChannelAdapter(org.springframework.kafka.listener.AbstractShareKafkaMessageListenerContainer<K,V> shareListenerContainer)
    Construct an instance with the provided container.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
     
    int
     
    protected void
     
    protected void
     
     
    protected org.springframework.core.AttributeAccessor
    getErrorMessageAttributes(@Nullable org.springframework.messaging.Message<?> message)
     
    protected void
     
    void
    setBindSourceRecord(boolean bindSourceRecord)
    Set to true to bind the source consumer record in the header named IntegrationMessageHeaderAccessor.SOURCE_DATA.
    void
    setPayloadType(Class<?> payloadType)
    When using a type-aware message converter such as StringJsonMessageConverter, set the payload type the converter should create.
    void
    setRecordFilterStrategy(org.springframework.kafka.listener.adapter.RecordFilterStrategy<K,V> recordFilterStrategy)
    Specify a RecordFilterStrategy to discard records before they are converted and sent.
    void
    setRecordMessageConverter(org.springframework.kafka.support.converter.RecordMessageConverter messageConverter)
    Set the message converter to use.

    Methods inherited from class org.springframework.integration.endpoint.MessageProducerSupport

    afterSingletonsInstantiated, buildErrorMessage, getErrorChannel, getErrorMessageStrategy, getIntegrationPatternType, getMessagingTemplate, getOutputChannel, getOutputChannelName, getRequiredOutputChannel, isObserved, registerObservationRegistry, sendErrorMessageIfNecessary, sendMessage, setErrorChannel, setErrorChannelName, setErrorMessageStrategy, setObservationConvention, setOutputChannel, setOutputChannelName, setSendTimeout, setShouldTrack, subscribeToPublisher

    Methods inherited from class org.springframework.integration.endpoint.AbstractEndpoint

    destroy, doStop, getPhase, getRole, isActive, isAutoStartup, isRunning, setAutoStartup, setPhase, setRole, start, stop, stop

    Methods inherited from class org.springframework.integration.context.IntegrationObjectSupport

    afterPropertiesSet, extractTypeIfPossible, generateId, getApplicationContext, getApplicationContextId, getBeanDescription, getBeanFactory, getBeanName, getChannelResolver, getComponentDescription, getComponentName, getComponentSource, getConversionService, getExpression, getIntegrationProperties, getMessageBuilderFactory, getTaskScheduler, isInitialized, setApplicationContext, setBeanFactory, setBeanName, setChannelResolver, setComponentDescription, setComponentName, setComponentSource, setConversionService, setMessageBuilderFactory, setPrimaryExpression, setTaskScheduler, toString

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

    Methods inherited from interface org.springframework.integration.support.management.IntegrationManagement

    destroy, getManagedName, getManagedType, getOverrides, getThisAs, isLoggingEnabled, registerMetricsCaptor, setLoggingEnabled, setManagedName, setManagedType

    Methods inherited from interface KafkaInboundEndpoint

    doWithRetry

    Methods inherited from interface org.springframework.integration.support.context.NamedComponent

    getBeanName, getComponentName

    Methods inherited from interface org.springframework.context.SmartLifecycle

    isPauseable, pause, restart
  • Constructor Details

    • KafkaShareMessageDrivenChannelAdapter

      public KafkaShareMessageDrivenChannelAdapter(org.springframework.kafka.listener.AbstractShareKafkaMessageListenerContainer<K,V> shareListenerContainer)
      Construct an instance with the provided container.
      Parameters:
      shareListenerContainer - the container.
  • Method Details

    • setRecordMessageConverter

      public void setRecordMessageConverter(org.springframework.kafka.support.converter.RecordMessageConverter messageConverter)
      Set the message converter to use.
      Parameters:
      messageConverter - the converter.
    • setRecordFilterStrategy

      public void setRecordFilterStrategy(org.springframework.kafka.listener.adapter.RecordFilterStrategy<K,V> recordFilterStrategy)
      Specify a RecordFilterStrategy to discard records before they are converted and sent. A discarded record is terminally acknowledged (accepted) by this adapter when the container's ContainerProperties.ShareAckMode is MANUAL.
      Parameters:
      recordFilterStrategy - the RecordFilterStrategy to use.
    • setPayloadType

      public void setPayloadType(Class<?> payloadType)
      When using a type-aware message converter such as StringJsonMessageConverter, set the payload type the converter should create. Defaults to Object.
      Parameters:
      payloadType - the type.
    • setBindSourceRecord

      public void setBindSourceRecord(boolean bindSourceRecord)
      Set to true to bind the source consumer record in the header named IntegrationMessageHeaderAccessor.SOURCE_DATA.
      Parameters:
      bindSourceRecord - true to bind.
    • getComponentType

      public String getComponentType()
      Specified by:
      getComponentType in interface org.springframework.integration.support.context.NamedComponent
      Overrides:
      getComponentType in class org.springframework.integration.endpoint.MessageProducerSupport
    • onInit

      protected void onInit()
      Overrides:
      onInit in class org.springframework.integration.endpoint.MessageProducerSupport
    • doStart

      protected void doStart()
      Overrides:
      doStart in class org.springframework.integration.endpoint.MessageProducerSupport
    • doStop

      protected void doStop()
      Overrides:
      doStop in class org.springframework.integration.endpoint.MessageProducerSupport
    • beforeShutdown

      public int beforeShutdown()
      Specified by:
      beforeShutdown in interface org.springframework.integration.context.OrderlyShutdownCapable
    • afterShutdown

      public int afterShutdown()
      Specified by:
      afterShutdown in interface org.springframework.integration.context.OrderlyShutdownCapable
    • getErrorMessageAttributes

      protected org.springframework.core.AttributeAccessor getErrorMessageAttributes(@Nullable org.springframework.messaging.Message<?> message)
      Overrides:
      getErrorMessageAttributes in class org.springframework.integration.endpoint.MessageProducerSupport