Distributed Event Broker – Scoping, identification and serializers

In my last post I gave an introduction to the nuts and bolts of the distributed event broker. In this post we are going even deeper into some of the customization possibilities the distributed event broker offers. I want to cover the following topics: Scoping, identification and serializers.

The distributed event broker is a virtual compound of several event brokers in several processes eventually on different machines. For various reasons your application might have not just one event broker but multiple event brokers to separate different business domain events and components from each other. The distributed event broker takes this concept over process boundaries. The application of this concept is pretty simple and straight forward.

Scoping

The distributed event broker identification allows to bind several event brokers together. Only events fired in the same context are recognized from the event brokers participating in the context. That allows to have several distributed event brokers in one application. How does this look like in code (here with the NServiceBus adapter)?

// App A
// Setup event broker and extension for business domain "X"
var extensionX = new NServiceBusDistributedEventBrokerExtension("DistributedEventBrokerX", bus);
eventBrokerX.AddDistributedExtension(extensionX);

// Setup event broker and extension for business domain "Y"
var extensionY = new NServiceBusDistributedEventBrokerExtension("DistributedEventBrokerY", bus);
eventBrokerY.AddDistributedExtension(extensionY);

// App B
// Setup event broker and extension for business domain "X"
var extensionX = new NServiceBusDistributedEventBrokerExtension("DistributedEventBrokerX", bus);
eventBrokerX.AddDistributedExtension(extensionX);

// App C
// Setup event broker and extension for business domain "Y"
var extensionY = new NServiceBusDistributedEventBrokerExtension("DistributedEventBrokerY", bus);
eventBrokerY.AddDistributedExtension(extensionY);

Although eventBrokerX and eventBrokerY are running in the same process, events published and handled on the distributed event broker of the business domain “X” are not seen on the distributed event broker of the business domain “Y” and vice versa.

Identification

Each event broker can be identified by specifying an event broker identification. This information is just transmitted when an event is published without further impact on the distributed event broker. But it lets you distinguish from which location the event was coming from. The identification can be specified by using the following AddDistributedExtension overload:

eventBroker.AddDistributedExtension(extension, "ApplicationXGlobalEventBroker");

When using the extension method without specifying the event broker identification a new System.Guid is generated for each event broker.

// Will identify event broker by using System.Guid internally.
eventBroker.AddDistributedExtension(extension);

Serializers
If you want to use another or a custom serializer you have to inherit from DefaultDistributedFactory and override CreateEventArgsSerializer. By default the BinarySerializer is used. Be aware of the restrictions you bring upon your architecture depending on the chosen serializer.

    public class CustomDistributedFactory: DefaultDistributedFactory     {
        public override IEventArgsSerializer CreateEventArgsSerializer()
        {
            return new XmlEventArgsSerializer();
        }
    }

Use your custom distributed factory when instantiating the technology specific distributed event broker extension. The next upcoming post will cover custom messages, selection strategies and restrictions.

About the author

Daniel Marbach

1 comment

By Daniel Marbach

Recent Posts