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. We can define exchanges from one of the following types:Ĭommand is a type of message, specifically used to tell a service to do something. 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. Using a message broker allows us to build decoupling, performant applications, relying on asynchronous communication between our applications. To very briefly recap, RabbitMQ is a message broker, which handles the accepting, storing, and sending of messages between our applications. We will cover some of the more advanced features of RabbitMQ in this article, but for an introduction, we have a great article on the topic: How to Use RabbitMQ in ASP.NET Core.Īfter finishing this article, we expect you to have a good understanding of what MassTransit is, what benefits it provides, and how we can use it in conjunction with RabbitMQ. To download the source code for this article, you can visit our GitHub repository.įor this tutorial, we recommend that you have some knowledge of RabbitMQ.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |