Class MessagingMessageListenerAdapter<K,​V>

    • Field Detail

      • NULL_MESSAGE

        protected static final org.springframework.messaging.Message<KafkaNull> NULL_MESSAGE
        Message used when no conversion is needed.
      • logger

        protected final org.springframework.core.log.LogAccessor logger
    • Constructor Detail

      • MessagingMessageListenerAdapter

        public MessagingMessageListenerAdapter​(java.lang.Object bean,
                                               java.lang.reflect.Method method)
    • Method Detail

      • setMessageConverter

        public void setMessageConverter​(RecordMessageConverter messageConverter)
        Set the MessageConverter.
        Parameters:
        messageConverter - the converter.
      • getType

        protected java.lang.reflect.Type getType()
        Returns the inferred type for conversion or, if null, the fallbackType.
        Returns:
        the type.
      • setFallbackType

        public void setFallbackType​(java.lang.Class<?> fallbackType)
        Set a fallback type to use when using a type-aware message converter and this adapter cannot determine the inferred type from the method. An example of a type-aware message converter is the StringJsonMessageConverter. Defaults to Object.
        Parameters:
        fallbackType - the type.
      • setHandlerMethod

        public void setHandlerMethod​(HandlerAdapter handlerMethod)
        Set the HandlerAdapter to use to invoke the method processing an incoming ConsumerRecord.
        Parameters:
        handlerMethod - HandlerAdapter instance.
      • isConsumerRecordList

        protected boolean isConsumerRecordList()
      • isConsumerRecords

        public boolean isConsumerRecords()
      • isConversionNeeded

        public boolean isConversionNeeded()
      • setReplyTopic

        public void setReplyTopic​(java.lang.String replyTopicParam)
        Set the topic to which to send any result from the method invocation. May be a SpEL expression !{...} evaluated at runtime.
        Parameters:
        replyTopicParam - the topic or expression.
        Since:
        2.0
      • setReplyTemplate

        public void setReplyTemplate​(KafkaTemplate<?,​?> replyTemplate)
        Set the template to use to send any result from the method invocation.
        Parameters:
        replyTemplate - the template.
        Since:
        2.0
      • setBeanResolver

        public void setBeanResolver​(org.springframework.expression.BeanResolver beanResolver)
        Set a bean resolver for runtime SpEL expressions. Also configures the evaluation context with a standard type converter and map accessor.
        Parameters:
        beanResolver - the resolver.
        Since:
        2.0
      • isMessageList

        protected boolean isMessageList()
      • 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
      • isSplitIterables

        protected boolean isSplitIterables()
        When true, Iterable return results will be split into discrete records.
        Returns:
        true to split.
        Since:
        2.3.5
      • 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
      • registerSeekCallback

        public void registerSeekCallback​(ConsumerSeekAware.ConsumerSeekCallback callback)
        Description copied from interface: ConsumerSeekAware
        Register the callback to use when seeking at some arbitrary time. When used with a ConcurrentMessageListenerContainer or the same listener instance in multiple containers listeners should store the callback in a ThreadLocal.
        Specified by:
        registerSeekCallback in interface ConsumerSeekAware
        Parameters:
        callback - the callback.
      • onPartitionsAssigned

        public void onPartitionsAssigned​(java.util.Map<org.apache.kafka.common.TopicPartition,​java.lang.Long> assignments,
                                         ConsumerSeekAware.ConsumerSeekCallback callback)
        Description copied from interface: ConsumerSeekAware
        When using group management, called when partition assignments change.
        Specified by:
        onPartitionsAssigned in interface ConsumerSeekAware
        Parameters:
        assignments - the new assignments and their current offsets.
        callback - the callback to perform an initial seek after assignment.
      • onIdleContainer

        public void onIdleContainer​(java.util.Map<org.apache.kafka.common.TopicPartition,​java.lang.Long> assignments,
                                    ConsumerSeekAware.ConsumerSeekCallback callback)
        Description copied from interface: ConsumerSeekAware
        If the container is configured to emit idle container events, this method is called when the container idle event is emitted - allowing a seek operation.
        Specified by:
        onIdleContainer in interface ConsumerSeekAware
        Parameters:
        assignments - the new assignments and their current offsets.
        callback - the callback to perform a seek.
      • toMessagingMessage

        protected org.springframework.messaging.Message<?> toMessagingMessage​(org.apache.kafka.clients.consumer.ConsumerRecord<K,​V> record,
                                                                              Acknowledgment acknowledgment,
                                                                              org.apache.kafka.clients.consumer.Consumer<?,​?> consumer)
      • invokeHandler

        protected final java.lang.Object invokeHandler​(java.lang.Object data,
                                                       Acknowledgment acknowledgment,
                                                       org.springframework.messaging.Message<?> message,
                                                       org.apache.kafka.clients.consumer.Consumer<?,​?> consumer)
        Invoke the handler, wrapping any exception to a ListenerExecutionFailedException with a dedicated error message.
        Parameters:
        data - the data to process during invocation.
        acknowledgment - the acknowledgment to use if any.
        message - the message to process.
        consumer - the consumer.
        Returns:
        the result of invocation.
      • handleResult

        protected void handleResult​(java.lang.Object resultArg,
                                    java.lang.Object request,
                                    java.lang.Object source)
        Handle the given result object returned from the listener method, sending a response message to the SendTo topic.
        Parameters:
        resultArg - the result object to handle (never null)
        request - the original request message
        source - the source data for the method invocation - e.g. o.s.messaging.Message<?>; may be null
      • sendResponse

        protected void sendResponse​(java.lang.Object result,
                                    java.lang.String topic,
                                    @Nullable
                                    java.lang.Object source,
                                    boolean returnTypeMessage)
        Send the result to the topic.
        Parameters:
        result - the result.
        topic - the topic.
        source - the source (input).
        returnTypeMessage - true if we are returning message(s).
        Since:
        2.1.3
      • createMessagingErrorMessage

        protected final java.lang.String createMessagingErrorMessage​(java.lang.String description,
                                                                     java.lang.Object payload)
      • determineInferredType

        protected java.lang.reflect.Type determineInferredType​(java.lang.reflect.Method method)
        Subclasses can override this method to use a different mechanism to determine the target type of the payload conversion.
        Parameters:
        method - the method.
        Returns:
        the type.