日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

java 动态队列_RabbitMq之动态修改队列参数

發布時間:2024/7/5 编程问答 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java 动态队列_RabbitMq之动态修改队列参数 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

RabbitMq不支持修改已經存在的隊列和交換機參數,可以通過創建失敗,捕獲異常信息,然后刪除原隊列或交換機,然后重新創建,以達到修改參數的功能。

package com.sky.study.delete;

import java.io.IOException;

import java.util.concurrent.TimeoutException;

import com.rabbitmq.client.AMQP;

import com.rabbitmq.client.AMQP.Queue.DeclareOk;

import com.rabbitmq.client.Channel;

import com.rabbitmq.client.Connection;

import com.sky.study.ConnectionUtil;

public class DynamicDelete {

private final static String queueName="ceshi_queue";

public static void main(String[] args) throws Exception {

Connection connection = ConnectionUtil.getConnection();

Channel channel = connection.createChannel();

DeclareOk ss = declearQueue(channel,queueName);

System.out.println(ss);

channel.close();

connection.close();

}

public static DeclareOk declearQueue(Channel channel, String queueName) throws Exception {

Connection connection1 = ConnectionUtil.getConnection();

Channel channel1 = connection1.createChannel();

try {

channel1.queueDeclare(queueName,true, false, false, null);

} catch (IOException e) {

try {

channel1.close();

} catch (Exception ex) {

}

try {

connection1.close();

} catch (Exception ex) {

}

connection1 = ConnectionUtil.getConnection();

channel1 = connection1.createChannel();

channel1.queueDelete(queueName);

try {

channel1.close();

} catch (Exception ex) {

}

try {

connection1.close();

} catch (Exception ex) {

}

} finally {

try {

channel1.close();

} catch (Exception ex) {

}

try {

connection1.close();

} catch (Exception ex) {

}

}

DeclareOk declareOk = channel.queueDeclare(queueName, true, false, false, null);

return declareOk;

}

public static AMQP.Exchange.DeclareOk declearExchange(Channel channel, String exchangeName, String exchangeMode) throws IOException, TimeoutException {

//exchangeDeclare 交換機名字,類型,是否持久化,不使用時是否自動刪除,是否是內部的(不能被客戶端使用),其他參數

Connection connection1 = ConnectionUtil.getConnection();

Channel channel1 = connection1.createChannel();

AMQP.Exchange.DeclareOk declareOk;

try {

channel1.exchangeDeclare(exchangeName, exchangeMode, true, false, false, null);

} catch (IOException e) {

try {

channel1.close();

} catch (Exception ex) {

}

try {

connection1.close();

} catch (Exception ex) {

}

connection1 = ConnectionUtil.getConnection();

channel1 = connection1.createChannel();

channel1.exchangeDelete(exchangeName);

try {

channel1.close();

} catch (Exception ex) {

}

try {

connection1.close();

} catch (Exception ex) {

}

} finally {

try {

channel1.close();

} catch (Exception ex) {

}

try {

connection1.close();

} catch (Exception ex) {

}

}

declareOk = channel.exchangeDeclare(exchangeName, exchangeMode,true, false, false, null);

return declareOk;

}

}

總結

以上是生活随笔為你收集整理的java 动态队列_RabbitMq之动态修改队列参数的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。