Class AbstractKafkaListenerEndpoint<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.InitializingBean, KafkaListenerEndpoint
    Direct Known Subclasses:
    MethodKafkaListenerEndpoint

    public abstract class AbstractKafkaListenerEndpoint<K,​V>
    extends java.lang.Object
    implements KafkaListenerEndpoint, org.springframework.beans.factory.BeanFactoryAware, org.springframework.beans.factory.InitializingBean
    Base model for a Kafka listener endpoint.
    Author:
    Stephane Nicoll, Gary Russell, Artem Bilan
    See Also:
    MethodKafkaListenerEndpoint
    • Constructor Detail

      • AbstractKafkaListenerEndpoint

        public AbstractKafkaListenerEndpoint()
    • Method Detail

      • setBeanFactory

        public void setBeanFactory​(org.springframework.beans.factory.BeanFactory beanFactory)
                            throws org.springframework.beans.BeansException
        Specified by:
        setBeanFactory in interface org.springframework.beans.factory.BeanFactoryAware
        Throws:
        org.springframework.beans.BeansException
      • getBeanFactory

        protected org.springframework.beans.factory.BeanFactory getBeanFactory()
      • getResolver

        protected org.springframework.beans.factory.config.BeanExpressionResolver getResolver()
      • getBeanExpressionContext

        protected org.springframework.beans.factory.config.BeanExpressionContext getBeanExpressionContext()
      • getBeanResolver

        protected org.springframework.expression.BeanResolver getBeanResolver()
      • setId

        public void setId​(java.lang.String id)
      • setGroupId

        public void setGroupId​(java.lang.String groupId)
        Set the group id to override the group.id property in the ContainerFactory.
        Parameters:
        groupId - the group id.
        Since:
        1.3
      • getGroupId

        public java.lang.String getGroupId()
        Description copied from interface: KafkaListenerEndpoint
        Return the groupId of this endpoint - if present, overrides the group.id property of the consumer factory.
        Specified by:
        getGroupId in interface KafkaListenerEndpoint
        Returns:
        the group id; may be null.
      • getTopics

        public java.util.Collection<java.lang.String> getTopics()
        Return the topics for this endpoint.
        Specified by:
        getTopics in interface KafkaListenerEndpoint
        Returns:
        the topics for this endpoint.
      • getTopicPattern

        public java.util.regex.Pattern getTopicPattern()
        Return the topicPattern for this endpoint.
        Specified by:
        getTopicPattern in interface KafkaListenerEndpoint
        Returns:
        the topicPattern for this endpoint.
      • getGroup

        public java.lang.String getGroup()
        Description copied from interface: KafkaListenerEndpoint
        Return the group of this endpoint or null if not in a group.
        Specified by:
        getGroup in interface KafkaListenerEndpoint
        Returns:
        the group of this endpoint or null if not in a group.
      • setGroup

        public void setGroup​(java.lang.String group)
        Set the group for the corresponding listener container.
        Parameters:
        group - the group.
      • isBatchListener

        public boolean isBatchListener()
        Return true if this endpoint creates a batch listener.
        Returns:
        true for a batch listener.
        Since:
        1.1
      • setBatchListener

        public void setBatchListener​(boolean batchListener)
        Set to true if this endpoint should create a batch listener.
        Parameters:
        batchListener - true for a batch listener.
        Since:
        1.1
      • setReplyTemplate

        public void setReplyTemplate​(KafkaTemplate<?,​?> replyTemplate)
        Set the KafkaTemplate to use to send replies.
        Parameters:
        replyTemplate - the template.
        Since:
        2.0
      • getReplyTemplate

        protected KafkaTemplate<?,​?> getReplyTemplate()
      • setRecordFilterStrategy

        public void setRecordFilterStrategy​(RecordFilterStrategy<? super K,​? super V> recordFilterStrategy)
        Set a RecordFilterStrategy implementation.
        Parameters:
        recordFilterStrategy - the strategy implementation.
      • isAckDiscarded

        protected boolean isAckDiscarded()
      • getRetryTemplate

        protected org.springframework.retry.support.RetryTemplate getRetryTemplate()
      • setRetryTemplate

        public void setRetryTemplate​(org.springframework.retry.support.RetryTemplate retryTemplate)
        Set a retryTemplate.
        Parameters:
        retryTemplate - the template.
      • getRecoveryCallback

        protected org.springframework.retry.RecoveryCallback<?> getRecoveryCallback()
      • setRecoveryCallback

        public void setRecoveryCallback​(org.springframework.retry.RecoveryCallback<? extends java.lang.Object> recoveryCallback)
        Set a callback to be used with the setRetryTemplate(RetryTemplate).
        Parameters:
        recoveryCallback - the callback.
      • isStatefulRetry

        protected boolean isStatefulRetry()
      • setStatefulRetry

        public void setStatefulRetry​(boolean statefulRetry)
        When using a RetryTemplate, set to true to enable stateful retry. Use in conjunction with a SeekToCurrentErrorHandler when retry can take excessive time; each failure goes back to the broker, to keep the Consumer alive.
        Parameters:
        statefulRetry - true to enable stateful retry.
        Since:
        2.1.3
      • getClientIdPrefix

        public java.lang.String getClientIdPrefix()
        Description copied from interface: KafkaListenerEndpoint
        Return the client id prefix for the container; it will be suffixed by '-n' to provide a unique id when concurrency is used.
        Specified by:
        getClientIdPrefix in interface KafkaListenerEndpoint
        Returns:
        the client id prefix.
      • setClientIdPrefix

        public void setClientIdPrefix​(java.lang.String clientIdPrefix)
        Set the client id prefix; overrides the client id in the consumer configuration properties.
        Parameters:
        clientIdPrefix - the prefix.
        Since:
        2.1.1
      • setConcurrency

        public void setConcurrency​(java.lang.Integer concurrency)
        Set the concurrency for this endpoint's container.
        Parameters:
        concurrency - the concurrency.
        Since:
        2.2
      • setAutoStartup

        public void setAutoStartup​(java.lang.Boolean autoStartup)
        Set the autoStartup for this endpoint's container.
        Parameters:
        autoStartup - the autoStartup.
        Since:
        2.2
      • setReplyHeadersConfigurer

        public void setReplyHeadersConfigurer​(ReplyHeadersConfigurer replyHeadersConfigurer)
        Set a configurer which will be invoked when creating a reply message.
        Parameters:
        replyHeadersConfigurer - the configurer.
        Since:
        2.2
      • setConsumerProperties

        public void setConsumerProperties​(java.util.Properties consumerProperties)
        Set the consumer properties that will be merged with the consumer properties provided by the consumer factory; properties here will supersede any with the same name(s) in the consumer factory. group.id and client.id are ignored.
        Parameters:
        consumerProperties - the properties.
        Since:
        2.1.4
        See Also:
        ConsumerConfig, setGroupId(String), setClientIdPrefix(String)
      • setSplitIterables

        public void setSplitIterables​(boolean splitIterables)
        Set to false to disable splitting Iterable reply values into separate records.
        Parameters:
        splitIterables - false to disable; default true.
        Since:
        2.3.5
      • afterPropertiesSet

        public void afterPropertiesSet()
        Specified by:
        afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
      • setupListenerContainer

        public void setupListenerContainer​(MessageListenerContainer listenerContainer,
                                           MessageConverter messageConverter)
        Description copied from interface: KafkaListenerEndpoint
        Setup the specified message listener container with the model defined by this endpoint.

        This endpoint must provide the requested missing option(s) of the specified container to make it usable. Usually, this is about setting the queues and the messageListener to use but an implementation may override any default setting that was already set.

        Specified by:
        setupListenerContainer in interface KafkaListenerEndpoint
        Parameters:
        listenerContainer - the listener container to configure
        messageConverter - the message converter - can be null
      • getEndpointDescription

        protected java.lang.StringBuilder getEndpointDescription()
        Return a description for this endpoint.
        Returns:
        a description for this endpoint.

        Available to subclasses, for inclusion in their toString() result.

      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object