rabbitmq進階

聲明備份交換機
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("alternate-exchange" , "myAe");//備份交換機名稱爲myAe
        channel.exchangeDeclare( "normalExchange" , "direct" , true , false , map);//聲明一個direct交換機
        channel.exchangeDeclare( "myAe" , "fanout" , true, false , null) ;//聲明一個fanout備份交換機
        channel.basicPublish("normalExchange", "errorkey", null, message.getBytes());
        發送信息到normalExchange交換機當路由鍵錯誤時會將信息發送單myAe交換機上ui

設置信息的TTL
        隊列設置TTL
        map.put("x-message-ttl", 6000);//設置信息過時時間6秒過時
        channel.queueDeclare( "normalQueue" , true , false , false , map);//建立一個norma1Queue隊列
        交換機設置每條信息超時時間
        AMQP.BasicProperties.Builder builder = new AMQP.BasicProperties.Builder();
        builder.deliveryMode(2);
        builder.expiration("11000");
        AMQP.BasicProperties properties = builder.build();
        channel.basicPublish("normalExchange", "normalKey", properties, message.getBytes());spa

死信隊列.net

  1. 信息被拒絕
  2. 信息過時
  3. 隊列達到最大長度

     建立死信隊列
        channel.exchangeDeclare("exchange.dlx", "direct", true);//建立一個持久化名爲exchange.dlx類型direct的交換機
        channel.exchangeDeclare("exchange.normal", "fanout", true);
        channel. basicPublish( "exchange.normal", "rk",MessageProperties.PERSISTENT_TEXT_PLAIN, "dlx".getBytes()) ;   orm

        Map<String, Object> map = new HashMap<String, Object>();
        map.put("x-message-ttl", 10000);//設置信息超時l0000秒
        map.put("x-dead-letter-exchange" , "exchange.dlx");//設置死信信息到exchange.dlx交換機
        map.put("x-dead-letter-routing-key", "routingkey");//死信隊列的key
        channel.queueDeclare("queue.normal" , true , false , false , map);
        channel.queueBind("queue.normal", "exchange.normal", "");
        channel.queueDeclare("queue.dlx", true , false , false , null) ;
        channel.queueBind( "queue.dlx" ,"exchange.dlx","routingkey");//queue.dlx爲死信隊列 
        (TTL隊列結合死信隊列能夠看作一個延遲隊列)blog

隊列優先級隊列

        設置隊列優先
        Map<String, Object> map =new HashMap<String, Object>() ;
        map.put( "x-rnax-priority " , 10) ;
        channel.queueDeclare( "queue.priority" , true, false , false , map) ;
        設置信息優先級
        AMQP.BasicProperties.Builder builder = new AMQP.BasicProperties.Builder() ;
        builder.priority(5) ;
        AMQP.BasicProperties properties = builder.build () ;
        channel.basicPub1ish( "exchange_priority" ,"rk_priority",properties , ("messages").getBytes()) ;
        默認優先級最低爲0路由

RPC實例
        https://blog.csdn.net/leisure_life/article/details/78657935get

相關文章
相關標籤/搜索