liulin
2025-07-03 fb2f11d7d502ceacbe7fbed176bea4ab0f152f69
src/main/java/com/lunhan/water/host/mqtt/MQTTServer.java
@@ -63,11 +63,10 @@
     * @param topic 发布消息的主题
     * @param data 消息内容
     */
    public boolean send(String topic, String data) throws MqttException {
        MqttConnectOptions options = mqttConnect.getOptions();
    public boolean send(String topic, String data) {
        try {
            client.connect(mqttConnect.getOptions(options));
        } catch (Exception e) {}
            this.connect();
        } catch (Exception ignored) {}
        MqttTopic mqttTopic = client.getTopic(topic);
        MqttMessage message = new MqttMessage();
@@ -81,7 +80,13 @@
        message.setPayload(data.getBytes());
        return this.publish(mqttTopic, message);
        LOGGER.debug(String.format("发送mqtt消息:%s, 消息内容:%s", topic, message));
        try {
            return this.publish(mqttTopic, message);
        } catch (MqttException e) {
            LOGGER.error("发送mqtt消息", e);
            return Boolean.FALSE;
        }
    }
    @Override