Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mastransit - publish vs send and how to manage message

I have just used MassTransit in my project, .Net core2.0. It is great but there are some concerns:

  • That is different between Publish vs Send. In my scenario, I have one email service to send email to out side. Other services will pass request to email service via RabbitMQ. So, in this case we should use "Publish" or "Send".

  • With Send, we need to pass the full URL of endpoint. There is any best practice to manage endpoint? Because if we have 10 commands, we need to manage 10 endpoints. Is it right?

  • Relate to event(Publish), if one service is deployed on multiple instances, when one event is published to queue. It will be processed one time or will be processed many times on each instance.

  • Could you please share me one unit test for consumer? Because with harness test, it seems we just ensure message was queued.

  • Masstransit is ready for .Net Core 2.1?

Many thanks,

like image 366
Jacky Phuong Avatar asked Jul 22 '18 15:07

Jacky Phuong


1 Answers

There are way too many questions for one post tbh, on SO it is better to ask more specific questions, one by one. Some of your questions already have answers on SO.

The difference between publishing events and sending commands is similar to what you expect. We actually cover some of it in the documentation.

You can handle as many message types as you want in one receive endpoint, but you need to be aware of the consequences. The best practice is to have one endpoint per command type or at least one endpoint for related commands. The risk here is that an important command might get stuck waiting in the queue until other, less important commands will be processed.

If you publish events, each endpoint (queue) will get a copy of it. If you have several instances of one endpoint, only one of those instances will get it. It is valid also for sending commands, but it will be only one endpoint that gets a message and only one of the instances will process it.

Although there is no documentation for MT testing just yet, you can look at this test to see how it is done.

MassTransit is compiled for .NET 4.6 and .NET Standard 2.0. There is nothing specifically different in .NET Core 2.1 that would have any effect on MassTransit.

like image 144
Alexey Zimarev Avatar answered Nov 26 '22 15:11

Alexey Zimarev