Package | Version | Description |
---|---|---|
Pri.Messaging.Primitives |
A small, independent and decoupled, class library to contain message-oriented abstractions. For the most part this library will only contain interfaces but may contain base classes in the future | |
Pri.Messaging.Patterns |
A library that contains patterns for implementing message-oriented systems. The patterns are implementations from Pri.Messaging.Primitives . |
Mostly a marker interface, but does contain a string CorrelationId
property. This interface provides a message abstraction for other interfaces/implementations.
A marker interface to provide an event abstraction. An event is a type of message; but a unique event abstraction allows messages and events to be handled separately. An event is the representation of a immutable fact that describes something that occurred in the past.
A marker interface that provides an abstraction of a command message specific to requesting a change in state, i.e. the execution of a command.
A generic interface that provides an abstraction for something that consumes or handles a message. IConsumer
has a Handle
method to consume a messuage derived from IMessage
and has the signature void Handle<T>(T message)
A generic interface that provides an abstraction for something that produces a message. IProducer
has a AttachConsumer
method to attach something that implements a IConsumer
so that the producer and send the messages that are produced to the consumer. This interface promotes the idea that messages are asynchronous and aren't singular. The AttachConsumer
method allows consumers to consume any number of messages that the producer will produce in the future.
A convenient marker interface for something that is both a consumer and a producer, a pipe (or filter). It implements both IConsumer
and IProducer
and able to consume a message of one type and produce a method of another type.
A abstraction for a bus that when implemented would facilitate a decoupled architecture whose responsibility is to facilitate the connection of producers and consumers.
For a more in-depth introduction to Primitives, please see http://blog.peterritchie.com/Introduction-to-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 Pri.Messaging.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);
client.ChangeAddress(message.NewAddress);
}));
Along the same vane as ActionConsumer<TMessage>
, from Pri.Messaging.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
}
));