Class KafkaMessageDrivenChannelAdapter<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.KafkaMessageDrivenChannelAdapter<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.ExpressionCapable, org.springframework.integration.context.OrderlyShutdownCapable, org.springframework.integration.core.MessageProducer, org.springframework.integration.core.Pausable, org.springframework.integration.IntegrationPattern, org.springframework.integration.support.context.NamedComponent, org.springframework.integration.support.management.ManageableLifecycle, org.springframework.integration.support.management.ManageableSmartLifecycle, org.springframework.integration.support.management.TrackableComponent

public class KafkaMessageDrivenChannelAdapter<K,​V>
extends org.springframework.integration.endpoint.MessageProducerSupport
implements org.springframework.integration.context.OrderlyShutdownCapable, org.springframework.integration.core.Pausable
Message-driven channel adapter.
Since:
5.4
  • Nested Class Summary

    Nested Classes 
    Modifier and Type Class Description
    static class  KafkaMessageDrivenChannelAdapter.ListenerMode
    The listener mode for the container, record or batch.
  • Field Summary

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

    lifecycleCondition, lifecycleLock

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

    EXPRESSION_PARSER, logger

    Fields inherited from interface org.springframework.context.SmartLifecycle

    DEFAULT_PHASE
  • Constructor Summary

    Constructors 
    Constructor Description
    KafkaMessageDrivenChannelAdapter​(org.springframework.kafka.listener.AbstractMessageListenerContainer<K,​V> messageListenerContainer)
    KafkaMessageDrivenChannelAdapter​(org.springframework.kafka.listener.AbstractMessageListenerContainer<K,​V> messageListenerContainer, KafkaMessageDrivenChannelAdapter.ListenerMode mode)
    Construct an instance with the provided mode.
  • Method Summary

    Modifier and Type Method Description
    int afterShutdown()  
    int beforeShutdown()  
    protected void doStart()  
    protected void doStop()  
    java.lang.String getComponentType()  
    protected org.springframework.core.AttributeAccessor getErrorMessageAttributes​(org.springframework.messaging.Message<?> message)  
    boolean isPaused()  
    protected void onInit()  
    void pause()  
    void resume()  
    void setAckDiscarded​(boolean ackDiscarded)
    A boolean flag to indicate if FilteringMessageListenerAdapter should acknowledge discarded records or not.
    void setBatchMessageConverter​(org.springframework.kafka.support.converter.BatchMessageConverter messageConverter)
    Set the message converter to use with a batch-based consumer.
    void setBindSourceRecord​(boolean bindSourceRecord)
    Set to true to bind the source consumer record in the header named IntegrationMessageHeaderAccessor.SOURCE_DATA.
    void setFilterInRetry​(boolean filterInRetry)
    The boolean flag to specify the order how RetryingMessageListenerAdapter and FilteringMessageListenerAdapter are wrapped to each other, if both of them are present.
    void setMessageConverter​(org.springframework.kafka.support.converter.MessageConverter messageConverter)
    Set the message converter; must be a RecordMessageConverter or BatchMessageConverter depending on mode.
    void setOnPartitionsAssignedSeekCallback​(java.util.function.BiConsumer<java.util.Map<org.apache.kafka.common.TopicPartition,​java.lang.Long>,​org.springframework.kafka.listener.ConsumerSeekAware.ConsumerSeekCallback> onPartitionsAssignedCallback)
    Specify a BiConsumer for seeks management during ConsumerSeekAware.onPartitionsAssigned(Map, ConsumerSeekAware.ConsumerSeekCallback) call from the KafkaMessageListenerContainer.
    void setPayloadType​(java.lang.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 wrap KafkaMessageDrivenChannelAdapter.IntegrationRecordMessageListener into FilteringMessageListenerAdapter.
    void setRecordMessageConverter​(org.springframework.kafka.support.converter.RecordMessageConverter messageConverter)
    Set the message converter to use with a record-based consumer.
    void setRecoveryCallback​(org.springframework.retry.RecoveryCallback<?> recoveryCallback)
    A RecoveryCallback instance for retry operation; if null, the exception will be thrown to the container after retries are exhausted (unless an error channel is configured).
    void setRetryTemplate​(org.springframework.retry.support.RetryTemplate retryTemplate)
    Specify a RetryTemplate instance to wrap KafkaMessageDrivenChannelAdapter.IntegrationRecordMessageListener into RetryingMessageListenerAdapter.

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

    afterSingletonsInstantiated, buildErrorMessage, getErrorChannel, getIntegrationPatternType, getMessagingTemplate, getOutputChannel, sendErrorMessageIfNecessary, sendMessage, setErrorChannel, setErrorChannelName, setErrorMessageStrategy, 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, getComponentName, getConversionService, getExpression, getIntegrationProperties, getIntegrationProperty, getMessageBuilderFactory, getTaskScheduler, isInitialized, setApplicationContext, setBeanFactory, setBeanName, setChannelResolver, setComponentName, setConversionService, setMessageBuilderFactory, setPrimaryExpression, setTaskScheduler, toString

    Methods inherited from class java.lang.Object

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

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

    isRunning, start, stop

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

    getBeanName, getComponentName
  • Constructor Details

  • Method Details

    • setMessageConverter

      public void setMessageConverter​(org.springframework.kafka.support.converter.MessageConverter messageConverter)
      Set the message converter; must be a RecordMessageConverter or BatchMessageConverter depending on mode.
      Parameters:
      messageConverter - the converter.
    • setRecordMessageConverter

      public void setRecordMessageConverter​(org.springframework.kafka.support.converter.RecordMessageConverter messageConverter)
      Set the message converter to use with a record-based consumer.
      Parameters:
      messageConverter - the converter.
      Since:
      2.1
    • setBatchMessageConverter

      public void setBatchMessageConverter​(org.springframework.kafka.support.converter.BatchMessageConverter messageConverter)
      Set the message converter to use with a batch-based consumer.
      Parameters:
      messageConverter - the converter.
      Since:
      2.1
    • setRecordFilterStrategy

      public void setRecordFilterStrategy​(org.springframework.kafka.listener.adapter.RecordFilterStrategy<K,​V> recordFilterStrategy)
      Specify a RecordFilterStrategy to wrap KafkaMessageDrivenChannelAdapter.IntegrationRecordMessageListener into FilteringMessageListenerAdapter.
      Parameters:
      recordFilterStrategy - the RecordFilterStrategy to use.
      Since:
      2.0.1
    • setAckDiscarded

      public void setAckDiscarded​(boolean ackDiscarded)
      A boolean flag to indicate if FilteringMessageListenerAdapter should acknowledge discarded records or not. Does not make sense if setRecordFilterStrategy(RecordFilterStrategy) isn't specified.
      Parameters:
      ackDiscarded - true to ack (commit offset for) discarded messages.
      Since:
      2.0.1
    • setRetryTemplate

      public void setRetryTemplate​(org.springframework.retry.support.RetryTemplate retryTemplate)
      Specify a RetryTemplate instance to wrap KafkaMessageDrivenChannelAdapter.IntegrationRecordMessageListener into RetryingMessageListenerAdapter.
      Parameters:
      retryTemplate - the RetryTemplate to use.
      Since:
      2.0.1
    • setRecoveryCallback

      public void setRecoveryCallback​(org.springframework.retry.RecoveryCallback<?> recoveryCallback)
      A RecoveryCallback instance for retry operation; if null, the exception will be thrown to the container after retries are exhausted (unless an error channel is configured). Does not make sense if setRetryTemplate(RetryTemplate) isn't specified.
      Parameters:
      recoveryCallback - the recovery callback.
      Since:
      2.0.1
    • setFilterInRetry

      public void setFilterInRetry​(boolean filterInRetry)
      The boolean flag to specify the order how RetryingMessageListenerAdapter and FilteringMessageListenerAdapter are wrapped to each other, if both of them are present. Does not make sense if only one of RetryTemplate or RecordFilterStrategy is present, or any.
      Parameters:
      filterInRetry - the order for RetryingMessageListenerAdapter and FilteringMessageListenerAdapter wrapping. Defaults to false.
      Since:
      2.0.1
    • setPayloadType

      public void setPayloadType​(java.lang.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.
      Since:
      2.1.1
    • setOnPartitionsAssignedSeekCallback

      public void setOnPartitionsAssignedSeekCallback​(java.util.function.BiConsumer<java.util.Map<org.apache.kafka.common.TopicPartition,​java.lang.Long>,​org.springframework.kafka.listener.ConsumerSeekAware.ConsumerSeekCallback> onPartitionsAssignedCallback)
      Specify a BiConsumer for seeks management during ConsumerSeekAware.onPartitionsAssigned(Map, ConsumerSeekAware.ConsumerSeekCallback) call from the KafkaMessageListenerContainer. This is called from the internal MessagingMessageListenerAdapter implementation.
      Parameters:
      onPartitionsAssignedCallback - the BiConsumer to use
      Since:
      3.0.4
      See Also:
      ConsumerSeekAware.onPartitionsAssigned(java.util.Map<org.apache.kafka.common.TopicPartition, java.lang.Long>, org.springframework.kafka.listener.ConsumerSeekAware.ConsumerSeekCallback)
    • setBindSourceRecord

      public void setBindSourceRecord​(boolean bindSourceRecord)
      Set to true to bind the source consumer record in the header named IntegrationMessageHeaderAccessor.SOURCE_DATA. Does not apply to batch listeners.
      Parameters:
      bindSourceRecord - true to bind.
      Since:
      3.1.4
    • getComponentType

      public java.lang.String getComponentType()
      Specified by:
      getComponentType in interface org.springframework.integration.support.context.NamedComponent
      Overrides:
      getComponentType in class org.springframework.integration.context.IntegrationObjectSupport
    • 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
    • pause

      public void pause()
      Specified by:
      pause in interface org.springframework.integration.core.Pausable
    • resume

      public void resume()
      Specified by:
      resume in interface org.springframework.integration.core.Pausable
    • isPaused

      public boolean isPaused()
      Specified by:
      isPaused in interface org.springframework.integration.core.Pausable
    • 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​(org.springframework.messaging.Message<?> message)
      Overrides:
      getErrorMessageAttributes in class org.springframework.integration.endpoint.MessageProducerSupport