jiazx0107@163.com
2023-11-09 eebab358e2882fc7e3aeec152db5151a6bd0be02
src/main/java/com/fzzy/gateway/hx2023/service/OnReceiveMqttService.java
@@ -8,7 +8,9 @@
import com.fzzy.gateway.hx2023.ScConstant;
import com.fzzy.gateway.hx2023.data.CloudSendData;
import com.fzzy.gateway.hx2023.data.SyncReqData;
import com.fzzy.mqtt.MqttGatewayService;
import com.fzzy.mqtt.MqttProviderConfig;
import com.fzzy.mqtt.MqttPublishService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
@@ -24,7 +26,7 @@
    @Resource
    private GatewayRemoteManager gatewayRemoteManager;
    @Resource
    private MqttProviderConfig providerClient;
    private MqttGatewayService mqttGatewayService;
    /**
@@ -32,7 +34,7 @@
     *
     * @param message
     */
    public void onReceiveMessage(String message) {
    public void onReceiveMessage(String topic,String message) {
        try {
            CloudSendData cloudSendData = JSONObject.parseObject(message, CloudSendData.class);
@@ -46,7 +48,7 @@
            }
        } catch (Exception e) {
            log.error("--------执行异常-----{}",e);
        }
    }
@@ -69,13 +71,15 @@
        //自动推送
        if (200 == resp.getCode() && syncReqData.isAutoReplay()) {
            String topic = "/${productId}/${deviceId}/properties/report";
            String topic = ScConstant.TOPIC_REPORT;
            topic = topic.replace("${productId}", device.getProductId()).replace("${deviceId}", device.getDeviceId());
            providerClient.publish(topic, resp.getData());
            mqttGatewayService.publishMqttWithTopic(resp.getData(), topic);
            log.info("=======粮情推送==========={}", resp.getData());
            log.info("----------------------------推送MQTT信息---------------------------");
            log.info("-----TOPIC-----{}",topic);
            log.info("-----Message-----{}",resp.getData());
        }
    }
}