Duplex WCF “Service Bus”: Part 2

By | August 8, 2012

In part one, I discussed how I started down the road of creating a mini Service Bus for our system.

Using the existing framework from Juval Lowy, I added a service contract to the publish/subscribe WCF service that accepted a C# xml element XElement. This is the callback interface that the consumer will implement. When data is ready to be sent, the publisher will…Publish (imagine that) an XElement to the pub/sub service. The service will then look up everyone who is subscribed to this particular data and send the XElement to them.

public interface IXMLSubscription
[OperationContract(IsOneWay = true)]
void SubscriptionDataReady(XElement data, string dataname);

[ServiceContract(CallbackContract = typeof(IXMLSubscription))]
interface IXMLSubscriptionService : ISubscriptionService { }

The difference between Lowy’s implementation is the string dataname property of the SubscriptionDataReady() method. Instead of looking up subscriptions by method name, we just look them up by a data title: dataname. The dataname does not execute any code (as a normal WCF call would), it is just more or less a way to match up subscribers with the correct data.

So, on the publisher side, he would call: Publish(myXElementData, “MyCommonDataName”). The subscriber would subscribe to that data by calling: Subscribe(“MyCommonDataName”). Any published data that comes in with the name “MyCommonDataName” will get routed to every subscriber who has subscribed to “MyCommonDataName”.

In the next article, I’ll discuss how the subscription service uses datanames to figure out which subscribers to send to.

Leave a Reply

Your email address will not be published. Required fields are marked *