public abstract class AbstractAdaptableMessageListener extends java.lang.Object implements ChannelAwareMessageListener
MessageListener adapter providing the
necessary infrastructure to extract the payload of a Message.ChannelAwareMessageListener| Modifier and Type | Class and Description |
|---|---|
static class |
AbstractAdaptableMessageListener.ReplyExpressionRoot
Root object for reply expression evaluation.
|
| Modifier and Type | Field and Description |
|---|---|
protected org.apache.commons.logging.Log |
logger
Logger available to subclasses.
|
| Constructor and Description |
|---|
AbstractAdaptableMessageListener() |
| Modifier and Type | Method and Description |
|---|---|
protected org.springframework.amqp.core.Message |
buildMessage(com.rabbitmq.client.Channel channel,
java.lang.Object result,
java.lang.reflect.Type genericType)
Build a Rabbit message to be sent as response based on the given result object.
|
void |
containerAckMode(org.springframework.amqp.core.AcknowledgeMode mode) |
protected org.springframework.amqp.core.Message |
convert(java.lang.Object result,
java.lang.reflect.Type genericType,
org.springframework.amqp.support.converter.MessageConverter converter)
Convert to a message, with reply content type based on settings.
|
protected void |
doHandleResult(InvocationResult resultArg,
org.springframework.amqp.core.Message request,
com.rabbitmq.client.Channel channel,
java.lang.Object source) |
protected void |
doPublish(com.rabbitmq.client.Channel channel,
org.springframework.amqp.core.Address replyTo,
org.springframework.amqp.core.Message message) |
protected java.lang.Object |
extractMessage(org.springframework.amqp.core.Message message)
Extract the message body from the given Rabbit message.
|
java.lang.String |
getEncoding()
The encoding to use when inter-converting between byte arrays and Strings in
message properties.
|
protected org.springframework.amqp.support.converter.MessageConverter |
getMessageConverter()
Return the converter that will convert incoming Rabbit messages to listener method arguments, and objects
returned from listener methods back to Rabbit messages.
|
protected java.lang.String |
getReceivedExchange(org.springframework.amqp.core.Message request) |
protected java.lang.String |
getReplyContentType()
Get the reply content type.
|
protected org.springframework.amqp.core.Address |
getReplyToAddress(org.springframework.amqp.core.Message request,
java.lang.Object source,
InvocationResult result)
Determine a reply-to Address for the given message.
|
protected void |
handleListenerException(java.lang.Throwable ex)
Handle the given exception that arose during listener execution.
|
protected void |
handleResult(InvocationResult resultArg,
org.springframework.amqp.core.Message request,
com.rabbitmq.client.Channel channel)
Handle the given result object returned from the listener method, sending a
response message back.
|
protected void |
handleResult(InvocationResult resultArg,
org.springframework.amqp.core.Message request,
com.rabbitmq.client.Channel channel,
java.lang.Object source)
Handle the given result object returned from the listener method, sending a
response message back.
|
protected boolean |
isConverterWinsContentType()
Return whether the content type set by a converter prevails or not.
|
protected void |
postProcessChannel(com.rabbitmq.client.Channel channel,
org.springframework.amqp.core.Message response)
Post-process the given message before sending the response.
|
protected void |
postProcessResponse(org.springframework.amqp.core.Message request,
org.springframework.amqp.core.Message response)
Post-process the given response message before it will be sent.
|
protected void |
sendResponse(com.rabbitmq.client.Channel channel,
org.springframework.amqp.core.Address replyTo,
org.springframework.amqp.core.Message messageIn)
Send the given response message to the given destination.
|
void |
setBeanResolver(org.springframework.expression.BeanResolver beanResolver)
Set a bean resolver for runtime SpEL expressions.
|
void |
setBeforeSendReplyPostProcessors(org.springframework.amqp.core.MessagePostProcessor... beforeSendReplyPostProcessors)
Set post processors that will be applied before sending replies.
|
void |
setConverterWinsContentType(boolean converterWinsContentType)
Set whether the content type set by a converter prevails or not.
|
void |
setDefaultRequeueRejected(boolean defaultRequeueRejected)
Set to the value of this listener's container equivalent property.
|
void |
setEncoding(java.lang.String encoding)
The encoding to use when inter-converting between byte arrays and Strings in
message properties.
|
void |
setMandatoryPublish(boolean mandatoryPublish) |
void |
setMessageConverter(org.springframework.amqp.support.converter.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.
|
void |
setRecoveryCallback(org.springframework.retry.RecoveryCallback<?> recoveryCallback)
Set a
RecoveryCallback to invoke when retries are exhausted. |
void |
setReplyContentType(java.lang.String replyContentType)
Set the reply content type.
|
void |
setReplyPostProcessor(ReplyPostProcessor replyPostProcessor)
Set a
ReplyPostProcessor to post process a response message before it is
sent. |
void |
setResponseAddress(java.lang.String defaultReplyTo)
Set the default replyTo address to use when sending response messages.
|
void |
setResponseExchange(java.lang.String responseExchange)
Set the exchange to use when sending response messages.
|
void |
setResponseRoutingKey(java.lang.String responseRoutingKey)
Set the routing key to use when sending response messages.
|
void |
setRetryTemplate(org.springframework.retry.support.RetryTemplate retryTemplate)
Set a
RetryTemplate to use when sending replies. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitonMessage, onMessage, onMessageBatchprotected final org.apache.commons.logging.Log logger
public void setResponseRoutingKey(java.lang.String responseRoutingKey)
Response destinations are only relevant for listener methods that return result objects, which will be wrapped in a response message and sent to a response destination.
responseRoutingKey - The routing key.public void setEncoding(java.lang.String encoding)
encoding - the encoding to set.public java.lang.String getEncoding()
public void setResponseExchange(java.lang.String responseExchange)
Response destinations are only relevant for listener methods that return result objects, which will be wrapped in a response message and sent to a response destination.
responseExchange - The exchange.public void setResponseAddress(java.lang.String defaultReplyTo)
Response destinations are only relevant for listener methods that return result objects, which will be wrapped in a response message and sent to a response destination.
It can be a string surrounded by "!{...}" in which case the expression is evaluated at runtime; see the reference manual for more information.
defaultReplyTo - The exchange.public void setMandatoryPublish(boolean mandatoryPublish)
public void setMessageConverter(org.springframework.amqp.support.converter.MessageConverter messageConverter)
The default converter is a SimpleMessageConverter, which is able to handle "text" content-types.
messageConverter - The message converter.public void setBeforeSendReplyPostProcessors(org.springframework.amqp.core.MessagePostProcessor... beforeSendReplyPostProcessors)
beforeSendReplyPostProcessors - the post processors.public void setRetryTemplate(org.springframework.retry.support.RetryTemplate retryTemplate)
RetryTemplate to use when sending replies.retryTemplate - the template.setRecoveryCallback(RecoveryCallback)public void setRecoveryCallback(org.springframework.retry.RecoveryCallback<?> recoveryCallback)
RecoveryCallback to invoke when retries are exhausted.recoveryCallback - the recovery callback.setRetryTemplate(RetryTemplate)public void setBeanResolver(org.springframework.expression.BeanResolver beanResolver)
beanResolver - the resolver.public void setReplyPostProcessor(ReplyPostProcessor replyPostProcessor)
ReplyPostProcessor to post process a response message before it is
sent. It is called after postProcessResponse(Message, Message) which sets
up the correlationId header.replyPostProcessor - the post processor.protected java.lang.String getReplyContentType()
public void setReplyContentType(java.lang.String replyContentType)
replyContentType - the content type.protected boolean isConverterWinsContentType()
public void setConverterWinsContentType(boolean converterWinsContentType)
converterWinsContentType - false to always apply the reply content type.protected org.springframework.amqp.support.converter.MessageConverter getMessageConverter()
public void setDefaultRequeueRejected(boolean defaultRequeueRejected)
defaultRequeueRejected - false to not requeue.public void containerAckMode(org.springframework.amqp.core.AcknowledgeMode mode)
containerAckMode in interface org.springframework.amqp.core.MessageListenerprotected void handleListenerException(java.lang.Throwable ex)
Can be used by inheritors from overridden ChannelAwareMessageListener.onMessage(Message)
or ChannelAwareMessageListener.onMessage(Message, com.rabbitmq.client.Channel)
ex - the exception to handleprotected java.lang.Object extractMessage(org.springframework.amqp.core.Message message)
message - the Rabbit Messageprotected void handleResult(InvocationResult resultArg, org.springframework.amqp.core.Message request, com.rabbitmq.client.Channel channel)
resultArg - the result object to handle (never null)request - the original request messagechannel - the Rabbit channel to operate on (may be null)buildMessage(com.rabbitmq.client.Channel, java.lang.Object, java.lang.reflect.Type),
postProcessResponse(org.springframework.amqp.core.Message, org.springframework.amqp.core.Message),
getReplyToAddress(Message, Object, InvocationResult),
sendResponse(com.rabbitmq.client.Channel, org.springframework.amqp.core.Address, org.springframework.amqp.core.Message)protected void handleResult(InvocationResult resultArg, org.springframework.amqp.core.Message request, com.rabbitmq.client.Channel channel, java.lang.Object source)
resultArg - the result object to handle (never null)request - the original request messagechannel - the Rabbit channel to operate on (may be null)source - the source data for the method invocation - e.g.
o.s.messaging.Message<?>; may be nullbuildMessage(com.rabbitmq.client.Channel, java.lang.Object, java.lang.reflect.Type),
postProcessResponse(org.springframework.amqp.core.Message, org.springframework.amqp.core.Message),
getReplyToAddress(Message, Object, InvocationResult),
sendResponse(com.rabbitmq.client.Channel, org.springframework.amqp.core.Address, org.springframework.amqp.core.Message)protected void doHandleResult(InvocationResult resultArg, org.springframework.amqp.core.Message request, com.rabbitmq.client.Channel channel, java.lang.Object source)
protected java.lang.String getReceivedExchange(org.springframework.amqp.core.Message request)
protected org.springframework.amqp.core.Message buildMessage(com.rabbitmq.client.Channel channel,
java.lang.Object result,
java.lang.reflect.Type genericType)
channel - the Rabbit Channel to operate on.result - the content of the message, as returned from the listener method.genericType - the generic type to populate type headers.Message (never null).setMessageConverter(org.springframework.amqp.support.converter.MessageConverter)protected org.springframework.amqp.core.Message convert(java.lang.Object result,
java.lang.reflect.Type genericType,
org.springframework.amqp.support.converter.MessageConverter converter)
result - the result.genericType - the type.converter - the converter.protected void postProcessResponse(org.springframework.amqp.core.Message request,
org.springframework.amqp.core.Message response)
The default implementation sets the response's correlation id to the request message's correlation id, if any; otherwise to the request message id.
request - the original incoming Rabbit messageresponse - the outgoing Rabbit message about to be sentprotected org.springframework.amqp.core.Address getReplyToAddress(org.springframework.amqp.core.Message request,
java.lang.Object source,
InvocationResult result)
The default implementation first checks the Rabbit Reply-To Address of the supplied request; if that is not
null it is returned; if it is null, then the configured default response Exchange and
routing key are used to construct a reply-to Address. If the responseExchange property is also null,
then an AmqpException is thrown.
request - the original incoming Rabbit message.source - the source data (e.g. o.s.messaging.Message<?>).result - the result.null)org.springframework.amqp.AmqpException - if no Address can be determinedsetResponseAddress(String),
setResponseRoutingKey(String),
Message.getMessageProperties(),
MessageProperties.getReplyTo()protected void sendResponse(com.rabbitmq.client.Channel channel,
org.springframework.amqp.core.Address replyTo,
org.springframework.amqp.core.Message messageIn)
channel - the Rabbit channel to operate onreplyTo - the Rabbit ReplyTo string to use when sending. Currently interpreted to be the routing key.messageIn - the Rabbit message to sendpostProcessResponse(Message, Message),
setReplyPostProcessor(ReplyPostProcessor)protected void doPublish(com.rabbitmq.client.Channel channel,
org.springframework.amqp.core.Address replyTo,
org.springframework.amqp.core.Message message)
throws java.io.IOException
java.io.IOExceptionprotected void postProcessChannel(com.rabbitmq.client.Channel channel,
org.springframework.amqp.core.Message response)
The default implementation is empty.
channel - The channel.response - the outgoing Rabbit message about to be sent