Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to understand rabbitmq dead letter queue, delay queue, priority queue

Shulou Source: shulou.com Published: 2022-06-01 23:16:09 10月01日 Update

This article mainly introduces "how to understand rabbitmq dead letter queue, delay queue, priority queue". In daily operation, I believe many people have doubts about how to understand rabbitmq dead letter queue, delay queue and priority queue. Xiaobian consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the questions of "how to understand rabbitmq Dead letter queue, delay queue, priority queue". Next, please follow the editor to study!

Delay queue: a dead letter queue is a delay queue through expiration time. Messages are sent to normal queues, waiting for expiration, waiting for rabbitmq to deliver messages from normal queues to dead letter queues, and consuming dead letter queues by consumers themselves.

Priority queue: x-max-priority specifies priority

Package com.rabbitmq.demo;import com.rabbitmq.client.*;import java.util.HashMap;import java.util.Map;public class TtlProduce {public static void main (String args []) throws Exception {ConnectionFactory connectionFactory=new ConnectionFactory (); connectionFactory.setPassword ("guest"); connectionFactory.setPassword ("guest"); connectionFactory.setHost ("192.168.1.141"); connectionFactory.setPort (5672); Connection connection=connectionFactory.newConnection () Channel channel= connection.createChannel (); / * * cause of dead letter queue * message is rejected (Basic.Reject/Basic .Na ck), and set requeue parameter to alse; * message expires; * queue reaches maximum length. * / / Dead letter queue channel.exchangeDeclare ("exchange.dlx", "direct", true); / / normal queue, send messages to normal queue first, channel.exchangeDeclare ("exchange.normal", "fanout", true); Map map = new HashMap () / the message expires in the normal queue map.put ("x-message-ttl", 10000); / / specifies the priority queue map.put ("x-max-priority", 10) through x-max-priority; / / the associated dead letter queue map.put ("x-dead-letter-exchange", "exchange.dlx") / / Dead letter queue routing key map.put ("x-dead-letter-routing-key", "routingkey"); / / normal queue binding exchange channel.queueDeclare ("queue.norma1", true, false,false, map); channel.queueBind ("queue.norma1", "exchange.normal", "") / / Dead letter queue binds exchang channel.queueDeclare ("queue.d1x", true, false, false, null); channel.queueBind ("queue.d1x", "exchange.dlx", "routingkey"); channel.basicPublish ("exchange.normal", "rk", MessageProperties.PERSISTENT_TEXT_PLAIN, "dlx" .getBytes ());}}

The display effect of the management end:

After the waiting time expires:

At this point, the study on "how to understand rabbitmq dead letter queue, delay queue, priority queue" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Tags: Queue dead letter priority delay message learning time more help consumption utility maximum next reason parameter that is effect article method theory Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information vpn Xiaomi Redmi Huawei