Spring.NET 1.3.0 RC1 for .NET 2.0 API Reference

MessageListenerAdapter Class

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.

For a list of all members of this type, see MessageListenerAdapter Members .

System.Object
   MessageListenerAdapter

[Visual Basic]
Public Class MessageListenerAdapter
    Implements IMessageListener, IApplicationContextAware, IInitializingObject
[C#]
public class MessageListenerAdapter : IMessageListener, IApplicationContextAware, IInitializingObject

Thread Safety

Public static (Shared in Visual Basic) members of this type are safe for multithreaded operations. Instance members are not guaranteed to be thread-safe.

Remarks

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); }

Requirements

Namespace: Spring.Messaging.Listener

Assembly: Spring.Messaging (in Spring.Messaging.dll)

See Also

MessageListenerAdapter Members | Spring.Messaging.Listener Namespace