In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article will explain in detail the example analysis of the delay mechanism in rabbitMq. Xiaobian thinks it is quite practical, so share it with you as a reference. I hope you can gain something after reading this article.
1: TTL mechanism
TTL mechanism is actually to set expiration time for queues or messages, because middleware capacity and accumulation capacity are limited, some messages can not be consumed for a long time, you can use expiration to delete. The usage is as follows:
With the Queue property set, all messages in the queue have the same expiration time-in milliseconds.
The message itself is set individually, and the TTL of each message can be different.
** II: Dead letter queue **
Dead letter queue is used to store messages that cannot be consumed normally in ordinary queues, such as timeout, rejection, return nack, etc.
A normal queue bound to a dead letter switch is a dead letter queue; a dead letter switch is also a normal switch, but in other queue declaration attributes, there is an attribute called x-dead-letter-exchange, and the switch specified by its value becomes a dead letter switch. Details are as shown in the figure:
When the message expires, it will be sent to the switch according to the specified routingKey, and finally routed to the dead letter queue according to the binding key.
III: Application scenarios
What can we do after understanding TTL and Deadline above? For example, in e-commerce system, users need to pay after placing an order. The payment time is 15 minutes. After timeout, the unpaid order is changed to cancelled. What should I do?
Practice 1: Use the timed task to continuously scan the unpaid orders in the database to see if the creation time and the current time are greater than 15 minutes, and if so, change to cancelled.
Here's the problem: if the order table is large, frequent scans can cause performance problems. If not frequently enough, the error will be large and the status will not be updated in time.
Practice 2: For example, TTL and dead letter queue, send a message to mq after generating the order (do not consume it), set the expiration time of 15 minutes, send it to the dead letter queue after 15 minutes, listen to the consumer end of the dead letter queue after receiving the message, inquire about the order, if it is still not paid, it will be changed to cancelled.
IV: Delayed queue
Delay queue is actually a variant of TTL and dead message queue, but the above is to store messages in the queue to achieve expiration. Delay queue is based on the plug-in rabbitmq_delayed_message_exchange, which sends messages to the x-delayed-message exchange delay switch first, and then sends them to the queue after the time.
This plug-in needs to be downloaded, usage is not described here.
About "rabbitMq delay mechanism example analysis" This article is shared here, I hope the above content can be of some help to everyone, so that you can learn more knowledge, if you think the article is good, please share it to let more people see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 249
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.