C# 클래스 Spring.Messaging.Listener.MessageListenerAdapter

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

By default, the content of incoming MSMQ messages gets extracted before being passed into the target handler method, to let the target method operate on message content types such as String or business object instead of Message. Message type conversion is delegated to a Spring IMessageConverter By default, an XmlMessageConverter with TargetType set to System.String is 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 handler method returns a non-null object (for example, with a message content type such as String), it will get wrapped in a MSMQ Message and sent to the response destination (either using the MSMQ Message.ResponseQueue property or DefaultResponseQueue) specified default response queue destination).

Find below some examples of method signatures compliant with this adapter class. This first example uses the default XmlMessageConverter that can marhsall/unmarshall string values from the MSMQ Message.

public interface IMyHandler { void HandleMessage(string text); }

The next example indicates a similar method signature but the name of the handler method name has been changed to "DoWork", using the property DefaultHandlerMethod

public interface IMyHandler { void DoWork(string text); }

If your IMessageConverter implementation will return multiple object types, overloading the handler method is perfectly acceptible, the most specific matching method will be used. A method with an object signature would be consider a 'catch-all' method

public interface IMyHandler { void DoWork(string text); void DoWork(OrderRequest orderRequest); void DoWork(InvoiceRequest invoiceRequest); void DoWork(object obj); }

The last example shows how to send a message to the ResponseQueue for those methods that do not return void. public interface MyHandler { string DoWork(string text); OrderResponse DoWork(OrderRequest orderRequest); InvoiceResponse DoWork(InvoiceRequest invoiceRequest); void DoWork(object obj); }

상속: IMessageListener, IApplicationContextAware, IInitializingObject
파일 보기 프로젝트 열기: spring-projects/spring-net

공개 프로퍼티들

프로퍼티 타입 설명
ORIGINAL_DEFAULT_LISTENER_METHOD string

공개 메소드들

메소드 설명
AfterPropertiesSet ( ) : void

Invoked by an Spring.Objects.Factory.IObjectFactory after it has injected all of an object's dependencies.

This method allows the object instance to perform the kind of initialization only possible when all of it's dependencies have been injected (set), and to throw an appropriate exception in the event of misconfiguration.

Please do consult the class level documentation for the Spring.Objects.Factory.IObjectFactory interface for a description of exactly when this method is invoked. In particular, it is worth noting that the Spring.Objects.Factory.IObjectFactoryAware and Spring.Context.IApplicationContextAware callbacks will have been invoked prior to this method being called.

MessageListenerAdapter ( ) : System.Collections.Generic

Initializes a new instance of the MessageListenerAdapter class.

MessageListenerAdapter ( object handlerObject ) : System.Collections.Generic

Initializes a new instance of the MessageListenerAdapter class.

OnMessage ( System.Messaging.Message message ) : void

Called when message is received.

보호된 메소드들

메소드 설명
BuildListenerArguments ( object convertedMessage ) : object[]

Builds an array of arguments to be passed into the taret listener method.

Allows for multiple method arguments to be built from a single message object.

The default implementation builds an array with the given message object as sole element. This means that the extracted message will always be passed into a single method argument, even if it is an array, with the target method having a corresponding single argument of the array's type declared.

This can be overridden to treat special message content such as arrays differently, for example passing in each element of the message array as distinct method argument.

BuildMessage ( object result ) : System.Messaging.Message

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

ExtractMessage ( System.Messaging.Message message ) : object

Extracts the message body from the given message.

GetHandlerMethodName ( System.Messaging.Message originalMessage, object extractedMessage ) : string

Gets the name of the handler method.

GetResponseDestination ( System.Messaging.Message request, System.Messaging.Message response ) : System.Messaging.MessageQueue

Determine a response destination for the given message.

The default implementation first checks the MSMQ ResponseQueue of the supplied request; if that is not null it is returned; if it is null, then the configured DefaultResponseQueue default response destination} is returned; if this too is null, then an MessagingExceptionis thrown.

HandleResult ( object result, System.Messaging.Message request ) : void

Handles the result of a listener method.

InitDefaultStrategies ( ) : void

Initialize the default implementations for the adapter's strategies.

InvokeListenerMethod ( string methodName, object arguments ) : object

Invokes the specified listener method. This default implementation can only handle invoking a single argument method.

PostProcessResponse ( System.Messaging.Message request, System.Messaging.Message 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.

SendResponse ( System.Messaging.MessageQueue destination, System.Messaging.Message response ) : void

Sends the given response message to the given destination.

메소드 상세

AfterPropertiesSet() 공개 메소드

Invoked by an Spring.Objects.Factory.IObjectFactory after it has injected all of an object's dependencies.

This method allows the object instance to perform the kind of initialization only possible when all of it's dependencies have been injected (set), and to throw an appropriate exception in the event of misconfiguration.

Please do consult the class level documentation for the Spring.Objects.Factory.IObjectFactory interface for a description of exactly when this method is invoked. In particular, it is worth noting that the Spring.Objects.Factory.IObjectFactoryAware and Spring.Context.IApplicationContextAware callbacks will have been invoked prior to this method being called.

/// In the event of misconfiguration (such as the failure to set a /// required property) or if initialization fails. ///
public AfterPropertiesSet ( ) : void
리턴 void

BuildListenerArguments() 보호된 메소드

Builds an array of arguments to be passed into the taret listener method.
Allows for multiple method arguments to be built from a single message object.

The default implementation builds an array with the given message object as sole element. This means that the extracted message will always be passed into a single method argument, even if it is an array, with the target method having a corresponding single argument of the array's type declared.

This can be overridden to treat special message content such as arrays differently, for example passing in each element of the message array as distinct method argument.

protected BuildListenerArguments ( object convertedMessage ) : object[]
convertedMessage object The converted message.
리턴 object[]

BuildMessage() 보호된 메소드

Builds a MSMQ message to be sent as response based on the given result object.
If no messgae converter is specified.
protected BuildMessage ( object result ) : System.Messaging.Message
result object The result.
리턴 System.Messaging.Message

ExtractMessage() 보호된 메소드

Extracts the message body from the given message.
protected ExtractMessage ( System.Messaging.Message message ) : object
message System.Messaging.Message The message.
리턴 object

GetHandlerMethodName() 보호된 메소드

Gets the name of the handler method.
protected GetHandlerMethodName ( System.Messaging.Message originalMessage, object extractedMessage ) : string
originalMessage System.Messaging.Message The original message.
extractedMessage object The extracted message.
리턴 string

GetResponseDestination() 보호된 메소드

Determine a response destination for the given message.

The default implementation first checks the MSMQ ResponseQueue of the supplied request; if that is not null it is returned; if it is null, then the configured DefaultResponseQueue default response destination} is returned; if this too is null, then an MessagingExceptionis thrown.

protected GetResponseDestination ( System.Messaging.Message request, System.Messaging.Message response ) : System.Messaging.MessageQueue
request System.Messaging.Message The request.
response System.Messaging.Message The response.
리턴 System.Messaging.MessageQueue

HandleResult() 보호된 메소드

Handles the result of a listener method.
protected HandleResult ( object result, System.Messaging.Message request ) : void
result object The result that was returned from listener.
request System.Messaging.Message The original request.
리턴 void

InitDefaultStrategies() 보호된 메소드

Initialize the default implementations for the adapter's strategies.
protected InitDefaultStrategies ( ) : void
리턴 void

InvokeListenerMethod() 보호된 메소드

Invokes the specified listener method. This default implementation can only handle invoking a single argument method.
protected InvokeListenerMethod ( string methodName, object arguments ) : object
methodName string Name of the listener method.
arguments object The arguments to be passed in. Only the first argument in the list is currently /// supported in this implementation.
리턴 object

MessageListenerAdapter() 공개 메소드

Initializes a new instance of the MessageListenerAdapter class.
public MessageListenerAdapter ( ) : System.Collections.Generic
리턴 System.Collections.Generic

MessageListenerAdapter() 공개 메소드

Initializes a new instance of the MessageListenerAdapter class.
public MessageListenerAdapter ( object handlerObject ) : System.Collections.Generic
handlerObject object The handler object.
리턴 System.Collections.Generic

OnMessage() 공개 메소드

Called when message is received.
public OnMessage ( System.Messaging.Message message ) : void
message System.Messaging.Message The message.
리턴 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.
protected PostProcessResponse ( System.Messaging.Message request, System.Messaging.Message response ) : void
request System.Messaging.Message The original incoming message.
response System.Messaging.Message The outgoing MSMQ message about to be sent.
리턴 void

SendResponse() 보호된 메소드

Sends the given response message to the given destination.
protected SendResponse ( System.Messaging.MessageQueue destination, System.Messaging.Message response ) : void
destination System.Messaging.MessageQueue The destination to send to.
response System.Messaging.Message The outgoing message about to be sent.
리턴 void

프로퍼티 상세

ORIGINAL_DEFAULT_LISTENER_METHOD 공개적으로 정적으로 프로퍼티

Out-of-the-box value for the default listener method: "HandleMessage"
public static string ORIGINAL_DEFAULT_LISTENER_METHOD
리턴 string