Sending a message to a queue on different Host in Rebus

Viewed 107

In my setup I have two RabbitMQ servers that are used by different applications employing Rebus ESB. What I would like to know is if I can map a message to a queue on a different Host the way I can with MassTransit.

I also would like to know if I can send messages in a batch mode the same way with MassTransit. Thanks In Advance.

1 Answers

In my setup I have two RabbitMQ servers that are used by different applications employing Rebus ESB. What I would like to know is if I can map a message to a queue on a different Host the way I can with MassTransit.

I am not sure how this works with MassTransit, but I'm pretty sure it's not readily possible with Rebus.

With Rebus, you're encouraged to treat this as you would any other integration scenario, where you'd put a ICanSendToOtherSystem in your IoC container, which just happens to be implemented by CanSendToOtherSystemUsingRebus. Your CanSendToOtherSystemUsingRebus class would probably look somewhat like this:

public class CanSendToOtherSystemUsingRebus : ICanSendToOtherSystem, IDisposable
{
    readonly IBus _bus;

    public CanSendToOtherSystemUsingRebus(string connectionString)
    {
        _bus = Configure.With(new BuiltinHandlerActivator())
            .Transport(t => t.UseRabbitMqAsOneWayClient(connectionString))
            .Start();
    }

    public Task Send(object message) => _bus.Send(message);

    public void Dispose() => _bus.Dispose();
}

(i.e. just something that wraps a one-way client that can connect to that other RabbitMQ host, registered as a SINGLETON in the container)

I also would like to know if I can send messages in a batch mode the same way with MassTransit. Thanks In Advance.

Don't know how this works with MassTransit, but with Rebus, you can give the transport more convenient circumstances for optimizing the send operation(s) by using scopes:

using var scope = new RebusTransactionScope();

foreach (var message in lotsOfMessages) 
{
    // scope is automagically detected
    await bus.Send(message);
}

await scope.CompleteAsync();

which will improve the rate with which you can send/publish with most transports. Just remember that the scope results in queuing up messages in memory before actually sending them, so you'll probably not want to send millions of messages in each batch.

I hope that answered your questions

Related