Masstransit: Possibly incorrect behavior of `Send` method

Created on 5 Jul 2017  路  4Comments  路  Source: MassTransit/MassTransit

Hello.
I'm trying to configure MassTransit to throw an error if there is no suitable queue for consuming the message.

As I see in this comment by @alexeyzimarev the correct way to achieve this is by using Send method instead of Publish.

But the only difference I see between Send and Publish methods is names of queues to push message.

Both deprecated and latest documentation doesn't explain this aspect.

Also I see that I can set Mandatory flag on PublishContext when using Publish method, but I can't find the way to configure such behavior globally.

Can you please explain me how to configure & use MassTransit to implement desired behaviour?

Most helpful comment

If you set Mandatory on Send or Publish, it will throw an exception (for RabbitMQ) if there are no exchange bindings.

If you want Send to create the queue for you, I think you can add &bindQueue=true to the endpoint address.

All 4 comments

My comment was incorrect. It is mentioned below in the thread that messages are sent to the exchange. If there is no consumer for that message - there will be no binding, so the message will disappear. I am not aware of any way to ensure that there is a consumer for your message at the moment you use Send.

The difference between Send and Publish is fundamental and described by @maldworth in details here https://www.maldworth.com/2015/10/27/masstransit-send-vs-publish/

If you set Mandatory on Send or Publish, it will throw an exception (for RabbitMQ) if there are no exchange bindings.

If you want Send to create the queue for you, I think you can add &bindQueue=true to the endpoint address.

@phatboyg, thank you for answer.
As I see, Mandatory flag implemented only in PublishContext but not in SendContext.
Is this a bug?
Also, can you give me any idea how to configure Mandatory flag for all Send commands globally?

Looks like I found the correct answer to my question.

The way to do this is implementing class inherited from IPipeSpecification<SendContext> and register it via IRabbitMqBusFactoryConfigurator.ConfigureSend.

This section from the docs can help.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ghd258 picture ghd258  路  6Comments

akaFalsh picture akaFalsh  路  3Comments

ffMathy picture ffMathy  路  3Comments

nkot picture nkot  路  5Comments

slaneyrw picture slaneyrw  路  6Comments