Castle Windsor Component Messaging: Senders & Receivers
June 12th, 2007 by TrilobyteHere is some more information about the messaging framework I have been working on the last couple of weeks. Although I had less time to work on the framework then I had expected, I managed to get some work done on message filtering, but that is a subject for a next post.
In this post I will explain how you implement a message sender and receiver class. I tried to keep the framework as simple as possible and I think I did a pretty good job, however if you have any comments or ideas, please let me know.
Anyway, enough talk, lets get down to business.
Implementing a message sender
Implementing a sender is very easy, there are two things to do: The first step is to implement the IMessageSender interface or derive from the SenderBase class. Then you need to decorate the sender class with the MessageSenderAttribute. That is it.
Example:
[MessageSender()]
public class TestSender: SenderBase
{
public void SendMessage()
{
TestMessage msg = new TestMessage();
base.DoSend(msg);
}
}
The TestMessage which is send in the example code does not contain any information, but you can define your own message class which contains any information you can imagine.
Implementing a message receiver
The implementation of a receiver class is not equal easy as the implementation of the sender class. There are two steps as well: The first step is to implement the IMessageReceiver interface and the second step is to decorate the class with the MessageReceiverAttribute.
Example:
[MessageReceiver()]
public class TestReceiver: IMessageReceiver
{
public void Receive(IMessage message)
{
// do something with the message
}
}
The receive function will be called when a message is received.
Currently I am working on the implementation of the message filters. The idea is that you can do pre-processing on messages using some clean C# constructs. When I got an implementation ready I will post it on this weblog. That is it for now. See you next time.