Class MessagingMessageListenerAdapter
java.lang.Object
org.springframework.amqp.rabbit.listener.adapter.AbstractAdaptableMessageListener
org.springframework.amqp.rabbit.listener.adapter.MessagingMessageListenerAdapter
- All Implemented Interfaces:
MessageListener
,ChannelAwareMessageListener
- Direct Known Subclasses:
BatchMessagingMessageListenerAdapter
,StreamMessageListenerAdapter
A
MessageListener
adapter that invokes a configurable HandlerAdapter
.
Wraps the incoming AMQP Message
to Spring's Message
abstraction, copying the
standard headers using a configurable
AmqpHeaderMapper
.
The original Message
and
the Channel
are provided as additional arguments so that these can
be injected as method arguments if necessary.
- Since:
- 1.4
- Author:
- Stephane Nicoll, Gary Russell, Artem Bilan, Kai Stapel
-
Nested Class Summary
Modifier and TypeClassDescriptionprotected final class
Delegates payload extraction toAbstractAdaptableMessageListener.extractMessage(org.springframework.amqp.core.Message message)
to enforce backward compatibility.Nested classes/interfaces inherited from class org.springframework.amqp.rabbit.listener.adapter.AbstractAdaptableMessageListener
AbstractAdaptableMessageListener.ReplyExpressionRoot
-
Field Summary
Fields inherited from class org.springframework.amqp.rabbit.listener.adapter.AbstractAdaptableMessageListener
logger
-
Constructor Summary
ModifierConstructorDescriptionMessagingMessageListenerAdapter
(Object bean, Method method) MessagingMessageListenerAdapter
(Object bean, Method method, boolean returnExceptions, RabbitListenerErrorHandler errorHandler) protected
MessagingMessageListenerAdapter
(Object bean, Method method, boolean returnExceptions, RabbitListenerErrorHandler errorHandler, boolean batch) -
Method Summary
Modifier and TypeMethodDescriptionprotected void
asyncFailure
(Message request, com.rabbitmq.client.Channel channel, Throwable t, Object source) protected Message
buildMessage
(com.rabbitmq.client.Channel channel, Object result, Type genericType) Build a Rabbit message to be sent as response based on the given result object.protected HandlerAdapter
protected final MessagingMessageConverter
protected void
invokeHandlerAndProcessResult
(Message amqpMessage, com.rabbitmq.client.Channel channel, Message<?> message) boolean
Return true if this listener is request/reply and the replies are async.void
Callback for processing a received Rabbit message.void
setHandlerAdapter
(HandlerAdapter handlerAdapter) Set theHandlerAdapter
to use to invoke the method processing an incomingMessage
.void
setHeaderMapper
(AmqpHeaderMapper headerMapper) Set theAmqpHeaderMapper
implementation to use to map the standard AMQP headers.void
setMessageConverter
(MessageConverter messageConverter) Set the converter that will convert incoming Rabbit messages to listener method arguments, and objects returned from listener methods back to Rabbit messages.protected Message<?>
toMessagingMessage
(Message amqpMessage) Methods inherited from class org.springframework.amqp.rabbit.listener.adapter.AbstractAdaptableMessageListener
containerAckMode, convert, doHandleResult, doPublish, extractMessage, getEncoding, getMessageConverter, getReceivedExchange, getReplyContentType, getReplyToAddress, handleListenerException, handleResult, handleResult, isConverterWinsContentType, postProcessChannel, postProcessResponse, sendResponse, setBeanResolver, setBeforeSendReplyPostProcessors, setConverterWinsContentType, setDefaultRequeueRejected, setEncoding, setMandatoryPublish, setRecoveryCallback, setReplyContentType, setReplyPostProcessor, setResponseAddress, setResponseExchange, setResponseRoutingKey, setRetryTemplate
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.springframework.amqp.rabbit.listener.api.ChannelAwareMessageListener
onMessage, onMessageBatch
Methods inherited from interface org.springframework.amqp.core.MessageListener
onMessageBatch
-
Constructor Details
-
MessagingMessageListenerAdapter
public MessagingMessageListenerAdapter() -
MessagingMessageListenerAdapter
-
MessagingMessageListenerAdapter
public MessagingMessageListenerAdapter(Object bean, Method method, boolean returnExceptions, RabbitListenerErrorHandler errorHandler) -
MessagingMessageListenerAdapter
protected MessagingMessageListenerAdapter(Object bean, Method method, boolean returnExceptions, RabbitListenerErrorHandler errorHandler, boolean batch)
-
-
Method Details
-
setHandlerAdapter
Set theHandlerAdapter
to use to invoke the method processing an incomingMessage
.- Parameters:
handlerAdapter
-HandlerAdapter
instance.
-
getHandlerAdapter
-
isAsyncReplies
public boolean isAsyncReplies()Description copied from interface:MessageListener
Return true if this listener is request/reply and the replies are async.- Returns:
- true for async replies.
-
setHeaderMapper
Set theAmqpHeaderMapper
implementation to use to map the standard AMQP headers. By default, aSimpleAmqpHeaderMapper
is used.- Parameters:
headerMapper
- theAmqpHeaderMapper
instance.- See Also:
-
getMessagingMessageConverter
- Returns:
- the
MessagingMessageConverter
for this listener, being able to convertMessage
.
-
setMessageConverter
Description copied from class:AbstractAdaptableMessageListener
Set the converter that will convert incoming Rabbit messages to listener method arguments, and objects returned from listener methods back to Rabbit messages.The default converter is a
SimpleMessageConverter
, which is able to handle "text" content-types.- Overrides:
setMessageConverter
in classAbstractAdaptableMessageListener
- Parameters:
messageConverter
- The message converter.
-
onMessage
Description copied from interface:ChannelAwareMessageListener
Callback for processing a received Rabbit message.Implementors are supposed to process the given Message, typically sending reply messages through the given Session.
- Parameters:
amqpMessage
- the received AMQP message (nevernull
)channel
- the underlying Rabbit Channel (nevernull
unless called by the stream listener container).- Throws:
Exception
- Any.
-
asyncFailure
protected void asyncFailure(Message request, com.rabbitmq.client.Channel channel, Throwable t, Object source) - Overrides:
asyncFailure
in classAbstractAdaptableMessageListener
-
invokeHandlerAndProcessResult
protected void invokeHandlerAndProcessResult(@Nullable Message amqpMessage, com.rabbitmq.client.Channel channel, Message<?> message) throws Exception - Throws:
Exception
-
toMessagingMessage
-
buildMessage
protected Message buildMessage(com.rabbitmq.client.Channel channel, Object result, Type genericType) Build a Rabbit message to be sent as response based on the given result object.- Overrides:
buildMessage
in classAbstractAdaptableMessageListener
- Parameters:
channel
- the Rabbit Channel to operate onresult
- the content of the message, as returned from the listener methodgenericType
- the generic type of the result.- Returns:
- the Rabbit
Message
(nevernull
) - See Also:
-