這篇文章主要介紹“怎么理解rabbitmq死信隊(duì)列,延遲隊(duì)列,優(yōu)先級(jí)隊(duì)列”,在日常操作中,相信很多人在怎么理解rabbitmq死信隊(duì)列,延遲隊(duì)列,優(yōu)先級(jí)隊(duì)列問題上存在疑惑,小編查閱了各式資料,整理出簡(jiǎn)單好用的操作方法,希望對(duì)大家解答”怎么理解rabbitmq死信隊(duì)列,延遲隊(duì)列,優(yōu)先級(jí)隊(duì)列”的疑惑有所幫助!接下來,請(qǐng)跟著小編一起來學(xué)習(xí)吧!
我們提供的服務(wù)有:成都網(wǎng)站建設(shè)、做網(wǎng)站、微信公眾號(hào)開發(fā)、網(wǎng)站優(yōu)化、網(wǎng)站認(rèn)證、太谷ssl等。為上千余家企事業(yè)單位解決了網(wǎng)站和推廣的問題。提供周到的售前咨詢和貼心的售后服務(wù),是有科學(xué)管理、有技術(shù)的太谷網(wǎng)站制作公司
延遲隊(duì)列:死信隊(duì)列通過過期時(shí)間實(shí)現(xiàn)就是延遲隊(duì)列,消息發(fā)送到正常隊(duì)列,等待過期,等待rabbitmq將正常隊(duì)列中的消息投遞到死信隊(duì)列中,消費(fèi)自己消費(fèi)死信隊(duì)列
優(yōu)先級(jí)隊(duì)列:x-max-priority指定優(yōu)先級(jí)
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(); /** * 死信隊(duì)列出現(xiàn)原因 * 消息被拒絕 (Basic.Reject/Basic .Na ck) ,井且設(shè)置 requeue 參數(shù)為 alse; * 消息過期; * 隊(duì)列達(dá)到最大長(zhǎng)度。 */ //死信隊(duì)列 channel.exchangeDeclare("exchange.dlx" , "direct" , true); //正常隊(duì)列,先發(fā)送消息到正常隊(duì)列, channel.exchangeDeclare( "exchange.normal" , "fanout" , true); Mapmap = new HashMap ( ); //消息在正常隊(duì)列過期時(shí)間 map.put("x-message-ttl" , 10000);
//通過x-max-priority指定優(yōu)先級(jí)隊(duì)列 map.put("x-max-priority" ,10) ;
//關(guān)聯(lián)的死信隊(duì)列 map.put("x-dead-letter-exchange" , "exchange.dlx"); // 死信隊(duì)列路由key map.put("x-dead-letter-routing-key" , "routingkey"); //正常隊(duì)列綁定exchange channel.queueDeclare("queue.norma1" ,true ,false,false, map); channel.queueBind("queue.norma1" , "exchange.normal" , ""); // 死信隊(duì)列綁定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()) ; } }
管理端展示效果:
等待時(shí)間過期后:
到此,關(guān)于“怎么理解rabbitmq死信隊(duì)列,延遲隊(duì)列,優(yōu)先級(jí)隊(duì)列”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實(shí)踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識(shí),請(qǐng)繼續(xù)關(guān)注創(chuàng)新互聯(lián)網(wǎng)站,小編會(huì)繼續(xù)努力為大家?guī)砀鄬?shí)用的文章!