C# Класс Spring.Messaging.Nms.Listener.Adapter.MessageListenerAdapter

Message listener adapter that delegates the handling of messages to target listener methods via reflection, with flexible message type conversion. Allows listener methods to operate on message content types, completely independent from the NMS API.

By default, the content of incoming messages gets extracted before being passed into the target listener method, to let the target method operate on message content types such as String or byte array instead of the raw Message. Message type conversion is delegated to a Spring IMessageConverter. By default, a SimpleMessageConverter will be used. (If you do not want such automatic message conversion taking place, then be sure to set the MessageConverter property to null.)

If a target listener method returns a non-null object (typically of a message content type such as String or byte array), it will get wrapped in a NMS Message and sent to the response destination (either the NMS "reply-to" destination or the defaultResponseDestination specified.

The sending of response messages is only available when using the ISessionAwareMessageListener entry point (typically through a Spring message listener container). Usage as standard NMS MessageListener does not support the generation of response messages.

Consult the reference documentation for examples of method signatures compliant with this adapter class.

Наследование: IMessageListener, ISessionAwareMessageListener
Показать файл Открыть проект Примеры использования класса

Открытые свойства

Свойство Тип Описание
ORIGINAL_DEFAULT_HANDLER_METHOD string

Открытые методы

Метод Описание
MessageListenerAdapter ( ) : System

Initializes a new instance of the MessageListenerAdapter class with default settings.

MessageListenerAdapter ( object handlerObject ) : System

Initializes a new instance of the MessageListenerAdapter class for the given handler object

OnMessage ( IMessage message ) : void

Standard JMS {@link MessageListener} entry point.

Delegates the message to the target listener method, with appropriate conversion of the message arguments

In case of an exception, the HandleListenerException method will be invoked. Note Does not support sending response messages based on result objects returned from listener methods. Use the ISessionAwareMessageListener entry point (typically through a Spring message listener container) for handling result objects as well.

OnMessage ( IMessage message, ISession session ) : void

Spring ISessionAwareMessageListener entry point.

Delegates the message to the target listener method, with appropriate conversion of the message argument. If the target method returns a non-null object, wrap in a NMS message and send it back.

Защищенные методы

Метод Описание
BuildMessage ( ISession session, Object result ) : IMessage

Builds a JMS message to be sent as response based on the given result object.

GetHandlerMethodName ( IMessage originalIMessage, object extractedMessage ) : string

Gets the name of the listener method that is supposed to handle the given message. The default implementation simply returns the configured default listener method, if any.

GetResponseDestination ( IMessage request, IMessage response, ISession session ) : IDestination

Determine a response destination for the given message.

The default implementation first checks the JMS Reply-To Destination of the supplied request; if that is not null it is returned; if it is null, then the configured DefaultResponseDestination default response destination is returned; if this too is null, then an InvalidDestinationExceptionis thrown.

HandleListenerException ( Exception ex ) : void

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 NMS MessageListener. In case of the Spring ISessionAwareMessageListener mechanism, exceptions get handled by the caller instead.

HandleResult ( object result, IMessage request, ISession session ) : void

Handles the given result object returned from the listener method, sending a response message back.

InitDefaultStrategies ( ) : void

Initialize the default implementations for the adapter's strategies.

PostProcessProducer ( IMessageProducer producer, IMessage response ) : void

Post-process the given message producer before using it to send the response. The default implementation is empty.

PostProcessResponse ( IMessage request, IMessage response ) : void

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.

ResolveDefaultResponseDestination ( ISession session ) : IDestination

Resolves the default response destination into a Destination, using this accessor's IDestinationResolver in case of a destination name.

SendResponse ( ISession session, IDestination destination, IMessage response ) : void

Sends the given response message to the given destination.

Приватные методы

Метод Описание
ExtractMessage ( IMessage message ) : object

Extract the message body from the given message.

Описание методов

BuildMessage() защищенный метод

Builds a JMS message to be sent as response based on the given result object.
If there was an error in message conversion if thrown by NMS API methods
protected BuildMessage ( ISession session, Object result ) : IMessage
session ISession The JMS Session to operate on.
result Object The content of the message, as returned from the listener method.
Результат IMessage

GetHandlerMethodName() защищенный метод

Gets the name of the listener method that is supposed to handle the given message. The default implementation simply returns the configured default listener method, if any.
if thrown by NMS API methods
protected GetHandlerMethodName ( IMessage originalIMessage, object extractedMessage ) : string
originalIMessage IMessage The NMS request message.
extractedMessage object The converted JMS request message, /// to be passed into the listener method as argument.
Результат string

GetResponseDestination() защищенный метод

Determine a response destination for the given message.

The default implementation first checks the JMS Reply-To Destination of the supplied request; if that is not null it is returned; if it is null, then the configured DefaultResponseDestination default response destination is returned; if this too is null, then an InvalidDestinationExceptionis thrown.

if thrown by NMS API methods if no destination can be determined.
protected GetResponseDestination ( IMessage request, IMessage response, ISession session ) : IDestination
request IMessage The original incoming message.
response IMessage The outgoing message about to be sent.
session ISession The session to operate on.
Результат IDestination

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 NMS MessageListener. In case of the Spring ISessionAwareMessageListener mechanism, exceptions get handled by the caller instead.

protected HandleListenerException ( Exception ex ) : void
ex System.Exception The exception to handle.
Результат void

HandleResult() защищенный метод

Handles the given result object returned from the listener method, sending a response message back.
protected HandleResult ( object result, IMessage request, ISession session ) : void
result object The result object to handle (never null).
request IMessage The original request message.
session ISession The session to operate on (may be null).
Результат void

InitDefaultStrategies() защищенный метод

Initialize the default implementations for the adapter's strategies.
protected InitDefaultStrategies ( ) : void
Результат void

MessageListenerAdapter() публичный метод

Initializes a new instance of the MessageListenerAdapter class with default settings.
public MessageListenerAdapter ( ) : System
Результат System

MessageListenerAdapter() публичный метод

Initializes a new instance of the MessageListenerAdapter class for the given handler object
public MessageListenerAdapter ( object handlerObject ) : System
handlerObject object The delegate object.
Результат System

OnMessage() публичный метод

Standard JMS {@link MessageListener} entry point.

Delegates the message to the target listener method, with appropriate conversion of the message arguments

In case of an exception, the HandleListenerException method will be invoked. Note Does not support sending response messages based on result objects returned from listener methods. Use the ISessionAwareMessageListener entry point (typically through a Spring message listener container) for handling result objects as well.
public OnMessage ( IMessage message ) : void
message IMessage The incoming message.
Результат void

OnMessage() публичный метод

Spring ISessionAwareMessageListener entry point.

Delegates the message to the target listener method, with appropriate conversion of the message argument. If the target method returns a non-null object, wrap in a NMS message and send it back.

public OnMessage ( IMessage message, ISession session ) : void
message IMessage The incoming message.
session ISession The session to operate on.
Результат void

PostProcessProducer() защищенный метод

Post-process the given message producer before using it to send the response. The default implementation is empty.
protected PostProcessProducer ( IMessageProducer producer, IMessage response ) : void
producer IMessageProducer The producer that will be used to send the message.
response IMessage The outgoing message about to be sent.
Результат void

PostProcessResponse() защищенный метод

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 thrown by NMS API methods
protected PostProcessResponse ( IMessage request, IMessage response ) : void
request IMessage The original incoming message.
response IMessage The outgoing JMS message about to be sent.
Результат void

ResolveDefaultResponseDestination() защищенный метод

Resolves the default response destination into a Destination, using this accessor's IDestinationResolver in case of a destination name.
protected ResolveDefaultResponseDestination ( ISession session ) : IDestination
session ISession The session to operate on.
Результат IDestination

SendResponse() защищенный метод

Sends the given response message to the given destination.
protected SendResponse ( ISession session, IDestination destination, IMessage response ) : void
session ISession The session to operate on.
destination IDestination The destination to send to.
response IMessage The outgoing message about to be sent.
Результат void

Описание свойств

ORIGINAL_DEFAULT_HANDLER_METHOD публичное статическое свойство

The default handler method name.
public static string ORIGINAL_DEFAULT_HANDLER_METHOD
Результат string