liangyt 5 years ago
parent
commit
cf2a0b73bd

+ 20 - 42
src/main/java/com/miyzh/config/RabbitConfig.java

@@ -35,18 +35,17 @@ public class RabbitConfig {
     private String password;
 
 
-    public static final String EXCHANGE_A = "my-mq-exchange_A";
-    public static final String EXCHANGE_B = "my-mq-exchange_B";
-    public static final String EXCHANGE_C = "my-mq-exchange_C";
 
+    public static final String EXCHANGE_SETTLE = "settexchange";
 
-    public static final String QUEUE_A = "QUEUE_A";
-    public static final String QUEUE_B = "QUEUE_B";
-    public static final String QUEUE_C = "QUEUE_C";
 
-    public static final String ROUTINGKEY_A = "spring-boot-routingKey_A";
-    public static final String ROUTINGKEY_B = "spring-boot-routingKey_B";
-    public static final String ROUTINGKEY_C = "spring-boot-routingKey_C";
+
+    public static final String QUEUE_SETTLE = "confirmSettle";
+    public static final String QUEUE_PRESETTLE = "preSettle";
+
+
+    public static final String ROUTINGKEY_CONFIRM = "confirmSettle";
+    public static final String ROUTINGKEY_PRE = "preSettle";
 
     @Bean
     public ConnectionFactory connectionFactory() {
@@ -75,59 +74,38 @@ public class RabbitConfig {
      DirectExchange:按照routingkey分发到指定队列
      TopicExchange:多关键字匹配
      */
-    @Bean
-    public DirectExchange directExchange() {
-        return new DirectExchange(EXCHANGE_A);
-    }
 
     @Bean
-    public FanoutExchange fanoutExchange() {
-        return new FanoutExchange(EXCHANGE_B);
+    public DirectExchange directExchange() {
+        return new DirectExchange(EXCHANGE_SETTLE);
     }
 
-    @Bean
-    public TopicExchange topicExchange() {
-        return new TopicExchange(EXCHANGE_C);
-    }
     /**
-     * 获取队列A
+     * 获取队列Pre
      * @return
      */
     @Bean
-    public Queue queueA() {
+    public Queue queuePre() {
         //队列持久
-        return new Queue(QUEUE_A, true);
+        return new Queue(QUEUE_PRESETTLE, true);
     }
     @Bean
-    public Binding binding() {
+    public Binding bindingPre() {
 
-        return BindingBuilder.bind(queueA()).to(directExchange()).with(RabbitConfig.ROUTINGKEY_A);
+        return BindingBuilder.bind(queuePre()).to(directExchange()).with(RabbitConfig.ROUTINGKEY_PRE);
     }
     /**
-     * 获取队列B
+     * 获取队列confirm
      * @return
      */
     @Bean
-    public Queue queueB() {
+    public Queue queueConfirm() {
         //队列持久
-        return new Queue(QUEUE_B, true);
+        return new Queue(QUEUE_SETTLE, true);
     }
     @Bean
-    public Binding bindingB(){
-        return BindingBuilder.bind(queueB()).to(fanoutExchange());
-    }
+    public Binding binding() {
 
-    /**
-     * 获取队列B
-     * @return
-     */
-    @Bean
-    public Queue queueC() {
-        //队列持久
-        return new Queue(QUEUE_C, true);
-    }
-    @Bean
-    public Binding bindingC(){
-        return BindingBuilder.bind(queueB()).to(topicExchange()).with(ROUTINGKEY_C);
+        return BindingBuilder.bind(queueConfirm()).to(directExchange()).with(RabbitConfig.ROUTINGKEY_CONFIRM);
     }
 }

+ 9 - 1
src/main/java/com/miyzh/rabbitMQ/MsgProducer.java

@@ -47,7 +47,15 @@ public class MsgProducer implements RabbitTemplate.ConfirmCallback,RabbitTemplat
         CorrelationData correlationId = new CorrelationData(UUID.randomUUID().toString());
         //把消息放入ROUTINGKEY_A对应的队列当中去,对应的是队列A
         System.out.println("发送消息。。。。");
-        rabbitTemplate.convertAndSend(RabbitConfig.EXCHANGE_A, RabbitConfig.ROUTINGKEY_A, msg, correlationId);
+//        rabbitTemplate.convertAndSend(RabbitConfig.EXCHANGE_A, RabbitConfig.ROUTINGKEY_A, msg, correlationId);
+    }
+
+    public void sendMsgB(String msg) {
+        //消息唯一性
+        CorrelationData correlationId = new CorrelationData(UUID.randomUUID().toString());
+        //把消息放入ROUTINGKEY_A对应的队列当中去,对应的是队列A
+        System.out.println("发送消息。。。。");
+//        rabbitTemplate.convertAndSend(RabbitConfig.EXCHANGE_A, RabbitConfig.ROUTINGKEY_B, msg, correlationId);
     }
     /**
      * @author: lyt

+ 3 - 2
src/main/java/com/miyzh/rabbitMQ/MsgReceiver.java

@@ -3,6 +3,7 @@ package com.miyzh.rabbitMQ;
 import com.miyzh.config.RabbitConfig;
 import com.miyzh.entity.UploadExceptionLog;
 import com.miyzh.service.UploadService;
+import com.miyzh.utils.DesUtil;
 import com.rabbitmq.client.Channel;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -34,7 +35,7 @@ public class MsgReceiver {
             System.out.println("消费消息:" + content);
             channel.basicAck(message.getMessageProperties().getDeliveryTag(), true);
             UploadExceptionLog uploadExceptionLog = new UploadExceptionLog();
-            uploadExceptionLog.setUploadInfo(content);
+            uploadExceptionLog.setUploadInfo(DesUtil.decrypt(content));
             uploadService.upload(uploadExceptionLog);
             System.out.println("消费消息确认" + message.getMessageProperties().getConsumerQueue() + ",接收到了回调方法");
         } catch (Exception e) {
@@ -55,7 +56,7 @@ public class MsgReceiver {
             System.out.println("消费消息:" + content);
             channel.basicAck(message.getMessageProperties().getDeliveryTag(), true);
             UploadExceptionLog uploadExceptionLog = new UploadExceptionLog();
-            uploadExceptionLog.setUploadInfo(content);
+            uploadExceptionLog.setUploadInfo(DesUtil.decrypt(content));
             uploadService.upload(uploadExceptionLog);
             System.out.println("消费消息确认" + message.getMessageProperties().getConsumerQueue() + ",接收到了回调方法");
         } catch (Exception e) {

+ 1 - 1
src/main/java/com/miyzh/service/UploadService.java

@@ -36,7 +36,7 @@ public class UploadService {
 
     public String upload(UploadExceptionLog uploadExceptionLog) {
         try {
-            Document doc = DocumentHelper.parseText(DesUtil.encrypt(uploadExceptionLog.getUploadInfo()));
+            Document doc = DocumentHelper.parseText(uploadExceptionLog.getUploadInfo());
 //            Document doc = DocumentHelper.parseText(uploadExceptionLog.getUploadInfo());
             if (StringUtils.isBlank(uploadExceptionLog.getTradeCode())) {
                 if (StringUtils.isBlank(doc.getRootElement().element("TradeCode").getTextTrim())) {