
Thus, When the requester initiates a message ( event ) To RabbitMQ, After listening and processing, the response side returns the processing result to RabbitMQ, The requester continues to execute subsequent requests according to the response result. Var response = await _client.GetResponse(new ") Public OrderController(IRequestClient client) Public class OrderController : ControllerBase x.AddRequestClient(new Uri(GetServiceAddress("events-checkorderstatus"))) Īdd one more Controller And Action, To request and obtain processing results (OrderStatusResult). Stay Startup Add a new one to send messages (CheckOrderStatus) Request client and specify message queue name ( Create a separate queue for each message ). On a publish subscribe basis, Change your old habits, When a message is released, Waiting for the subscriber to process, And push the message back to RabbitMQ, The sender receives the processed message and continues to execute. In this way, adopt Postman Send a request, Send a message to RabbitMQ, Subscribers listen for messages, Process the message, Everything is familiar.

Ĭfg.Host(Configuration, ushort.Parse(Configuration), Configuration, h =>
#Masstransit handler password
Yes RabbitMQ Connection address port for 、 Virtual host 、 Access account password and other series configuration.Stay Startup add MassTransit Required services and initialization configuration. īased on the need to build two WebApi Program, Used to simulate senders and subscribers, Among them RabbitMQ It's pre built, You can only refer to the package configuration in the program. This kind of scene is very common, Send a message ( Or event ) Go to the message queue, There are one or more subscribers to the expected message reception processing. Official website address : Publish subscribe mode

Message based communication is a reliable and scalable way to implement a service-oriented architecture. MassTransit Provides a wide range of capabilities over existing messaging, So that developers can use message based session mode to connect services asynchronously. It is convenient to build applications and services of loosely coupled asynchronous communication based on message. Net frame, For creating distributed applications. MassTransit It's a freedom 、 Open source 、 The lightweight message bus is based on.
