diff --git a/device-manager/src/main/java/com/mortals/xhx/daemon/applicationservice/RabbitMsgComsumerStartedService.java b/device-manager/src/main/java/com/mortals/xhx/daemon/applicationservice/RabbitMsgComsumerStartedService.java index 63b607c602afd094152d503fd8ff0f8bcaf2def9..fe6a7c511763770d58a3d6aff6a63a1146bb69e7 100644 --- a/device-manager/src/main/java/com/mortals/xhx/daemon/applicationservice/RabbitMsgComsumerStartedService.java +++ b/device-manager/src/main/java/com/mortals/xhx/daemon/applicationservice/RabbitMsgComsumerStartedService.java @@ -46,7 +46,7 @@ public class RabbitMsgComsumerStartedService implements IApplicationStartedServi .toArray(String[]::new); simpleContainer.addQueueNames(queues); simpleContainer.start(); - simpleContainer.addQueueNames("123"); + // simpleContainer.addQueueNames("123"); simpleContainer.setMessageListener(simpleDynamicListener); } diff --git a/device-manager/src/main/java/com/mortals/xhx/module/device/service/impl/DeviceServiceImpl.java b/device-manager/src/main/java/com/mortals/xhx/module/device/service/impl/DeviceServiceImpl.java index e6fa042e48656945a404b4d39fe544b740e7ec59..c38734e17beb0945278df25ba9c1c6d999ad9a3e 100644 --- a/device-manager/src/main/java/com/mortals/xhx/module/device/service/impl/DeviceServiceImpl.java +++ b/device-manager/src/main/java/com/mortals/xhx/module/device/service/impl/DeviceServiceImpl.java @@ -45,6 +45,7 @@ import com.mortals.xhx.module.site.model.SiteEntity; import com.mortals.xhx.module.site.service.SiteService; import com.mortals.xhx.queue.*; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; import org.springframework.amqp.rabbit.connection.CorrelationData; import org.springframework.amqp.rabbit.listener.DirectMessageListenerContainer; import org.springframework.beans.BeanUtils; @@ -107,7 +108,6 @@ public class DeviceServiceImpl extends AbstractCRUDCacheServiceImpl<DeviceDao, D @Autowired private SiteService siteService; - public void refresh() { log.info("寮€濮嬪垵濮嬪寲绯荤粺鍙傛暟..."); try { @@ -222,7 +222,8 @@ public class DeviceServiceImpl extends AbstractCRUDCacheServiceImpl<DeviceDao, D messageProducer.queueAddAndBinds(QueueKey.DEFAULT_EXCHANGE, Constant.UPLOAD_TOPIC + deviceCode, Constant.UPLOAD_TOPIC + deviceCode); messageProducer.queueAddAndBinds(QueueKey.DEFAULT_EXCHANGE, Constant.DOWN_TOPIC + deviceCode, Constant.DOWN_TOPIC + deviceCode); //璁㈤槄涓婅闃熷垪 - container.addQueueNames(Constant.UPLOAD_TOPIC + deviceCode); + // container.addQueueNames(Constant.UPLOAD_TOPIC + deviceCode); + restartMessageListener(Constant.UPLOAD_TOPIC + deviceCode); //鏂板璁惧閫氱煡绗笁鏂瑰钩鍙�,鍏堟柊澧炲悗婵€娲� sendThirdParty(deviceEntity, productEntity, platformEntity, DeviceMethodEnum.ADD); @@ -369,7 +370,8 @@ public class DeviceServiceImpl extends AbstractCRUDCacheServiceImpl<DeviceDao, D //娉ㄥ唽rabbmit鐩稿叧闃熷垪涓庣粦瀹� messageProducer.queueAddAndBinds(QueueKey.DEFAULT_EXCHANGE, Constant.UPLOAD_TOPIC + entity.getDeviceCode(), Constant.UPLOAD_TOPIC + entity.getDeviceCode()); messageProducer.queueAddAndBinds(QueueKey.DEFAULT_EXCHANGE, Constant.DOWN_TOPIC + entity.getDeviceCode(), Constant.DOWN_TOPIC + entity.getDeviceCode()); - + restartMessageListener(Constant.UPLOAD_TOPIC + entity.getDeviceCode()); + //鐩戝惉涓婅闃熷垪 sendThirdParty(entity, productEntity, platformEntity, DeviceMethodEnum.UPDATE); } } @@ -386,10 +388,7 @@ public class DeviceServiceImpl extends AbstractCRUDCacheServiceImpl<DeviceDao, D deviceReq.setDeviceInFloor(entity.getDeviceInFloor() == null ? 0 : entity.getDeviceInFloor()); //http://192.168.0.98:8090/inter/device/deviceIn //鍒ゆ柇鏄惁鏄痯hp锛屽鏋滀笉鏄� 鍒欐槸java 鍒欏唴閮ㄨ皟鐢� - try { - - if ("smartOffice".equals(platformEntity.getPlatformSn())) { deviceReq.setReceiveMethod(update.getValue()); //todo 璋冪敤鏅烘収鍔炲叕绯荤粺 @@ -417,16 +416,6 @@ public class DeviceServiceImpl extends AbstractCRUDCacheServiceImpl<DeviceDao, D log.info("fill resp ==>{}", JSON.toJSONString(fillRest)); } else { cacheService.lpush(RedisKey.KEY_DEVICE_THIRDPARTY_QUEUE, deviceReq); -// log.info("lpush:{}",lpush); -// String phpInUrl = GlobalSysInfo.getParamValue(PARAM_SERVER_PHP_IN_HTTP_URL, "http://172.15.28.116:8090"); -// ApiResp<String> resp = messageService.sendThirdParty(UrlBuilder.of(phpInUrl).addPath(thirdPartyPath).build(), deviceReq); -// log.info("sendThirty resp ==>{}", JSON.toJSONString(resp)); -// -// if (!ObjectUtils.isEmpty(resp) && resp.getCode() == YesNoEnum.YES.getValue()) { -// return Rest.ok("鎴愬姛锛�"); -// } else { -// return Rest.fail("鍙戦€佸け璐�"); -// } } } catch (Exception e) { log.error("feign璋冪敤寮傚父锛�"); @@ -648,7 +637,8 @@ public class DeviceServiceImpl extends AbstractCRUDCacheServiceImpl<DeviceDao, D if (!ObjectUtils.isEmpty(entity.getDeviceStatus()) && entity.getDeviceStatus() > DeviceStatusEnum.鏈縺娲�.getValue()) { //婵€娲昏澶囷紝娣诲姞闃熷垪璁㈤槄 - container.addQueueNames(Constant.UPLOAD_TOPIC + entity.getDeviceCode()); + //container.addQueueNames(Constant.UPLOAD_TOPIC + entity.getDeviceCode()); + restartMessageListener(Constant.UPLOAD_TOPIC + entity.getDeviceCode()); PlatformEntity platformEntity = platformService.getCache(entity.getPlatformId().toString()); ProductEntity productEntity = productService.getCache(entity.getProductId().toString()); sendThirdParty(entity, productEntity, platformEntity, DeviceMethodEnum.ADD); @@ -737,40 +727,35 @@ public class DeviceServiceImpl extends AbstractCRUDCacheServiceImpl<DeviceDao, D correlationData.setId(deviceEntity.getDeviceCode()); log.info("send rabbitmq msg:{}", item.getDeviceCode()); messageProducer.sendMsg(QueueKey.DEFAULT_EXCHANGE, Constant.DOWN_TOPIC + deviceEntity.getDeviceCode(), JSON.toJSONString(queueMsg), correlationData); - -/* DeviceLogEntity deviceLogEntity = new DeviceLogEntity(); - deviceLogEntity.initAttrValue(); - deviceLogEntity.setTraceID(IdUtil.fastSimpleUUID()); - deviceLogEntity.setSiteId(deviceEntity.getSiteId()); - deviceLogEntity.setDeviceId(deviceEntity.getId()); - deviceLogEntity.setDeviceName(deviceEntity.getDeviceName()); - deviceLogEntity.setDeviceCode(deviceEntity.getDeviceCode()); - deviceLogEntity.setMessageHead(item.getMessageType()); - deviceLogEntity.setContent(item.getData()); - deviceLogEntity.setLogType(LogTypeEnum.涓嬪彂鏈嶅姟.getValue()); - deviceLogEntity.setCreateUserId(1L); - deviceLogEntity.setCreateTime(new Date()); - deviceLogList.add(deviceLogEntity);*/ - // deviceLogService.save(deviceLogEntity, null); } else { log.info("鏈壘鍒拌澶囷紝deviceCode:{}", item.getDeviceCode()); } } - - /* if (!ObjectUtils.isEmpty(deviceLogList)) { - List<List<DeviceLogEntity>> partitionlogs = ListUtil.partition(deviceLogList, 100); - for (List<DeviceLogEntity> deviceLogEntities : partitionlogs) { - deviceLogService.save(deviceLogEntities); - } - }*/ - } catch (Exception e) { log.error("寮傚父锛�", e); } } + /** + * 閲嶅惎瀵规秷鎭槦鍒楃殑鐩戝惉 + * @param queueName + * @return + */ + public boolean restartMessageListener(String queueName) { + String key = StringUtils.trim(queueName); + container.addQueueNames(key); + + if(container.isRunning()){ + container.stop(); + container.start(); + } + container.start(); + return true; + } + + public static void main(String[] args) { BigDecimal bigDecimal = new BigDecimal("104.22241"); BigDecimal add = bigDecimal.add(new BigDecimal("0.01"));