AgentSender.java 2.3 KB
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();
                }
            }
        }
    }

}