Question

I am trying to implement a proof of concept service bus using MassTransit. I have three applications which need to communicate changes of a common entity type between each other. So when the user updates the entity in one application, the other two are notified.

Each application is configured as follows with their own queue:

bus = ServiceBusFactory.New(sbc =>
    {
        sbc.UseMsmq();
        sbc.VerifyMsmqConfiguration();
        sbc.ReceiveFrom("msmq://localhost/app1_queue");
        sbc.UseSubscriptionService("msmq://localhost/subscription");
        sbc.UseControlBus();

        sbc.Subscribe(subs =>
        {
            subs.Handler<IMessage1>(IMessage1_Received);
        });
    });

There is also a subscription service application configured as follows:

subscriptionBus = ServiceBusFactory.New(sbc =>
    {
        sbc.UseMsmq();
        sbc.VerifyMsmqConfiguration();
        sbc.ReceiveFrom("msmq://localhost/subscription");
    });

var subscriptionSagas = new InMemorySagaRepository<SubscriptionSaga>();
var subscriptionClientSagas = new InMemorySagaRepository<SubscriptionClientSaga>();
subscriptionService = new SubscriptionService(subscriptionBus, subscriptionSagas, subscriptionClientSagas);

subscriptionService.Start();

The problem is that when one of the applications publishes a message, all three applications receive it (including the original sender).

Is there any way to avoid this (without resorting to adding the application name to the message)?

Thanks,

G

Was it helpful?

Solution

So MassTransit is a pub/sub system. If you publish a message, everyone registered to receive it will. If you need only some endpoints to receive it, then you really need to directly send. It's just how this works.

You could include the source in your message and discard messages that aren't of interest to you. If you implement the Consumes.Accept interface, I think the Accept method would allow you to do so easily without mixing that into the normal consumption code.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top