Class KafkaInboundGateway<K,V,R>

java.lang.Object
org.springframework.integration.context.IntegrationObjectSupport
org.springframework.integration.endpoint.AbstractEndpoint
org.springframework.integration.gateway.MessagingGatewaySupport
org.springframework.integration.kafka.inbound.KafkaInboundGateway<K,V,R>
Type Parameters:
K - the key type.
V - the request value type.
R - the reply 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.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.Pausable, 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 KafkaInboundGateway<K,V,R> extends org.springframework.integration.gateway.MessagingGatewaySupport implements KafkaInboundEndpoint, org.springframework.integration.core.Pausable, org.springframework.integration.context.OrderlyShutdownCapable
Inbound gateway.
Since:
5.4
  • Nested Class Summary

    Nested classes/interfaces inherited from class org.springframework.integration.gateway.MessagingGatewaySupport

    org.springframework.integration.gateway.MessagingGatewaySupport.ConvertingMessagingTemplate

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

    org.springframework.integration.support.management.IntegrationManagement.ManagementOverrides
  • Field Summary

    Fields inherited from class org.springframework.integration.gateway.MessagingGatewaySupport

    messagingTemplate

    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.integration.support.management.IntegrationManagement

    METER_PREFIX, RECEIVE_COUNTER_NAME, SEND_TIMER_NAME

    Fields inherited from interface org.springframework.integration.kafka.inbound.KafkaInboundEndpoint

    ATTRIBUTES_HOLDER, CONTEXT_ACKNOWLEDGMENT, CONTEXT_CONSUMER, CONTEXT_RECORD

    Fields inherited from interface org.springframework.context.SmartLifecycle

    DEFAULT_PHASE
  • Constructor Summary

    Constructors
    Constructor
    Description
    KafkaInboundGateway(org.springframework.kafka.listener.AbstractMessageListenerContainer<K,V> messageListenerContainer, org.springframework.kafka.core.KafkaTemplate<K,R> kafkaTemplate)
    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(org.springframework.messaging.Message<?> message)
     
    boolean
     
    protected void
     
    void
     
    void
     
    void
    setBindSourceRecord(boolean bindSourceRecord)
    Set to true to bind the source consumer record in the header named IntegrationMessageHeaderAccessor.SOURCE_DATA.
    void
    setMessageConverter(org.springframework.kafka.support.converter.RecordMessageConverter messageConverter)
    Set the message converter; must be a RecordMessageConverter or BatchMessageConverter depending on mode.
    void
    setOnPartitionsAssignedSeekCallback(BiConsumer<Map<org.apache.kafka.common.TopicPartition,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(Class<?> payloadType)
    When using a type-aware message converter such as StringJsonMessageConverter, set the payload type the converter should create.
    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 use for retrying deliveries.

    Methods inherited from class org.springframework.integration.gateway.MessagingGatewaySupport

    buildErrorMessage, buildSendTimer, destroy, getErrorChannel, getErrorMessageStrategy, getIntegrationPatternType, getManagedName, getManagedType, getOverrides, getReplyChannel, getRequestChannel, isLoggingEnabled, isObserved, receive, receive, receiveMessage, receiveMessage, registerMetricsCaptor, registerObservationRegistry, registerReplyMessageCorrelatorIfNecessary, send, sendAndReceive, sendAndReceiveMessage, sendAndReceiveMessageReactive, sendTimer, setErrorChannel, setErrorChannelName, setErrorMessageStrategy, setErrorOnTimeout, setLoggingEnabled, setManagedName, setManagedType, setObservationConvention, setReceiverObservationConvention, setReplyChannel, setReplyChannelName, setReplyMapper, setReplyTimeout, setRequestChannel, setRequestChannelName, setRequestMapper, setRequestTimeout, setShouldTrack

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

    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, 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.IntegrationManagement

    getThisAs

    Methods inherited from interface org.springframework.integration.kafka.inbound.KafkaInboundEndpoint

    doWithRetry

    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

    • KafkaInboundGateway

      public KafkaInboundGateway(org.springframework.kafka.listener.AbstractMessageListenerContainer<K,V> messageListenerContainer, org.springframework.kafka.core.KafkaTemplate<K,R> kafkaTemplate)
      Construct an instance with the provided container.
      Parameters:
      messageListenerContainer - the container.
      kafkaTemplate - the kafka template.
  • Method Details

    • setMessageConverter

      public void setMessageConverter(org.springframework.kafka.support.converter.RecordMessageConverter messageConverter)
      Set the message converter; must be a RecordMessageConverter or BatchMessageConverter depending on mode.
      Parameters:
      messageConverter - the converter.
    • 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.
    • setRetryTemplate

      public void setRetryTemplate(org.springframework.retry.support.RetryTemplate retryTemplate)
      Specify a RetryTemplate instance to use for retrying deliveries.

      IMPORTANT: This form of retry is blocking and could cause a rebalance if the aggregate retry delays across all polled records might exceed the max.poll.interval.ms. Instead, consider adding a DefaultErrorHandler to the listener container, configured with a KafkaErrorSendingMessageRecoverer.

      Parameters:
      retryTemplate - the RetryTemplate to use.
    • 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). Only used if setRetryTemplate(RetryTemplate) is specified. Default is an ErrorMessageSendingRecoverer if an error channel has been provided. Set to null if you wish to throw the exception back to the container after retries are exhausted.
      Parameters:
      recoveryCallback - the recovery callback.
    • setOnPartitionsAssignedSeekCallback

      public void setOnPartitionsAssignedSeekCallback(BiConsumer<Map<org.apache.kafka.common.TopicPartition,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
      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.
      Parameters:
      bindSourceRecord - true to bind.
    • onInit

      protected void onInit()
      Overrides:
      onInit in class org.springframework.integration.gateway.MessagingGatewaySupport
    • doStart

      protected void doStart()
      Overrides:
      doStart in class org.springframework.integration.gateway.MessagingGatewaySupport
    • doStop

      protected void doStop()
      Overrides:
      doStop in class org.springframework.integration.gateway.MessagingGatewaySupport
    • 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
    • getComponentType

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