Masstransit message structure...turtles (interfaces) all the way down

51 views
Skip to first unread message

Shane Holder

unread,
May 6, 2015, 9:07:51 AM5/6/15
to masstrans...@googlegroups.com
It has been firmly ingrained in me that messages should be interfaces, but how about the content of a messages should it only contain interfaces?

For example an Order which implements IOrder has order lines.  Should the order lines be an interface of IOrderLine or is it OK to provide just use a class of OrderLine?

public interface IOrder {
  List<IOrderLines> Lines {get;set;}
}

or

public interface IOrder {
  List<OrderLines> Lines {get;set;}
}

Thanks,
Shane

Chris Patterson

unread,
May 6, 2015, 10:22:02 AM5/6/15
to masstrans...@googlegroups.com
It depends, of course, on your goals. In our application, most (not all, we have many developers and not everyone does it the same -- but we try) of the message contracts are entirely interface-only data types.

For instance, List<T> is mutable, so we use T[] (arrays). And we typically drop the IXxx convention since they are behavior-free data bags, it just makes it cleaner and easier to read.

So we have:

public interface Order {
    OrderLine[] Lines {get;}
}

public interface OrderLine {
    string ItemId {get;}
    string Description {get;}
    decimal UnitPrice {get;}
}

Notice that there are no {set;} methods on the properties, that would allow a consumer to modify the message content.

In a large application (easily 100+ decoupled services, coordinated through Courier routing slips, with over 200 consumers for various events and state machines) this has worked very well.


--
You received this message because you are subscribed to the Google Groups "masstransit-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to masstransit-dis...@googlegroups.com.
To post to this group, send email to masstrans...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/masstransit-discuss/e69bf9c8-7a3e-4ef4-89f1-a1d112284b9c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Shane Holder

unread,
May 6, 2015, 3:11:06 PM5/6/15
to masstrans...@googlegroups.com
Turtles all the way down it is then, thank you so much Chris.

Shane

Travis Smith

unread,
May 6, 2015, 3:19:55 PM5/6/15
to masstrans...@googlegroups.com
Shane, the major thought to keep in mind is that a message is an immutable contract; behaviour must exist elsewhere & interfaces are behaviour free to enforce that. I've deployed apps where behaviour has snuck into the messages and it always end up biting us somewhere in a really subtle way. 

-Travis

--
You received this message because you are subscribed to the Google Groups "masstransit-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to masstransit-dis...@googlegroups.com.
To post to this group, send email to masstrans...@googlegroups.com.

Chris Patterson

unread,
May 6, 2015, 3:21:55 PM5/6/15
to masstrans...@googlegroups.com
Yeah, it's usually right on the ass. At 4am. On a Sunday. Over a holiday weekend.
Reply all
Reply to author
Forward
0 new messages