Solutions    |    Downloads    |    License    |    Documentation    |    Training    |    Support    |    Customers    |    About Us

How Do I Define A Message?

Last Updated: Nov 28, 2012 10:36AM IST
public class MyMessage : IMessage { }

OR

public interface IMyMessage : IMessage { }

One of the advantages of using interfaces to define messages instead of classes is that you get "multiple inheritance" - one message can extend multiple other messages.

This is useful for solving a specific class of versioning problems.

Say that your business logic represents a state machine with states X and Y. When your system gets into state X, it publishes a message - EnteredStateX. When your system gets into state Y, it publishes a message - EnteredStateY. (For more information on how to publish a message, see below)

In the next version of your system, you add a new state Z, which represents the co-existence of both X and Y. So, you define a message EnteredStateZ which inherits both EnteredStateX and EnteredStateY.

When your system publishes EnteredStateZ, clients subscribed to either (or both) EnteredStateX or EnteredStateY will be notified.

Without the ability to have a message extend multiple others, you'd have to use composition. This would prevent the infrastructure from knowing how to automatically route messages to pre-existing subscribers of the composed messages.

About NServiceBus    |    Contact Us    |    Privacy    |    Follow us on:   
Copyright 2010-2013 NServiceBus. All rights reserved
NSB_Y@yahoo.com
http://assets3.desk.com/r1046ffeaa2233e531563a32d7edef6677d8a78b5/javascripts/
nservicebus
Loading
seconds ago
a minute ago
minutes ago
an hour ago
hours ago
a day ago
days ago
about
true
Invalid characters found
/customer/portal/articles/autocomplete
There was an error contacting Get Satisfaction
View All
0
discussions
replies
Questions
Ideas
Problems
Praise