1
0
Просмотр исходного кода

req_2021-07-19 清关时效性mq发送bug修复

lhm 3 лет назад
Родитель
Сommit
0bcf2f9b4e

+ 0 - 23
kmall-admin/src/main/java/com/kmall/admin/config/mq/CustomRabbitMQProperties.java

@@ -1,62 +1,39 @@
 package com.kmall.admin.config.mq;
 
 /**
- * 自定义的rabbitmq属性
- * @author lhm
- * @version 1.0
- * 2021-09-08 17:36
- */
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.context.annotation.PropertySource;
-import org.springframework.stereotype.Component;
-
-/**
  * 队列配置
  * req_20210826_001
  * @author lhm
  * @version 1.0
  * 2021-08-26 17:08
  */
-@PropertySource(value = {"classpath:conf/mq.properties"})
-@Component
 public class CustomRabbitMQProperties {
 
     /**
      * 主要配置
      */
-    @Value("${mq.username}")
     private String username;
 
-    @Value("${mq.password}")
     private String password;
 
-    @Value("${mq.host}")
     private String host;
 
-    @Value("${mq.port}")
     private int port;
 
-    @Value("${mq.virtual.host}")
     private String virtualHost;
 
-    @Value("${mq.channel.cache.size}")
     private int channelCacheSize;
 
     /**
      * 是否开启
      */
-    @Value("${mq.open}")
     private Boolean open;
 
-
     /**
      * 队列配置
      */
-    @Value("${k.normal.oms.order.to.handle.customs.clearance}")
     private String k_normal_oms_order_to_handle_customs_clearance;
-    @Value("${q.normal.oms.order.to.handle.customs.clearance}")
     private String q_normal_oms_order_to_handle_customs_clearance;
-    @Value("${e.normal.oms.order.to.handle.customs.clearance}")
     private String e_normal_oms_order_to_handle_customs_clearance;
 
 

+ 32 - 12
kmall-admin/src/main/java/com/kmall/admin/config/mq/RabbitMQConfig.java

@@ -14,6 +14,8 @@ import org.springframework.amqp.support.converter.MessageConverter;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.PropertySource;
+import org.springframework.core.env.Environment;
 
 /**
  * 队列相关配置
@@ -23,24 +25,42 @@ import org.springframework.context.annotation.Configuration;
  * 2021-08-26 17:07
  */
 @Configuration
+@PropertySource(value = {"classpath:conf/mq.properties"})
 public class RabbitMQConfig {
 
     @Autowired
-    private CustomRabbitMQProperties customRabbitMQProperties;
+    private Environment environment;
+
+    @Bean
+    public CustomRabbitMQProperties customRabbitMQProperties () {
+        CustomRabbitMQProperties customRabbitMQProperties = new CustomRabbitMQProperties();
+        customRabbitMQProperties.setUsername(environment.getProperty("mq.username"));
+        customRabbitMQProperties.setPassword(environment.getProperty("mq.password"));
+        customRabbitMQProperties.setHost(environment.getProperty("mq.host"));
+        customRabbitMQProperties.setPort(Integer.parseInt(environment.getProperty("mq.port")));
+        customRabbitMQProperties.setVirtualHost(environment.getProperty("mq.virtual.host"));
+        customRabbitMQProperties.setChannelCacheSize(Integer.parseInt(environment.getProperty("mq.channel.cache.size")));
+        customRabbitMQProperties.setOpen(Boolean.parseBoolean(environment.getProperty("mq.ope")));
+        customRabbitMQProperties.setE_normal_oms_order_to_handle_customs_clearance(environment.getProperty("e.normal.oms.order.to.handle.customs.clearance"));
+        customRabbitMQProperties.setQ_normal_oms_order_to_handle_customs_clearance(environment.getProperty("q.normal.oms.order.to.handle.customs.clearance"));
+        customRabbitMQProperties.setK_normal_oms_order_to_handle_customs_clearance(environment.getProperty("k.normal.oms.order.to.handle.customs.clearance"));
+
+        return customRabbitMQProperties;
+    }
 
     /* ----------------------------------------------- 基础配置 --------------------------------------------- */
     @Bean
     public ConnectionFactory connectionFactory () {
         CachingConnectionFactory connectionFactory = new CachingConnectionFactory();
-        connectionFactory.setUsername(customRabbitMQProperties.getUsername());
-        connectionFactory.setPassword(customRabbitMQProperties.getPassword());
-        connectionFactory.setHost(customRabbitMQProperties.getHost());
-        connectionFactory.setVirtualHost(customRabbitMQProperties.getVirtualHost());
-        connectionFactory.setPort(customRabbitMQProperties.getPort());
+        connectionFactory.setUsername(customRabbitMQProperties().getUsername());
+        connectionFactory.setPassword(customRabbitMQProperties().getPassword());
+        connectionFactory.setHost(customRabbitMQProperties().getHost());
+        connectionFactory.setVirtualHost(customRabbitMQProperties().getVirtualHost());
+        connectionFactory.setPort(customRabbitMQProperties().getPort());
         // 共用同一个Channel
         connectionFactory.setCacheMode(CachingConnectionFactory.CacheMode.CHANNEL);
         // 获取配置的Channel缓存大小
-        connectionFactory.setChannelCacheSize(customRabbitMQProperties.getChannelCacheSize());
+        connectionFactory.setChannelCacheSize(customRabbitMQProperties().getChannelCacheSize());
         // 消息到达broke后触发回调
         connectionFactory.setPublisherConfirms(true);
         return connectionFactory;
@@ -87,8 +107,8 @@ public class RabbitMQConfig {
     public RabbitTemplate clearRabbitTemplate (ConnectionFactory connectionFactory) {
         RabbitTemplate rabbitTemplate = new RabbitTemplate(connectionFactory);
 
-        rabbitTemplate.setExchange(customRabbitMQProperties.getE_normal_oms_order_to_handle_customs_clearance());
-        rabbitTemplate.setRoutingKey(customRabbitMQProperties.getK_normal_oms_order_to_handle_customs_clearance());
+        rabbitTemplate.setExchange(customRabbitMQProperties().getE_normal_oms_order_to_handle_customs_clearance());
+        rabbitTemplate.setRoutingKey(customRabbitMQProperties().getK_normal_oms_order_to_handle_customs_clearance());
         rabbitTemplate.setConfirmCallback(new SimpleClearConfirmCallback());
         rabbitTemplate.setReturnCallback(new SimpleClearReturnCallback());
 
@@ -97,16 +117,16 @@ public class RabbitMQConfig {
 
     @Bean
     public DirectExchange clearDirectExchange () {
-        return new DirectExchange(customRabbitMQProperties.getE_normal_oms_order_to_handle_customs_clearance());
+        return new DirectExchange(customRabbitMQProperties().getE_normal_oms_order_to_handle_customs_clearance());
     }
 
     @Bean
     public Queue clearQueue () {
-        return new Queue(customRabbitMQProperties.getQ_normal_oms_order_to_handle_customs_clearance());
+        return new Queue(customRabbitMQProperties().getQ_normal_oms_order_to_handle_customs_clearance());
     }
 
     @Bean
     public Binding clearBinding () {
-        return BindingBuilder.bind(clearQueue()).to(clearDirectExchange()).with(customRabbitMQProperties.getK_normal_oms_order_to_handle_customs_clearance());
+        return BindingBuilder.bind(clearQueue()).to(clearDirectExchange()).with(customRabbitMQProperties().getK_normal_oms_order_to_handle_customs_clearance());
     }
 }

+ 2 - 0
kmall-admin/src/main/resources/spring/spring-main.xml

@@ -21,6 +21,7 @@
                 <value>classpath:conf/db.properties</value>
                 <value>classpath:conf/servlet.properties</value>
                 <value>classpath:conf/fastdfs.properties</value>
+                <value>classpath:conf/mq.properties</value>
             </list>
         </property>
         <property name="fileEncoding" value="UTF-8"/>
@@ -29,6 +30,7 @@
     <import resource="classpath:spring/spring-manager-main.xml"/>
     <import resource="spring-mvc.xml"/>
     <import resource="spring-shiro.xml"/>
+    <import resource="spring-rabbit.xml"/>
     <import resource="classpath:kmall-api.xml"/>
 
 

+ 8 - 0
kmall-admin/src/main/resources/spring/spring-rabbit.xml

@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://www.springframework.org/schema/beans"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:rabbit="http://www.springframework.org/schema/rabbit"
+       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/rabbit http://www.springframework.org/schema/rabbit/spring-rabbit.xsd">
+
+
+
+</beans>