From 4ceb5e95fdeecb179496a53be0558b1b55c83efa Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E8=B5=B5=E5=95=B8=E9=9D=9E?= <13281114856@qq.com>
Date: Tue, 16 Aug 2022 17:01:35 +0800
Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=94=A8=E6=88=B7=E7=99=BB?=
 =?UTF-8?q?=E5=BD=95,=E6=9D=83=E9=99=90=E5=88=86=E9=85=8D=E7=AD=89?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../queue/rabbitmq/TbRabbitMqProducerTemplate.java  | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/common-lib/src/main/java/com/mortals/xhx/queue/rabbitmq/TbRabbitMqProducerTemplate.java b/common-lib/src/main/java/com/mortals/xhx/queue/rabbitmq/TbRabbitMqProducerTemplate.java
index 501c4231..bc7d48c3 100644
--- a/common-lib/src/main/java/com/mortals/xhx/queue/rabbitmq/TbRabbitMqProducerTemplate.java
+++ b/common-lib/src/main/java/com/mortals/xhx/queue/rabbitmq/TbRabbitMqProducerTemplate.java
@@ -84,7 +84,7 @@ public class TbRabbitMqProducerTemplate<T extends TbQueueMsg> implements TbQueue
         try {
             if (!topicIfNotExist) {
                 //topic涓嶅瓨鍦ㄥ垱寤洪€氶亾闃熷垪
-                log.info("queueDeclareAdd==>exchangeName:{} topic:{}",tpi.getExchangeName(),tpi.getTopic());
+                log.info("sendQueueDeclareAdd==>exchangeName:{} topic:{}",tpi.getExchangeName(),tpi.getTopic());
                 Map<String, Object> args = new HashMap<>();
                 args.put("x-message-ttl", Integer.parseInt(rabbitMqSettings.getMessageTtl()));
                 channel.queueDeclare(tpi.getTopic(), true, false, false, args);
@@ -133,17 +133,18 @@ public class TbRabbitMqProducerTemplate<T extends TbQueueMsg> implements TbQueue
     public void queueDeclare(TopicPartitionInfo tpi, TbQueueCallback callback) {
         Boolean topicIfNotExist = createTopicIfNotExist(tpi);
         try {
+            if (!innerExists(tpi.getExchangeName(), channel)) {
+                //鍒ゆ柇浜ゆ崲鏈烘槸鍚﹀瓨鍦紝濡傛灉涓嶅瓨鍦ㄥ垯鍒涘缓鍚庝笌鏂板姞鍏ョ殑闃熷垪缁戝畾
+                channel = connection.createChannel();
+                channel.exchangeDeclare(tpi.getExchangeName(), BuiltinExchangeType.DIRECT, true, false, null);
+            }
             if (!topicIfNotExist) {
                 //topic涓嶅瓨鍦ㄥ垱寤洪€氶亾闃熷垪
                 log.info("queueDeclareAdd==>exchangeName:{} topic:{}",tpi.getExchangeName(),tpi.getTopic());
                 Map<String, Object> args = new HashMap<>();
                 args.put("x-message-ttl", Integer.parseInt(rabbitMqSettings.getMessageTtl()));
                 channel.queueDeclare(tpi.getTopic(), true, false, false, args);
-            }
-            if (!innerExists(tpi.getExchangeName(), channel)) {
-                //鍒ゆ柇浜ゆ崲鏈烘槸鍚﹀瓨鍦紝濡傛灉涓嶅瓨鍦ㄥ垯鍒涘缓鍚庝笌鏂板姞鍏ョ殑闃熷垪缁戝畾
-                channel = connection.createChannel();
-                channel.exchangeDeclare(tpi.getExchangeName(), BuiltinExchangeType.DIRECT, true, false, null);
+                channel.queueBind(tpi.getTopic(), tpi.getExchangeName(), tpi.getTopic());
             }
 
             // callback.onSuccess(new RabbitQueueMsgMetadata());
-- 
2.24.3