Patterns for implementing message-oriented systems
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


Build status NuGet

Messaging.Patterns is a library that contains patterns for implementing message-oriented systems. The patterns are implemetations from Messaging.Primitives


A Bus is an simple implementation of IBus. This class currently facilitates chaining message handlers or or consumers (implementations of IConsumer. This bus provides the ability to automatically find and chain together handlers by providing a directory, wildcard and namespace specifier with the AddHandlersAndTranslators extension method. A handler is an IConsumer implementation and a translator is an IPipe implementation and IPipes are also consumers. As pipes are encountered they are connected to consumers of the pipes outgoing type. So, when the bus is given a message to handle, the message is broadcast to all consumers; much like a publish-subscribe channel. If a consumer is a pipe, the pipe processes the message then sends it to another consumer. If there is only one consumer of the message type to be handled by the bus, it will not broadcast but send to the one and only handler; like a point-to-point channel.


From Primitives, IConsumer<TMessage> provides an interface to implement and pass-around message handlers. But sometimes creating a new type to implement IConsumer</TMessage> may not make any sense. ActionConsumer<TMessage> is an implementation that lets you pass in a delegate or anonymous method that will handle the message. For example, if you had a MoveClientCommand message that you needed to handle, you could add a handler to a bus like this:

    bus.AddHandler(new ActionConsumer<MoveClientCommand>(message => {
        var client = clientRepository.Get(message.ClientId);

ActionPipe<TMessageIn, TMessageOut>

Along the same vane as ActionConsumer<TMessage>, from Primitives, IPipe<TMessageIn, TMessageOut> provides an interface to implement and pass around a message translator or pipe. Sometimes creating a new type to implement IPipe<TMessageIn, TMessageOut> is not the right thing to do. ActionPipe<TMessageIn, TMessageOut> provides an IPipe<TMessageIn, TMessageOut> implementation where a translation method or anonymous method can be provided to perform the translation. For example:

    bus.AddTranslator(new ActionPipe<MoveClientCommand,
        ChangeClientAddressCommand>(m=>new ChangeClientAddressCommand
                CorrelationId = m.CorrelationId,
                NewAddress = m.NewAddress