Nathan C
Nathan C

Reputation: 205

Can MassTransit's In-Memory bus work across processes?

I am experimenting with MassTransit's In-Memory bus, and I tried modifying the sample given by Loosely Couple Labs Publish/Subscribe Example to go from using RabbitMQ to the In-Memory bus. However, the subscriber doesn't seem to receive the message.

I am using version 3.1.2 of MassTransit.

In the Publisher I changed the bus creation from:

var bus = Bus.Factory.CreateUsingRabbitMq(x => x.Host(new Uri("rabbitmq://localhost/"), h => { }));

to:

var bus = Bus.Factory.CreateUsingInMemory(x => { });

In the Subscriber I changed the bus creation from:

var bus = Bus.Factory.CreateUsingRabbitMq(x =>
    {
        var host = x.Host(new Uri("rabbitmq://localhost/"), h => { });
        x.ReceiveEndpoint(host,
                          "MtPubSubExample_TestSubscriber",
                          e => e.Consumer<SomethingHappenedConsumer>());
    });

to:

var bus = Bus.Factory.CreateUsingInMemory(x => x.ReceiveEndpoint("myQueue",
                                                                 e => e.Consumer<SomethingHappenedConsumer>()));

When I ran this code, the messages did not get received by the subscriber console app. Since I am able to get a loopback to work within the same process, this makes me believe that the In-Memory bus won't work across processes. Is that correct, or is there a way to get the In-Memory bus to communicate between different processes on the same machine?

Upvotes: 0

Views: 3408

Answers (1)

Chris Patterson
Chris Patterson

Reputation: 33278

The in-memory transport is designed for use within a single process only. It is not possible to use the in-memory transport to communicate between multiple processes (even if they are on the same machine).

It is, however, possible to share the same in-memory transport with multiple bus instances within the same process by configuring the transport provider. This is done in many of the unit tests, to verify behavior across bus instances.

return MassTransit.Bus.Factory.CreateUsingInMemory(x =>
{
    _inMemoryTransportCache = new InMemoryTransportCache(Environment.ProcessorCount);

    x.SetTransportProvider(_inMemoryTransportCache);

    x.ReceiveEndpoint("input_queue", configurator =>
    {
        configurator.Handler<MyMessage>(context => {});
    });
});

The InMemoryTransportCache can be saved and passed to multiple bus instances. Again, this is all within the same process.

UPDATE

This capability was deprecated a long time ago and is not available in current version of MassTransit.

Upvotes: 5

Related Questions