Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

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

2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

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!

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: 0

*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.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report