AgentSender.java
2.3 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
package com.airport.core;
import com.airport.Main;
import org.apache.log4j.Logger;
import com.caac.imf.api.IMFClient;
import redis.clients.jedis.Jedis;
public class AgentSender extends Thread{
private static final Logger logger = Logger.getLogger(AgentSender.class);
public volatile boolean bool = false;
Jedis jedis = new Jedis("10.50.3.73", 6379);
private IMFClient client;
public AgentSender(IMFClient client){
this.client = client;
}
public void run(){
logger.info(jedis);
while(!bool){
if(Main.isSuc){
if(Main.LOGIN_OK){
String SendMsg = jedis.rpoplpush("task-queue", "tmp-queue"); //取队列消息
//队列消息不为NULL开始发送
if(SendMsg !=null && SendMsg.length() != 0){
logger.info("《《《已读取队列消息,请关注下方发送信息LOG回显》》》");
try{
String returnMsg = client.sendMSG(SendMsg);
logger.debug("<<发送返回的信息:"+returnMsg+">>");
//9是发送成功
if(returnMsg.indexOf("<CODE>9</CODE>")>=0){
jedis.rpop("tmp-queue");
logger.debug("<<移除队列>>");
}else{
//如果发送不成功继续发送
jedis.rpoplpush("tmp-queue", "task-queue");
logger.info("!!<<执行未成功发送的消息返回到发送消息队列>>!!");
}
}catch (Exception e){
e.printStackTrace();
logger.info("!!<<请注意!发送异常====>>!!");
}
}else {
logger.info("*********当前队列为空*********");
}
}else{
logger.info("---------登陆中");
}
try {
Thread.sleep(500);//发送延迟
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
}