4

We are working towards an architecture like one below but we will have micro services on cloud and some on premises which will talk to each other using queue(s) and bus(es),

RabbitMQ implementation of an event bus

Now I am confused with where we should host MassTransit and RabbitMq, also should it be a ASP.NET Core project on its own ? if yes what I will be doing in it ? starting a bus ? creating queues ? I am not able to move forward with this

Yahya Hussein
  • 8,767
  • 15
  • 58
  • 114
Mathematics
  • 7,314
  • 25
  • 77
  • 152
  • Did you read the documentation? RabbitMQ is a message broker. It must be hosted on its own. MassTransit is a messaging framework. You host it in your application. MassTransit will create queues and exchanges for you when you start the bus. – Alexey Zimarev Nov 16 '17 at 14:09
  • @AlexeyZimarev yes, and also looking at sample projects but it's really confusing, it's not really oblivious how both components fits in a architecture like above, in samples they we are creating starting bus in same console app, and creating endpoints and sending messages, it seems to be against SOLID principles – Mathematics Nov 16 '17 at 15:28
  • Not sure which SOLID principles get violated there and I would also not expect Hello World-style apps to be written with Clean Code. If this all confuses you - take a look at any intro to any .NET messaging framework. NServiceBus has many materials. Pluralsight has intro courses about MassTransit and NServiceBus. Same principles apply to both messaging frameworks. – Alexey Zimarev Nov 16 '17 at 17:32

2 Answers2

3

The simple MassTransit examples are just that, the absolute simplest examples of interacting with queues.

  1. RabbitMQ is your message broker. It is hosted separately.
  2. MassTransit is a development framework that makes it much easier to interact with RabbitMQ (or Azure Service Bus) by abstracting away the implementation-specific "plumbing."
  3. You write any number of .NET services that either publish messages to a queue, or subscribe to queues.
Peter J
  • 57,680
  • 8
  • 38
  • 45
  • Thank you peter but this answer confuses me even more... https://stackoverflow.com/questions/45247678/why-is-it-not-recommended-to-host-receive-endpoints-in-a-web-application-using-m?rq=1 If I understood you correctly... RabbitMQ can go in a separate container, but bus needs to be started and stopped and host end points, would it be where rabbitmq is ? or bus will be start and stop from producers and consumers of bus ? many thanks for your help – Mathematics Nov 17 '17 at 09:00
  • The endpoints do not "start or stop" the bus, the endpoints simply manage "connecting" and "disconnecting" to a queue on RabbitMQ, and serializing those messages. That question you linked to simply references the technical implementations of making sure that "connection" and "disconnection" happens correctly, and what happens when an application restarts. – Peter J Nov 17 '17 at 17:45
2

We recently worked on something similar, the way we did it is:

RabbitMQ was hosted separately, and buses/queues creation and management were done from the services that use messaging.

For each service that receives messages you use Maastransit to create a queue because service will be receiving messages using this queue.

You will be using publish/subscribe way of messaging so as mentioned above, inside each service, create a queue with logical name and connect to RabbitMQ server address.

Services that represent senders will publish messages of a custom type you create, and services that represent receivers will subscribe to this type of messages by having a consumer for this type registered inside the bus created.

Hope it helps.

Yahya Hussein
  • 8,767
  • 15
  • 58
  • 114
  • Thank you, I have reached understanding of topology you described as well, I am now trying to make MassTransit V4 work on .net core 2 web api and it's a mission lol – Mathematics Nov 23 '17 at 07:43
  • 1
    great to know that, I remember that .net core was not fully supported by masstransit, so good luck :D – Yahya Hussein Nov 23 '17 at 07:45
  • Yes, it's in pre-release phase but been told it will work for the topology you suggested in your answer, however finding a tutorial or making it work is complex, this is because of confusion, .Net Core 2, MT old api vs new api etc.. etc.. – Mathematics Nov 23 '17 at 09:21
  • 2
    Hi, any news trying to make masstransit work with .net core 2? – Yahya Hussein Dec 05 '17 at 11:21
  • 1
    We are not doing too much fancy things, but it seems to work for us with the latest dev version :) – Mathematics Dec 05 '17 at 14:05
  • Great, thank you, will start using it then :) just to be sure, v4.0.0.1216-develop? – Yahya Hussein Dec 05 '17 at 15:51
  • 1
    No worries, I made it work with 4.0.0.1334-develop, if there's any problem please let me know :) – Mathematics Dec 06 '17 at 10:17
  • @Mathematics Do you have a repo of how you got it set up? Are you using .NET Core's DI? – kjbetz Dec 16 '17 at 13:44
  • @kjbetz I will try to create one and share, but sorry can't promise but will try as soon as possible – Mathematics Dec 18 '17 at 06:57