| package com.zy.acs.gateway.listen; | 
|   | 
| import com.alibaba.fastjson.JSON; | 
| import com.zy.acs.common.constant.RedisConstant; | 
| import com.zy.acs.common.domain.AgvCommand; | 
| import com.zy.acs.common.domain.AgvProtocol; | 
| import com.zy.acs.gateway.config.SystemProperties; | 
| import com.zy.acs.gateway.domain.AgvPackage; | 
| import com.zy.acs.gateway.job.DispatcherPublisher; | 
| import com.zy.acs.common.utils.RedisSupport; | 
| import com.zy.acs.gateway.utils.ProtocolUtils; | 
| import org.slf4j.Logger; | 
| import org.slf4j.LoggerFactory; | 
| import org.springframework.beans.factory.annotation.Autowired; | 
| import org.springframework.stereotype.Component; | 
| import org.springframework.util.StringUtils; | 
|   | 
| import javax.annotation.PostConstruct; | 
| import javax.annotation.PreDestroy; | 
|   | 
| /** | 
|  * 下行报文监听器 | 
|  * 消息队列: redis list | 
|  * Created by vincent on 2019-04-02 | 
|  */ | 
| @Component | 
| public class MessageListener { | 
|   | 
|     private Thread thread; | 
|     private final RedisSupport redis = RedisSupport.defaultRedisSupport; | 
|     private final static Logger log = LoggerFactory.getLogger(MessageListener.class); | 
|   | 
|     @Autowired | 
|     private DispatcherPublisher publisher; | 
|     @Autowired | 
|     private SystemProperties systemProperties; | 
|   | 
|     @PostConstruct | 
|     private void start(){ | 
|         thread = new Thread(() -> { | 
|             while (!Thread.currentThread().isInterrupted()) { | 
|                 AgvProtocol protocol = redis.pop(RedisConstant.AGV_CMD_DOWN_FLAG); | 
|                 if (null != protocol){ | 
|                     if (systemProperties.isPrintPacLog()) { | 
|                         log.info("监听器 >>> {}", JSON.toJSONString(protocol)); | 
|                     } | 
|                     if (!StringUtils.isEmpty(protocol.getAgvNo())){ | 
|   | 
|                         publisher.publish(ProtocolUtils.installDownProtocol(protocol)); | 
|                     } | 
|                 } | 
|                 // 间隔 | 
|                 try { | 
|                     Thread.sleep(1000); | 
|                 } catch (Exception ignore) {} | 
|             } | 
|         }); | 
|         thread.start(); | 
|     } | 
|   | 
|     @PreDestroy | 
|     public void shutDown(){ | 
|         if (thread != null) thread.interrupt(); | 
|     } | 
|   | 
| } |