We are using the rabbitmq:3-management image from DockerHub which will provide us with a UI, available on port 15672. Given that Docker is installed, we’ll open a command-line terminal and use the docker run command to spin up our server:ĭocker run -d -hostname my-rabbitmq-server -name rabbitmq -p 5672:5672 -p 15672:15672 rabbitmq:3-management Installing RabbitMQīefore we start creating our application, we will first need to spin up a RabbitMQ server, by making use of Docker. Implementing MassTransit With RabbitMQ in ASP.NET Core Now that we have an understanding of what MassTransit is and why we would use it, let’s see how we can use it along with RabbitMQ in ASP.NET Core. MassTransit handles all of this for us, along with many other features such as exception handling, distributed transactions, and monitoring. This allows us to work with something such as the InMemory transport when working locally, then when deploying our code, use another transport such as Azure Service Bus or Amazon Simple Queue Service.Īdditionally, when we work with a message-based architecture, there are a lot of specific patterns we need to be aware of and implement, such as retry, circuit breaker, outbox to name a few. Firstly, by abstracting the underlying message broker logic, we can work with multiple message brokers, without having to completely rewrite our code. There are a few benefits to choosing to use a library such as MassTransit, instead of working with the native message broker library. Events are published to one or multiple consumers and will be expressed using noun-verb (past tense) sequence. These message types are sent to an endpoint (queue) and will be expressed using a verb-noun sequence.Įvents are another message type, signifying that something has happened. NET class or interface.Ĭommand is a type of message, specifically used to tell a service to do something. Message is a contract, defined code first by creating a. NET/C# content and get paid? > JOIN US! << Wanna join Code Maze Team, help us produce more awesome. It will just broadcast all the messages it receives to all the queues that have created a binding with it. We can define exchanges from one of the following types:įor this article, we will focus on the Fanout type, as that is what MassTransit uses by default. We must create a binding, which will ensure our messages get sent from our exchange to one or many queues. But what if we want to selectively send messages to different queues based on metadata found in the message? This is where exchanges come into play.Īn exchange receives messages from producers, and depending on its configuration, will send the message to one or many queues. When a producer sends directly to a queue, this message will be received by all consumers of that queue. When working with RabbitMQ, producers can send messages to a couple of different endpoints:Īs we have covered queues in the previous article, we are going to focus just on exchanges.
0 Comments
Leave a Reply. |