How does Rabbitmq know whether the execution is successful by the consumer.

Source: Internet
Author: User
Scenario: place an order and deduct inventory. My idea is to put the order tasks in the queue for processing one by one, so that the inventory will not go wrong when the deduction is made. When the producer and consumer click "Submit Order" in the UI, put the task in the queue and wait until the queue completes the task... scenario: place an order and deduct inventory.
My idea is to put the order tasks in the queue for processing one by one, so that the inventory will not go wrong when the deduction is made.
Is the producer and consumer
When you click "Submit Order" in the UI, place the task in the queue, wait for the result of the queue to process the task, and jump to the page based on the result (success or failure)

But there is a problem: After the queue is processed, how do I notify the producer of the result?
Taking RabbitMQ as an example, which of the following experts can provide code.

Reply content:

Scenario: place an order and deduct inventory.
My idea is to put the order tasks in the queue for processing one by one, so that the inventory will not go wrong when the deduction is made.
Is the producer and consumer
When you click "Submit Order" in the UI, place the task in the queue, wait for the result of the queue to process the task, and jump to the page based on the result (success or failure)

But there is a problem: After the queue is processed, how do I notify the producer of the result?
Taking RabbitMQ as an example, which of the following experts can provide code.

queneOnly the arrival or failure of messages can be guaranteed. whether your business is successful or not. This message queue is not guaranteed.

The producer listens to another returned message queue after publishing a message, for example, queue B.
After the consumer completes consumption, the result message is pushed to queue B.
In this way, the original producer can obtain the returned results.

The RPC implementation mechanism in RabbitMQ is as follows:

  • When a client sends a request (message), properties in message 14 are defined in MessageProperties, which are sent along with the message) set two values: replyTo (a Queue name, used to tell the server to send the notification message to this Queue after processing is completed) and correlationId (ID of this request, after the server completes processing, it needs to return this attribute. the client will know which request has been successfully executed or failed to execute according to this id)

  • The server receives and processes the message.

  • After the server finishes processing the message, it will generate a response message to the specified Queue of replyTo, with the correlationId attribute

  • The client has subscribed to the Queue specified by replyTo. after receiving the server response message, it analyzes which request is executed based on the correlationId attribute and carries out subsequent business processing based on the execution result.

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.