Skip to content

A distributed broadcast/subscribe event framework based on BearBones-Messaging

License

Notifications You must be signed in to change notification settings

i-e-b/SevenDigital.Messaging

Repository files navigation

SevenDigital.Messaging

A distributed contracts-based sender/handler messaging system built on RabbitMQ and BearBones-Messaging

Installation

Windows

Linux

  • As Windows, or use your distro's package manager to get RabbitMQ (you should get Erlang automatically)
    • (example, for Ubuntu: sudo apt-get install rabbitmq-server)

To check your installation is working, try the SimpleSample console app included

Getting Started: Path of least resistance

Configure messaging:

MessagingSystem.Configure.WithDefaults();

Define a message:

// Message contract (defined in both sender and receiver)
public interface IExampleMessage : IMessage {
	string Hello {get;set;}
}

// A specific instance (only needs to be defined in sender)
class MyExample : IExampleMessage {
	public string Hello {get;set;}
}

Setup a message handler:

public class MyHandler : IHandle<IExampleMessage> {
	public void Handle(IExampleMessage msg) {
		Console.WriteLine("Hello, "+msg.Hello);
	}
}

Register handler with listener:

// Spawns sets of background threads to handle incoming messages
using (MessagingSystem.Receiver().Listen(_=>_.Handle<IExampleMessage>().With<MyHandler>())) {
	while (true) {Thread.Sleep(1000);}
}
MessagingSystem.Control.Shutdown();

Register for load balanced: (if the named queue doesn't exist, it will be created automatically)

using (MessagingSystem.Receiver()
		.TakeFrom("MessageQueueName", _=>_
		.Handle<IExampleMessage>().With<MyHandler>())) {
.
.
.

Send some messages:

MessagingSystem.Sender().SendMessage(new MyExample{Hello = "World"});

Notes

  • Messaging.Receiver() to get a new IReceiver instance (this uses StructureMap under the hood)
  • Creating listener nodes takes time and resources. Do it infrequently -- usually once at the start of your app.
  • Your handler will get new()'d for every message. Don't do anything complex in the handler constructor!
  • To listen to messages, factory.Listener(binder=>binder.Handle<IMyMessageInterface>().With<MyHandlerType>()
  • Each listener can handle any number of message => handler pairs, and a message can have more than one handler (they all fire in parallel)

See further simple examples in the Integration Tests.

About

A distributed broadcast/subscribe event framework based on BearBones-Messaging

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages