AgentSender.java
2.1 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.airport.core;
import com.airport.Main;
import org.apache.log4j.Logger;
import com.caac.imf.api.IMFClient;
import redis.clients.jedis.Jedis;
import java.util.Properties;
public class AgentSender extends Thread{
private static final Logger logger = Logger.getLogger(AgentSender.class);
private static final String stype = "/MSG/META/STYP";
public volatile boolean bool = false;
Jedis jedis = new Jedis("10.50.3.73", 6379);
// Jedis jedis = new Jedis("192.168.0.253", 6379);
public String str ;
private IMFClient client;
public AgentSender(IMFClient client){
this.client = client;
}
public AgentSender(){
}
public void run(){
logger.info(jedis);
while(!bool){
if(Main.isSuc){
if(Main.LOGIN_OK){
String SendMsg = jedis.rpoplpush("task-queue", "tmp-queue"); //取队列消息
//9是发送成功
if(SendMsg !=null){
logger.debug("<<发送的报文内容为:"+SendMsg+">>");
String returnMsg = client.sendMSG(SendMsg);
logger.debug("<<发送返回的信息:"+returnMsg+">>");
if(returnMsg.indexOf("<CODE>9</CODE>")>=0){
jedis.rpop("tmp-queue");
logger.debug("<<移除队列>>");
}else{
//如果发送不成功继续发送
jedis.rpoplpush("tmp-queue", "task-queue");
logger.info("!!<<执行未成功发送的消息返回到发送消息队列>>!!");
}
}
}else{
logger.info("---------登陆中");
}
try {
Thread.sleep(5000);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
public String getStr() {
return str;
}
public void setStr(String str) {
this.str = str;
}
}