AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |
Back to Blog
Masstransit consumer get headers3/9/2023 ![]() In addition to messageType, the message contains information about the host to which it was sent: "urn:message:PlayWithMassTransit30.Extension:SendSmsCommand", In this case, the generated message will contain the following value in the messageType field (on the basis of which, after receiving the message, the responsible consumer is then selected): For example, I added for the ISendSms command inheritance from ICommand and the generic type: The function GetUrnForType (Type type) is responsible for its formation (urn: message :) headers). Speaking about the format of the message, I would like to dwell on the name (or messageType). That names for the last exchange and queue are generated automatically, and upon completion of work they will be deleted: If the configuration is carried out without specifying a queue:Ĭfg.ReceiveEndpoint(host, e=> e.LoadFrom(container)) The final message path, the type of which implements ISmsEvent, will look like this: Then in the bindings of exchange messages you can see the following picture: In the case that, when configuring receive endpoint, we indicate the name of the queue:Ĭfg.ReceiveEndpoint(host, "play_with_masstransit_queue", e => e.LoadFrom(container)) ![]() In the image you can see the exchanges created as part of my script: ![]() Similar actions at the send endpoint 's configuration stage are performed for commands that also require their own exchanges to send. When the receive endpoint is configured (connecting previously registered consumers), if RabbitMq is used as the delivery channel for messages, the names of the required exchanges are formed on the basis of the message types indicated for processing by the consumers, in which these messages will then be placed. In other words, when running n-consumers (from the English consumer - consumer, handler) processing a command, after its publication only one of them will receive a message about it, while everyone will receive a message about the event.Īccording to MassTransit documentation, when declaring message contracts, it is recommended to resort to interfaces:Įvents are dispatched using the Publish method.īoth the distribution of messages on exchange and the choice of consumers (they will be discussed later in this article) for processing are based on the runtime types of these messages - the namespace and type name are used in the name, in the case of generic, the name of the parent type and a list of arguments. While the event is focused on notifying n-subscribers, each of which reacts to the event in its own way. The main difference between these types of messages is also included in the terminology - the command is delivered to a single executor (in order to avoid duplication of execution): Work with events is carried out using the Publish method ( IPublishEndpoint interface ). They signal an event that may be of interest to a certain set of subscribers (Observer pattern) who respond to these events, for example: ConnectionEstimated, CallTerminated, SmsSent, CustomerNotified. Var endpoint = await busControl.GetSendEndpoint(AppSettings.CommandEndpoint) Private static async Task SendSmsCommand(IBus busControl) Work with commands is carried out using the Send method ( ISendEndpoint interface ) and specifying the endpoint recipient (queue): For the most meaningful name of the team, it is desirable to use the structure of the verb + noun:ĮstimateConnection, SendSms, Notif圜ustomerOrderProcessed. They signal the need to perform some action. The library has 2 main types of messages: commands and events. The message broker can be RabbitMq, Azure Service Bus or In-Memory manager (in the case of In-Memory, the scope is limited to the process in which the instance is initialized). NET platform that simplifies working with the data bus, which is used to build distributed applications and implement SOA (service oriented architecture). MassTransit is an open source library developed in C # for the.
0 Comments
Read More
Leave a Reply. |