|
|
@@ -1,63 +0,0 @@
|
|
|
-package com.zswl.dataservice.service.artemis;
|
|
|
-
|
|
|
-import cn.hutool.json.JSONObject;
|
|
|
-import com.zswl.dataservice.model.mqtt.SendMessageModel;
|
|
|
-import com.zswl.dataservice.service.base.SuperService;
|
|
|
-import com.zswl.dataservice.utils.DateUtils;
|
|
|
-import com.zswl.dataservice.utils.mqtt.mqttConfig.client.MQClient;
|
|
|
-import com.zswl.dataservice.utils.mqtt.mqttConfig.constant.MQConstant;
|
|
|
-import com.zswl.dataservice.utils.result.ResultContent;
|
|
|
-import jakarta.jms.Message;
|
|
|
-import lombok.extern.slf4j.Slf4j;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.jms.annotation.JmsListener;
|
|
|
-import org.springframework.stereotype.Service;
|
|
|
-
|
|
|
-import java.util.UUID;
|
|
|
-
|
|
|
-/**
|
|
|
- * @author TRX
|
|
|
- * @date 2024/6/27
|
|
|
- */
|
|
|
-@Slf4j
|
|
|
-@Service
|
|
|
-public class ArtemisService extends SuperService {
|
|
|
-
|
|
|
- @Autowired
|
|
|
- MQClient mqClient;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- OperationMessageService operationMessageService;
|
|
|
-
|
|
|
- // 网关来的消息
|
|
|
- @JmsListener(destination = "/v1/gateway/#", containerFactory = MQConstant.TopicListenerContainerFactory)
|
|
|
- @JmsListener(destination = ".v1.gateway.#", containerFactory = MQConstant.TopicListenerContainerFactory)
|
|
|
- public void receiveMessage(Message message) {
|
|
|
- operationMessageService.handlerGateWayMessage(message);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 发送指令
|
|
|
- *
|
|
|
- * @param param
|
|
|
- * @return
|
|
|
- */
|
|
|
- public ResultContent sendMessage(SendMessageModel param) {
|
|
|
- String msg = "发送成功";
|
|
|
- try {
|
|
|
- JSONObject jsonObject = new JSONObject();
|
|
|
- jsonObject.append("id", UUID.randomUUID().toString());
|
|
|
- jsonObject.append("data", param.getMessage());
|
|
|
- jsonObject.append("timeStr", DateUtils.paresTime(System.currentTimeMillis(), DateUtils.patternyyyySSS));
|
|
|
- jsonObject.append("time", System.currentTimeMillis());
|
|
|
- jsonObject.append("ttl", 10 * 1000);
|
|
|
- mqClient.sendObject(param.getTopic(), jsonObject.toString());
|
|
|
- log.info("mqtt msg 发送成功");
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- msg = "发送失败: " + e.getMessage();
|
|
|
- }
|
|
|
- return ResultContent.buildSuccess(msg);
|
|
|
- }
|
|
|
-
|
|
|
-}
|