Method for realizing timing task with rabbitmq delay queue
scene
Timed tasks are often used in development. For shopping malls, there are many timed tasks, such as timed expiration of coupons, timed closing of orders, closing of orders after 2 hours of wechat payment, etc. timed tasks are needed, but the timed tasks themselves have a problem, Generally speaking, we use regular polling to query the database to determine whether there are tasks to be executed, that is, anyway, we need to query the database first, and some tasks require high time accuracy and need to be queried once a second. It doesn't matter if the system is small. If the system itself is large and there are many data, This is unrealistic, so other methods are needed. Of course, there are many ways to implement it, such as redis implementing timing queue, JDK delay queue based on priority queue, time wheel, etc. Because rabbitmq is used in our project, based on the principle of convenient development and maintenance, we use rabbitmq delay queue to implement scheduled tasks. If you don't know what rabbitmq is and how spring boot integrates rabbitmq, you can see my previous article spring boot integrates rabbitmq