CustomMqGetTask.java
2.0 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package com.tianbo.analysis.task;
import com.tianbo.analysis.model.RabbitMQ;
import com.tianbo.analysis.rabbitmq.ReadMessage;
import com.tianbo.util.Date.DateUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.ThreadPoolExecutor;
/**
* 新舱单从mq服务器的tcs回执队列中获取回执报文并落地保存
* 回执解析定时任务
* 从mq获取报文 落地保存
*/
@Slf4j
@Component
public class CustomMqGetTask {
//报文保存目录
@Value("${mq.dir.saveXml-dir}")
private String receptDir;
@Value("${mq.connection.ip}")
private String mqIp;
@Value("${mq.connection.port}")
private int mqPort;
@Value("${mq.connection.vHost}")
private String mqVhost;
@Value("${mq.connection.username}")
private String mqUsername;
@Value("${mq.connection.password}")
private String mqPassword;
@Value("${mq.queue.read-from-mq}")
private String queueName;
@Value("${mq.exchange.name}")
private String exchangeName;
@Value("${mq.exchange.routing-key}")
private String routingKey;
// @Scheduled(fixedRate = 5000)
public void startTask(){
try {
//从mq获取回执
RabbitMQ readMessage = new RabbitMQ(mqIp,mqPort,mqVhost,mqUsername,mqPassword,queueName);
readMessage.setExchangeName(exchangeName);
readMessage.setRoutingKey(routingKey);
if(!"runing".equals(RabbitMQ.status)){
log.info("开始连接MQ服务器");
readMessage.getResponseFromMq();
log.info("MQ通道建立成功");
}
}catch (Exception e){
e.printStackTrace();
log.error("程序出错",e);
}
// log.info("获取消息结束");
}
}