Home  >  Article  >  Backend Development  >  How does Rabbitmq know whether the consumer execution is successful.

How does Rabbitmq know whether the consumer execution is successful.

WBOY
WBOYOriginal
2016-09-12 17:44:441917browse

Scenario: Place an order and deduct inventory.
My idea is to put the tasks of placing orders in the queue and process them one by one, so that there will be no mistakes when the inventory is deducted.
It is the producer and consumer
When the user clicks "Submit Order" in the UI, he puts the task in the queue, waits for the queue to process the result of the task, and jumps to the page based on the result (success or failure)

But there is a question: after the queue is processed, how to notify the producer of the result?
Take RabbitMQ as an example, can anyone provide the code?

Reply content:

Scenario: Place an order and deduct inventory.
My idea is to put the order tasks in the queue and process them one by one, so that there will be no mistakes when the inventory is deducted.
It is the producer and consumer
When the user clicks "Submit Order" in the UI, he puts the task in the queue, waits for the queue to process the result of the task, and jumps to the page based on the result (success or failure)

But there is a question: after the queue is processed, how to notify the producer of the result?
Take RabbitMQ as an example, can anyone provide the code?

quene can only guarantee whether the message arrives or not, specifically whether your business is executed successfully. This message queue is not guaranteed.

After the producer publishes the message, it listens to another return message queue, such as queue b.
After the consumer finishes consumption, he pushes the result message into queue b.
This way the original producer can get the returned results.

The mechanism for implementing RPC in RabbitMQ is:

  • When the client sends a request (message), it sets two values ​​replyTo (a Queue name, used for Tell the server to send the message notifying me to this Queue after the processing is completed) and correlationId (the identification number of this request. The server needs to return this attribute after the processing is completed. The client will know which request was successfully executed based on this ID. or execution failure)

  • The server receives the message and processes it

  • After the server processes the message, it will generate a response message to the Queue specified by replyTo, with the correlationId attribute

  • The client has previously subscribed to the Queue specified by replyTo. After receiving the response message from the server, it analyzes which request was executed based on the correlationId attribute, and performs subsequent business processing based on the execution results

It is pointed out that the producer will listen to another replyTo queue and obtain the corresponding response message to trigger subsequent operations.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn