How to connect à mass transit consumer to an exchange created by a different application

Viewed 464

I'm using Masstransit with RabbitMq to communicate between two web applications .net core. In the publisher application I publish a message to an exchange 'producer'.

rabbitConfigurator.Message<TMessage>(x => x.SetEntityName("producer"));

In the same application I have a consumer-A of said messages and that works fine (the consumer has an exchange and a queue as recommended by rabbit/masstransit connected to the producer exchange)

rabbitConfigurator.ReceiveEndpoint("consumer-A", x =>
            {
                x.Consumer<TConsumer>(context);
                x.Bind("producer");
            });

In a second application I'm trying to setup another consumer-B of the same message type connected to the exchange 'producer'.

rabbitConfigurator.ReceiveEndpoint("consumer-B", x =>
                {
                    x.Consumer<TConsumer>(context);
                    x.Bind("producer");
                });

However messages destined for this second application are getting sent to a skipped queue. From what I can see this second consumer is correctly configured in RabbitMq though.

I can't see what I'm missing.

Edit: In the producing application I can also successfully receive messages in a second consumer. But from another web application it doesn't work - perhaps something to do with the fact that there's a differetn connection/channel ?

1 Answers

Messages sent to the producer exchange should be in a format that can be deserialized by MassTransit. If they aren't, you'll need to add a message deserializer which can support the message type. If it is application/json then you'll need to add the RawJsonMessageDeserializer to the receive endpoint.

If the messages are in the correct format, verify that you have a consumer on the receive endpoint that can consume that message type. Message types must match entirely, including namespace, to be consumed. More details are available in the documentation.

Related