Mastransit - publish vs send and how to manage message
Asked Answered
A

1

9

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,

Amphetamine answered 22/7, 2018 at 15:44 Comment(1)
This Gist has some details that might be helpful: gist.github.com/maldworth/14c8850cbd5b24881fd7a97abb88a14dSensitive
C
6

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.

Cyclamen answered 22/7, 2018 at 17:57 Comment(1)
- Thanks, with your answer I understand that one service is deployed by many instances, only one of those instances can get message and process it. Because all of them is connecting to the same queue. - Relate to unit test, I checked this link before. But it seems we only check this message is sent. We don't run and test "consumer" code?Amphetamine

© 2022 - 2024 — McMap. All rights reserved.