MQImpl.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
76
77
78
79
80
81
package com.tianbo.analysis.service.imp;
import com.tianbo.analysis.service.MQ;
import com.tianbo.util.RabitMq.exchange.ExSendMsg;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FileUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
@Service
@Slf4j
public class MQImpl implements MQ {
//回执读取目录
@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.send-to-mq}")
private String queueName;
@Value("${mq.exchange.name}")
private String exchangeName;
@Value("${mq.exchange.type}")
private String exchangeType;
@Value("${mq.exchange.routing-key}")
private String routingName;
@Value("${mq.needSend}")
private boolean mqNeedSend;
@Override
public boolean send(String message) {
try{
if (mqNeedSend){
boolean mqSendResult = ExSendMsg.sendMsg(
exchangeName,
exchangeType,
routingName,
queueName,
message,
mqIp,
mqPort,
mqVhost,
mqUsername,
mqPassword
);
if (mqSendResult){
log.info("转发到MQ成功");
}else{
log.info("转发到MQ失败");
}
return mqSendResult;
}
return false;
} catch (Exception e){
log.error("mq读写失败",e);
return false;
}
}
@Override
public void get() {
}
}