This repository was archived by the owner on Nov 2, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Create Command Bus
Tyler Brinks edited this page Jan 28, 2014
·
4 revisions
Creating a SeekU Command Bus
Creating a SeekU command bus is as simple as implementing an interface.
The required interface is SeekU.Commanding.ICommandBus
That interface has a single, generic method "Send."
The Send method is generic and expects a single generic argument where the argument is of type SeekU.Commanding.ICommand.
Here's the full method signature:
void Send<T>(T command) where T : ICommand;
In order to create event the most complex implementation, all that is necessary is to take a command object instance and send it to the appropriate command handler. This is true even in complex scenarios like using NServiceBus.
For example, you might use RabbitMQ as your command bus:
public class RabbitMQCommandBus : ICommandBus
{
void Send<T>(T command) where T : ICommand
{
var factory = new ConnectionFactory() { HostName = "localhost" };
using (var connection = factory.CreateConnection())
using (var channel = connection.CreateModel())
{
channel.QueueDeclare("hello", false, false, false, null);
// serialize your command however you prefer
var body = {SomeSerializer}.Serialize(command)
channel.BasicPublish("", "hello", null, body);
}
}
}