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,RabbitAmqpMessageListenerAdapter,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
Nested ClassesModifier and TypeClassDescriptionprotected final classDelegates 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
FieldsModifier and TypeFieldDescriptionprotected final @Nullable RabbitListenerErrorHandlerprotected final MessagingMessageListenerAdapter.MessagingMessageConverterAdapterprotected final booleanFields inherited from class org.springframework.amqp.rabbit.listener.adapter.AbstractAdaptableMessageListener
logger -
Constructor Summary
ConstructorsModifierConstructorDescriptionMessagingMessageListenerAdapter(@Nullable Object bean, @Nullable Method method) MessagingMessageListenerAdapter(@Nullable Object bean, @Nullable Method method, boolean returnExceptions, @Nullable RabbitListenerErrorHandler errorHandler) protectedMessagingMessageListenerAdapter(@Nullable Object bean, @Nullable Method method, boolean returnExceptions, @Nullable RabbitListenerErrorHandler errorHandler, boolean batch) -
Method Summary
Modifier and TypeMethodDescriptionprotected voidasyncFailure(Message request, @Nullable com.rabbitmq.client.Channel channel, Throwable t, @Nullable Object source) protected MessagebuildMessage(@Nullable com.rabbitmq.client.Channel channel, @Nullable Object result, @Nullable Type genericType) Build a Rabbit message to be sent as response based on the given result object.protected HandlerAdapterprotected final MessagingMessageConverterprotected voidhandleException(Message amqpMessage, @Nullable com.rabbitmq.client.Channel channel, @Nullable Message<?> message, ListenerExecutionFailedException e) protected InvocationResultinvokeHandler(@Nullable com.rabbitmq.client.Channel channel, Message<?> message, boolean batch, Message... amqpMessages) Invoke the handler, wrapping any exception to aListenerExecutionFailedExceptionwith a dedicated error message.protected voidinvokeHandlerAndProcessResult(Message amqpMessage, @Nullable com.rabbitmq.client.Channel channel, Message<?> message) booleanReturn true if this listener is request/reply and the replies are async.voidCallback for processing a received Rabbit message.voidsetHandlerAdapter(HandlerAdapter handlerAdapter) Set theHandlerAdapterto use to invoke the method processing an incomingMessage.voidsetHeaderMapper(AmqpHeaderMapper headerMapper) Set theAmqpHeaderMapperimplementation to use to map the standard AMQP headers.voidsetMessageConverter(@Nullable 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
basicAck, containerAckMode, convert, doHandleResult, doPublish, extractMessage, getBeforeSendReplyPostProcessors, getEncoding, getMessageConverter, getReceivedExchange, getReplyContentType, getReplyToAddress, handleListenerException, handleResult, handleResult, isConverterWinsContentType, isDefaultRequeueRejected, isManualAck, postProcessChannel, postProcessResponse, sendResponse, setBeanResolver, setBeforeSendReplyPostProcessors, setConverterWinsContentType, setDefaultRequeueRejected, setEncoding, setMandatoryPublish, setRecoveryCallback, setReplyContentType, setReplyPostProcessor, setResponseAddress, setResponseExchange, setResponseRoutingKey, setRetryTemplateMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.amqp.rabbit.listener.api.ChannelAwareMessageListener
onMessage, onMessageBatchMethods inherited from interface org.springframework.amqp.core.MessageListener
onMessageBatch
-
Field Details
-
messagingMessageConverter
protected final MessagingMessageListenerAdapter.MessagingMessageConverterAdapter messagingMessageConverter -
returnExceptions
protected final boolean returnExceptions -
errorHandler
-
-
Constructor Details
-
MessagingMessageListenerAdapter
public MessagingMessageListenerAdapter() -
MessagingMessageListenerAdapter
-
MessagingMessageListenerAdapter
public MessagingMessageListenerAdapter(@Nullable Object bean, @Nullable Method method, boolean returnExceptions, @Nullable RabbitListenerErrorHandler errorHandler) -
MessagingMessageListenerAdapter
protected MessagingMessageListenerAdapter(@Nullable Object bean, @Nullable Method method, boolean returnExceptions, @Nullable RabbitListenerErrorHandler errorHandler, boolean batch)
-
-
Method Details
-
setHandlerAdapter
Set theHandlerAdapterto use to invoke the method processing an incomingMessage.- Parameters:
handlerAdapter-HandlerAdapterinstance.
-
getHandlerAdapter
-
isAsyncReplies
public boolean isAsyncReplies()Description copied from interface:MessageListenerReturn true if this listener is request/reply and the replies are async.- Returns:
- true for async replies.
-
setHeaderMapper
Set theAmqpHeaderMapperimplementation to use to map the standard AMQP headers. By default, aSimpleAmqpHeaderMapperis used.- Parameters:
headerMapper- theAmqpHeaderMapperinstance.- See Also:
-
getMessagingMessageConverter
- Returns:
- the
MessagingMessageConverterfor this listener, being able to convertMessage.
-
setMessageConverter
Description copied from class:AbstractAdaptableMessageListenerSet 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:
setMessageConverterin classAbstractAdaptableMessageListener- Parameters:
messageConverter- The message converter.
-
onMessage
public void onMessage(Message amqpMessage, @Nullable com.rabbitmq.client.Channel channel) throws Exception Description copied from interface:ChannelAwareMessageListenerCallback 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 (nevernullunless called by the stream listener container).- Throws:
Exception- Any.
-
asyncFailure
protected void asyncFailure(Message request, @Nullable com.rabbitmq.client.Channel channel, Throwable t, @Nullable Object source) - Overrides:
asyncFailurein classAbstractAdaptableMessageListener
-
handleException
protected void handleException(Message amqpMessage, @Nullable com.rabbitmq.client.Channel channel, @Nullable Message<?> message, ListenerExecutionFailedException e) throws Exception - Throws:
Exception
-
invokeHandlerAndProcessResult
-
toMessagingMessage
-
invokeHandler
protected InvocationResult invokeHandler(@Nullable com.rabbitmq.client.Channel channel, Message<?> message, boolean batch, Message... amqpMessages) Invoke the handler, wrapping any exception to aListenerExecutionFailedExceptionwith a dedicated error message.- Parameters:
channel- the channel.message- the messaging message.amqpMessages- the raw AMQP messages.- Returns:
- the result of invoking the handler.
-
buildMessage
protected Message buildMessage(@Nullable com.rabbitmq.client.Channel channel, @Nullable Object result, @Nullable Type genericType) Build a Rabbit message to be sent as response based on the given result object.- Overrides:
buildMessagein 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:
-