作者 朱兆平

rabbitMQ收发服务客户端

@@ -103,35 +103,29 @@ devops: @@ -103,35 +103,29 @@ devops:
103 mq: 103 mq:
104 # 从新舱单服务器读取申报业务报文发送到业务报文发送队列 {nmmsXml-mq};从回执队列{tcs-mq}读取报文保存到本地服务器回执报文接收目录 104 # 从新舱单服务器读取申报业务报文发送到业务报文发送队列 {nmmsXml-mq};从回执队列{tcs-mq}读取报文保存到本地服务器回执报文接收目录
105 # 从tcs服务器读取海关回执报文发送到回执报文发送队列 {tcs-mq};从新舱单报文申报队列{nmmsXml-mq}读取报文保存到本地服务器申报报文发送目录 105 # 从tcs服务器读取海关回执报文发送到回执报文发送队列 {tcs-mq};从新舱单报文申报队列{nmmsXml-mq}读取报文保存到本地服务器申报报文发送目录
106 - nmms:  
107 - #发送新舱单业务报文目录 [目录结尾要带/] 106 + dir:
  107 + #报文读取目录,读取本地文件发送到MQ [目录结尾要带/]
108 sendXml-dir: /Users/mrz/Downloads/rdp_temp/logs/回执报文样例/ 108 sendXml-dir: /Users/mrz/Downloads/rdp_temp/logs/回执报文样例/
109 #保存从mq取到的回执报文到本地回执目录 [目录结尾要带/] 109 #保存从mq取到的回执报文到本地回执目录 [目录结尾要带/]
110 saveXml-dir: /Users/mrz/Downloads/rdp_temp/logs/transmit/ 110 saveXml-dir: /Users/mrz/Downloads/rdp_temp/logs/transmit/
111 - tcs:  
112 - #发送回执报文目录  
113 - sendXml-dir: /Users/mrz/Downloads/rdp_temp/logs/回执报文样例/  
114 - #保存从mq取到的新舱单业务报文到本地回执目录  
115 - saveNmmsXml-dir: /Users/mrz/Downloads/rdp_temp/logs/transmit/  
116 queue: 111 queue:
117 - #新舱单业务报文mq队列名称  
118 - nmms-mq: send  
119 - #读取回执报文mq队列名称  
120 - tcs-mq: response.agent 112 + #发送mq队列名称
  113 + send-to-mq: send
  114 + #读取mq队列名称
  115 + read-from-mq: receive
121 exchange: 116 exchange:
122 #TCS回执发送到此交换,交换再把回执消息同步到其他配置的回执订阅队列 117 #TCS回执发送到此交换,交换再把回执消息同步到其他配置的回执订阅队列
123 - tcs-ex:  
124 - #交换名称  
125 - name: cus.rcv.broadcast  
126 - #交换类型  
127 - type: fanout  
128 - #routing key名称,此处为空,所有绑定交换的队列都被广播  
129 - routing-key: 118 + #交换名称
  119 + name: air.rcv.broadcast
  120 + #交换类型
  121 + type: fanout
  122 + #routing key名称,此处为空,所有绑定交换的队列都被广播
  123 + routing-key:
130 124
131 connection: 125 connection:
132 ip: 218.28.199.134 126 ip: 218.28.199.134
133 port: 8004 127 port: 8004
134 - vHost: NMMS 128 + vHost: AIRTRANS
135 username: tianbo 129 username: tianbo
136 password: vmvnv1v2VV 130 password: vmvnv1v2VV
137 # ip: 192.168.1.63 131 # ip: 192.168.1.63
@@ -4,7 +4,6 @@ @@ -4,7 +4,6 @@
4 */ 4 */
5 package com.tianbo.analysis; 5 package com.tianbo.analysis;
6 6
7 -import org.mybatis.spring.annotation.MapperScan;  
8 import org.springframework.boot.SpringApplication; 7 import org.springframework.boot.SpringApplication;
9 import org.springframework.boot.autoconfigure.SpringBootApplication; 8 import org.springframework.boot.autoconfigure.SpringBootApplication;
10 import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; 9 import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
@@ -14,7 +13,6 @@ import org.springframework.boot.web.client.RestTemplateBuilder; @@ -14,7 +13,6 @@ import org.springframework.boot.web.client.RestTemplateBuilder;
14 import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 13 import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
15 import org.springframework.cloud.client.loadbalancer.LoadBalanced; 14 import org.springframework.cloud.client.loadbalancer.LoadBalanced;
16 import org.springframework.context.annotation.Bean; 15 import org.springframework.context.annotation.Bean;
17 -import org.springframework.context.annotation.ComponentScan;  
18 import org.springframework.scheduling.annotation.EnableScheduling; 16 import org.springframework.scheduling.annotation.EnableScheduling;
19 import org.springframework.transaction.annotation.EnableTransactionManagement; 17 import org.springframework.transaction.annotation.EnableTransactionManagement;
20 import org.springframework.web.client.RestTemplate; 18 import org.springframework.web.client.RestTemplate;
@@ -29,10 +27,10 @@ import java.time.Duration; @@ -29,10 +27,10 @@ import java.time.Duration;
29 @EnableDiscoveryClient 27 @EnableDiscoveryClient
30 @EnableTransactionManagement 28 @EnableTransactionManagement
31 //@MapperScan("com.tianbo.analysis.dao") 29 //@MapperScan("com.tianbo.analysis.dao")
32 -public class BootApplication { 30 +public class MQBootApplication {
33 31
34 public static void main(String[] args) { 32 public static void main(String[] args) {
35 - SpringApplication.run(BootApplication.class, args); 33 + SpringApplication.run(MQBootApplication.class, args);
36 } 34 }
37 35
38 @Bean 36 @Bean
@@ -63,25 +63,25 @@ public class SendXml2MqThread implements Runnable{ @@ -63,25 +63,25 @@ public class SendXml2MqThread implements Runnable{
63 public void run() { 63 public void run() {
64 String filename = xmlfile.getName(); 64 String filename = xmlfile.getName();
65 log.info("线程:{}开始",filename); 65 log.info("线程:{}开始",filename);
66 -  
67 - try{  
68 - //解析前先转发  
69 - int i = handelXmlDocument();  
70 - //发送成功删除,发送失败不管保留报文  
71 - if(i==1){  
72 - FileUtils.forceDelete(xmlfile); 66 + if(xmlfile.canRead()){
  67 + try{
  68 + //解析前先转发
  69 + int i = handelXmlDocument();
  70 + //发送成功删除,发送失败不管保留报文
  71 + if(i==1){
  72 + FileUtils.forceDelete(xmlfile);
  73 + }
  74 +
  75 + }catch (IOException ioe){
  76 + log.error("文件不存在",ioe);
  77 + ioe.printStackTrace();
  78 + } catch (Exception e){
  79 + log.error("错误的解析文件剪切失败,目标目录已存在同名文件",e);
  80 + e.printStackTrace();
73 } 81 }
74 -  
75 - }catch (IOException ioe){  
76 - log.error("文件不存在",ioe);  
77 - ioe.printStackTrace();  
78 - } catch (Exception e){  
79 - log.error("错误的解析文件剪切失败,目标目录已存在同名文件",e);  
80 - e.printStackTrace();  
81 } 82 }
82 83
83 84
84 -  
85 log.info("线程:{}结束",xmlfile.getName()); 85 log.info("线程:{}结束",xmlfile.getName());
86 latch.countDown(); 86 latch.countDown();
87 log.info("剩余线程数量{}",latch.getCount()); 87 log.info("剩余线程数量{}",latch.getCount());
@@ -61,9 +61,9 @@ public class GetResponse extends DefaultConsumer { @@ -61,9 +61,9 @@ public class GetResponse extends DefaultConsumer {
61 Matcher matcher = r.matcher(content); 61 Matcher matcher = r.matcher(content);
62 String fileName = this.receptDir + UUID.randomUUID().toString()+".xml"; 62 String fileName = this.receptDir + UUID.randomUUID().toString()+".xml";
63 // 新舱单部署要去掉下面更改名称代码 63 // 新舱单部署要去掉下面更改名称代码
64 - if (matcher.find()){  
65 - fileName = this.receptDir+ matcher.group(1)+".xml";  
66 - } 64 +// if (matcher.find()){
  65 +// fileName = this.receptDir+ matcher.group(1)+".xml";
  66 +// }
67 log.info("-----------{}报文保存成功----------",fileName); 67 log.info("-----------{}报文保存成功----------",fileName);
68 File fileToDirectory = new File(fileName); 68 File fileToDirectory = new File(fileName);
69 FileUtils.writeStringToFile(fileToDirectory,content,"UTF-8"); 69 FileUtils.writeStringToFile(fileToDirectory,content,"UTF-8");
@@ -22,7 +22,7 @@ import java.util.concurrent.ThreadPoolExecutor; @@ -22,7 +22,7 @@ import java.util.concurrent.ThreadPoolExecutor;
22 public class NmmsMqGetTask { 22 public class NmmsMqGetTask {
23 23
24 //报文保存目录 24 //报文保存目录
25 - @Value("${mq.nmms.saveXml-dir}") 25 + @Value("${mq.dir.saveXml-dir}")
26 private String receptDir; 26 private String receptDir;
27 27
28 @Value("${mq.connection.ip}") 28 @Value("${mq.connection.ip}")
@@ -40,10 +40,10 @@ public class NmmsMqGetTask { @@ -40,10 +40,10 @@ public class NmmsMqGetTask {
40 @Value("${mq.connection.password}") 40 @Value("${mq.connection.password}")
41 private String mqPassword; 41 private String mqPassword;
42 42
43 - @Value("${mq.queue.tcs-mq}") 43 + @Value("${mq.queue.read-from-mq}")
44 private String queueName; 44 private String queueName;
45 45
46 - @Scheduled(fixedRate = 5000) 46 + @Scheduled(fixedRate = 5000)
47 public void startTask(){ 47 public void startTask(){
48 48
49 49
@@ -23,8 +23,8 @@ import java.util.concurrent.ThreadPoolExecutor; @@ -23,8 +23,8 @@ import java.util.concurrent.ThreadPoolExecutor;
23 @Component 23 @Component
24 public class NmmsMqSendTask { 24 public class NmmsMqSendTask {
25 25
26 - //回执读取目录  
27 - @Value("${mq.nmms.sendXml-dir}") 26 + //发送报文读取目录
  27 + @Value("${mq.dir.sendXml-dir}")
28 private String sendXmldir; 28 private String sendXmldir;
29 29
30 @Value("${mq.connection.ip}") 30 @Value("${mq.connection.ip}")
@@ -42,15 +42,24 @@ public class NmmsMqSendTask { @@ -42,15 +42,24 @@ public class NmmsMqSendTask {
42 @Value("${mq.connection.password}") 42 @Value("${mq.connection.password}")
43 private String mqPassword; 43 private String mqPassword;
44 44
45 - @Value("${mq.queue.nmms-mq}") 45 + @Value("${mq.queue.send-to-mq}")
46 private String queueName; 46 private String queueName;
47 47
  48 + @Value("${mq.exchange.name}")
  49 + private String exchangeName;
  50 +
  51 + @Value("${mq.exchange.type}")
  52 + private String exchangeType;
  53 +
  54 + @Value("${mq.exchange.routing-key}")
  55 + private String routingName;
  56 +
48 /** 57 /**
49 * 线程数量 58 * 线程数量
50 */ 59 */
51 private final static int theadamount = 10; 60 private final static int theadamount = 10;
52 61
53 - // @Scheduled(fixedRate = 5000) 62 + @Scheduled(fixedRate = 5000)
54 public void startTask(){ 63 public void startTask(){
55 64
56 final SimpleDateFormat sdf = new SimpleDateFormat( 65 final SimpleDateFormat sdf = new SimpleDateFormat(
@@ -106,6 +115,9 @@ public class NmmsMqSendTask { @@ -106,6 +115,9 @@ public class NmmsMqSendTask {
106 sendXml2MqThread.setMqUsername(mqUsername); 115 sendXml2MqThread.setMqUsername(mqUsername);
107 sendXml2MqThread.setMqPassword(mqPassword); 116 sendXml2MqThread.setMqPassword(mqPassword);
108 sendXml2MqThread.setQueueName(queueName); 117 sendXml2MqThread.setQueueName(queueName);
  118 + sendXml2MqThread.setExchangeName(exchangeName);
  119 + sendXml2MqThread.setExchangeType(exchangeType);
  120 + sendXml2MqThread.setRoutingName(routingName);
109 threadPool.execute(sendXml2MqThread); 121 threadPool.execute(sendXml2MqThread);
110 }catch (Exception e){ 122 }catch (Exception e){
111 log.error("线程解析出错{}",e); 123 log.error("线程解析出错{}",e);
@@ -19,7 +19,7 @@ import java.util.concurrent.ThreadPoolExecutor; @@ -19,7 +19,7 @@ import java.util.concurrent.ThreadPoolExecutor;
19 public class TCSMqGetTask { 19 public class TCSMqGetTask {
20 20
21 //报文保存目录 21 //报文保存目录
22 - @Value("${mq.tcs.saveNmmsXml-dir}") 22 + @Value("${mq.dir.saveXml-dir}")
23 private String receptDir; 23 private String receptDir;
24 24
25 @Value("${mq.connection.ip}") 25 @Value("${mq.connection.ip}")
@@ -37,8 +37,7 @@ public class TCSMqGetTask { @@ -37,8 +37,7 @@ public class TCSMqGetTask {
37 @Value("${mq.connection.password}") 37 @Value("${mq.connection.password}")
38 private String mqPassword; 38 private String mqPassword;
39 39
40 - //这里配置新舱单的队列名称  
41 - @Value("${mq.queue.nmms-mq}") 40 + @Value("${mq.queue.read-from-mq}")
42 private String queueName; 41 private String queueName;
43 42
44 // @Scheduled(fixedRate = 5000) 43 // @Scheduled(fixedRate = 5000)
@@ -23,7 +23,7 @@ import java.util.concurrent.ThreadPoolExecutor; @@ -23,7 +23,7 @@ import java.util.concurrent.ThreadPoolExecutor;
23 public class TCSMqSendTask { 23 public class TCSMqSendTask {
24 24
25 //回执读取目录 25 //回执读取目录
26 - @Value("${mq.tcs.sendXml-dir}") 26 + @Value("${mq.dir.sendXml-dir}")
27 private String sendXmldir; 27 private String sendXmldir;
28 28
29 @Value("${mq.connection.ip}") 29 @Value("${mq.connection.ip}")
@@ -41,16 +41,16 @@ public class TCSMqSendTask { @@ -41,16 +41,16 @@ public class TCSMqSendTask {
41 @Value("${mq.connection.password}") 41 @Value("${mq.connection.password}")
42 private String mqPassword; 42 private String mqPassword;
43 43
44 - @Value("${mq.queue.tcs-mq}") 44 + @Value("${mq.queue.send-to-mq}")
45 private String queueName; 45 private String queueName;
46 46
47 - @Value("${mq.exchange.tcs-ex.name}") 47 + @Value("${mq.exchange.name}")
48 private String exchangeName; 48 private String exchangeName;
49 49
50 - @Value("${mq.exchange.tcs-ex.type}") 50 + @Value("${mq.exchange.type}")
51 private String exchangeType; 51 private String exchangeType;
52 52
53 - @Value("${mq.exchange.tcs-ex.routing-key}") 53 + @Value("${mq.exchange.routing-key}")
54 private String routingName; 54 private String routingName;
55 /** 55 /**
56 * 线程数量 56 * 线程数量