package com.zy.acs.manager.core.listen; import com.zy.acs.common.constant.RedisConstant; import com.zy.acs.common.domain.AgvProtocol; import com.zy.acs.common.utils.RedisSupport; import com.zy.acs.manager.core.service.AgvDataService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import javax.annotation.PostConstruct; import javax.annotation.PreDestroy; /** * Created by vincent on 2023/6/16 */ @Slf4j @Component public class AgvDataSubscriber { private Thread thread; private final RedisSupport redis = RedisSupport.defaultRedisSupport; @Autowired private AgvDataService agvDataService; @PostConstruct private void start(){ // redis.deleteList(RedisConstant.AGV_DATA_FLAG); thread = new Thread(() -> { while (!Thread.currentThread().isInterrupted()) { try { // 间隔 Thread.sleep(10); AgvProtocol protocol = redis.pop(RedisConstant.AGV_DATA_FLAG); if (null != protocol){ agvDataService.dataProcess(protocol); } } catch (Exception ignore) {} } }); thread.start(); } @PreDestroy public void shutDown(){ if (thread != null) thread.interrupt(); } }