Class AbstractAdaptableMessageListener
- All Implemented Interfaces:
jakarta.jms.MessageListener, SessionAwareMessageListener<jakarta.jms.Message>
- Direct Known Subclasses:
MessageListenerAdapter, MessagingMessageListenerAdapter
MessageListener adapter providing the necessary
infrastructure to extract the payload of a JMS Message.- Since:
- 4.1
- Author:
- Juergen Hoeller, Stephane Nicoll
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final org.apache.commons.logging.LogLogger available to subclasses. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected jakarta.jms.MessagebuildMessage(jakarta.jms.Session session, Object result) Build a JMS message to be sent as response based on the given result object.protected ObjectextractMessage(jakarta.jms.Message message) Extract the message body from the given JMS message.protected DestinationResolverReturn the DestinationResolver for this adapter.protected @Nullable MessageConverterReturn the converter that will convert incoming JMS messages to listener method arguments, and objects returned from listener methods back to JMS messages.protected final MessagingMessageConverterReturn theMessagingMessageConverterfor this listener, being able to convertMessage.protected jakarta.jms.DestinationgetResponseDestination(jakarta.jms.Message request, jakarta.jms.Message response, jakarta.jms.Session session) Determine a response destination for the given message.protected @Nullable QosSettingsReturn theQosSettingsto use when sending a response, ornullif the defaults should be used.protected voidHandle the given exception that arose during listener execution.protected voidhandleResult(Object result, jakarta.jms.Message request, @Nullable jakarta.jms.Session session) Handle the given result object returned from the listener method, sending a response message back.voidonMessage(jakarta.jms.Message message) Standard JMSMessageListenerentry point.abstract voidCallback for processing a received JMS message.protected voidpostProcessProducer(jakarta.jms.MessageProducer producer, jakarta.jms.Message response) Post-process the given message producer before using it to send the response.protected voidpostProcessResponse(jakarta.jms.Message request, jakarta.jms.Message response) Post-process the given response message before it will be sent.protected ObjectpreProcessResponse(Object result) Pre-process the given result before it is converted to aMessage.protected @Nullable jakarta.jms.DestinationresolveDefaultResponseDestination(jakarta.jms.Session session) Resolve the default response destination into a JMSDestination, using this accessor'sDestinationResolverin case of a destination name.protected voidsendResponse(jakarta.jms.Session session, jakarta.jms.Destination destination, jakarta.jms.Message response) Send the given response message to the given destination.voidsetDefaultResponseDestination(jakarta.jms.Destination destination) Set the default destination to send response messages to.voidsetDefaultResponseQueueName(String destinationName) Set the name of the default response queue to send response messages to.voidsetDefaultResponseTopicName(String destinationName) Set the name of the default response topic to send response messages to.voidsetDestinationResolver(DestinationResolver destinationResolver) Set the DestinationResolver that should be used to resolve response destination names for this adapter.voidsetHeaderMapper(JmsHeaderMapper headerMapper) Set theJmsHeaderMapperimplementation to use to map the standard JMS headers.voidsetMessageConverter(@Nullable MessageConverter messageConverter) Set the converter that will convert incoming JMS messages to listener method arguments, and objects returned from listener methods back to JMS messages.voidsetResponseQosSettings(@Nullable QosSettings responseQosSettings) Set theQosSettingsto use when sending a response.
-
Field Details
-
logger
protected final org.apache.commons.logging.Log loggerLogger available to subclasses.
-
-
Constructor Details
-
AbstractAdaptableMessageListener
public AbstractAdaptableMessageListener()
-
-
Method Details
-
setDefaultResponseDestination
public void setDefaultResponseDestination(jakarta.jms.Destination destination) Set the default destination to send response messages to. This will be applied in case of a request message that does not carry a "JMSReplyTo" field.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.
Alternatively, specify a "defaultResponseQueueName" or "defaultResponseTopicName", to be dynamically resolved via the DestinationResolver.
- See Also:
-
setDefaultResponseQueueName
Set the name of the default response queue to send response messages to. This will be applied in case of a request message that does not carry a "JMSReplyTo" field.Alternatively, specify a JMS Destination object as "defaultResponseDestination".
- See Also:
-
setDefaultResponseTopicName
Set the name of the default response topic to send response messages to. This will be applied in case of a request message that does not carry a "JMSReplyTo" field.Alternatively, specify a JMS Destination object as "defaultResponseDestination".
- See Also:
-
setDestinationResolver
Set the DestinationResolver that should be used to resolve response destination names for this adapter.The default resolver is a SimpleDestinationResolver. Specify a JndiDestinationResolver for resolving destination names as JNDI locations.
- See Also:
-
getDestinationResolver
Return the DestinationResolver for this adapter. -
setMessageConverter
Set the converter that will convert incoming JMS messages to listener method arguments, and objects returned from listener methods back to JMS messages.The default converter is a
SimpleMessageConverter, which is able to handleBytesMessages,TextMessagesandObjectMessages. -
getMessageConverter
Return the converter that will convert incoming JMS messages to listener method arguments, and objects returned from listener methods back to JMS messages. -
setHeaderMapper
Set theJmsHeaderMapperimplementation to use to map the standard JMS headers. By default, aSimpleJmsHeaderMapperis used.- See Also:
-
getMessagingMessageConverter
Return theMessagingMessageConverterfor this listener, being able to convertMessage. -
setResponseQosSettings
Set theQosSettingsto use when sending a response. Can be set tonullto indicate that the broker's defaults should be used.- Parameters:
responseQosSettings- the QoS settings to use when sending a response ornullto use the default values.- Since:
- 5.0
-
getResponseQosSettings
Return theQosSettingsto use when sending a response, ornullif the defaults should be used.- Since:
- 5.0
-
onMessage
public void onMessage(jakarta.jms.Message message) Standard JMSMessageListenerentry point.Delegates the message to the target listener method, with appropriate conversion of the message argument. In case of an exception, the
handleListenerException(Throwable)method will be invoked.Note: Does not support sending response messages based on result objects returned from listener methods. Use the
SessionAwareMessageListenerentry point (typically through a Spring message listener container) for handling result objects as well.- Specified by:
onMessagein interfacejakarta.jms.MessageListener- Parameters:
message- the incoming JMS message- See Also:
-
onMessage
public abstract void onMessage(jakarta.jms.Message message, @Nullable jakarta.jms.Session session) throws jakarta.jms.JMSException Description copied from interface:SessionAwareMessageListenerCallback for processing a received JMS message.Implementors are supposed to process the given Message, typically sending reply messages through the given Session.
- Specified by:
onMessagein interfaceSessionAwareMessageListener<jakarta.jms.Message>- Parameters:
message- the received JMS message (nevernull)session- the underlying JMS Session (nevernull)- Throws:
jakarta.jms.JMSException- if thrown by JMS methods
-
handleListenerException
Handle the given exception that arose during listener execution. The default implementation logs the exception at error level.This method only applies when used as standard JMS
MessageListener. In case of the SpringSessionAwareMessageListenermechanism, exceptions get handled by the caller instead.- Parameters:
ex- the exception to handle- See Also:
-
extractMessage
Extract the message body from the given JMS message.- Parameters:
message- the JMSMessage- Returns:
- the content of the message, to be passed into the listener method as an argument
- Throws:
MessageConversionException- if the message could not be extracted
-
handleResult
protected void handleResult(Object result, jakarta.jms.Message request, @Nullable jakarta.jms.Session session) Handle the given result object returned from the listener method, sending a response message back.- Parameters:
result- the result object to handle (nevernull)request- the original request messagesession- the JMS Session to operate on (may benull)- Throws:
ReplyFailureException- if the response message could not be sent- See Also:
-
buildMessage
protected jakarta.jms.Message buildMessage(jakarta.jms.Session session, Object result) throws jakarta.jms.JMSException Build a JMS message to be sent as response based on the given result object.- Parameters:
session- the JMS Session to operate onresult- the content of the message, as returned from the listener method- Returns:
- the JMS
Message(nevernull) - Throws:
jakarta.jms.JMSException- if thrown by JMS API methods- See Also:
-
preProcessResponse
Pre-process the given result before it is converted to aMessage.- Parameters:
result- the result of the invocation- Returns:
- the payload response to handle, either the
resultargument or any other object (for instance wrapping the result). - Since:
- 4.3
-
postProcessResponse
protected void postProcessResponse(jakarta.jms.Message request, jakarta.jms.Message response) throws jakarta.jms.JMSException Post-process the given response message before it will be sent.The default implementation sets the response's correlation id to the request message's correlation id, if any; otherwise to the request message id.
- Parameters:
request- the original incoming JMS messageresponse- the outgoing JMS message about to be sent- Throws:
jakarta.jms.JMSException- if thrown by JMS API methods- See Also:
-
getResponseDestination
protected jakarta.jms.Destination getResponseDestination(jakarta.jms.Message request, jakarta.jms.Message response, jakarta.jms.Session session) throws jakarta.jms.JMSException Determine a response destination for the given message.The default implementation first checks the JMS Reply-To
Destinationof the supplied request; if that is notnullit is returned; if it isnull, then the configureddefault response destinationis returned; if this too isnull, then anInvalidDestinationExceptionis thrown.- Parameters:
request- the original incoming JMS messageresponse- the outgoing JMS message about to be sentsession- the JMS Session to operate on- Returns:
- the response destination (never
null) - Throws:
jakarta.jms.JMSException- if thrown by JMS API methodsjakarta.jms.InvalidDestinationException- if noDestinationcan be determined- See Also:
-
resolveDefaultResponseDestination
protected @Nullable jakarta.jms.Destination resolveDefaultResponseDestination(jakarta.jms.Session session) throws jakarta.jms.JMSException Resolve the default response destination into a JMSDestination, using this accessor'sDestinationResolverin case of a destination name.- Returns:
- the located
Destination - Throws:
jakarta.jms.JMSException- if resolution failed- See Also:
-
sendResponse
protected void sendResponse(jakarta.jms.Session session, jakarta.jms.Destination destination, jakarta.jms.Message response) throws jakarta.jms.JMSException Send the given response message to the given destination.- Parameters:
session- the JMS session to operate ondestination- the JMS destination to send toresponse- the JMS message to send- Throws:
jakarta.jms.JMSException- if thrown by JMS API methods- See Also:
-
postProcessProducer
protected void postProcessProducer(jakarta.jms.MessageProducer producer, jakarta.jms.Message response) throws jakarta.jms.JMSException Post-process the given message producer before using it to send the response.The default implementation is empty.
- Parameters:
producer- the JMS message producer that will be used to send the messageresponse- the outgoing JMS message about to be sent- Throws:
jakarta.jms.JMSException- if thrown by JMS API methods
-