Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to reconnect when connection Lost #2389

Open
SparkingAShift opened this issue Mar 12, 2024 · 0 comments
Open

How to reconnect when connection Lost #2389

SparkingAShift opened this issue Mar 12, 2024 · 0 comments

Comments

@SparkingAShift
Copy link

package io.emqx;

import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken;
import org.eclipse.paho.client.mqttv3.MqttCallback;
import org.eclipse.paho.client.mqttv3.MqttMessage;

public class OnMessageCallback implements MqttCallback {
public void connectionLost(Throwable cause) {
// 连接丢失后,一般在这里面进行重连
System.out.println("连接断开,可以做重连");
}

public void messageArrived(String topic, MqttMessage message) throws Exception {
    // subscribe后得到的消息会执行到这里面
    System.out.println("接收消息主题:" + topic);
    System.out.println("接收消息Qos:" + message.getQos());
    System.out.println("接收消息内容:" + new String(message.getPayload()));
}

public void deliveryComplete(IMqttDeliveryToken token) {
    System.out.println("deliveryComplete---------" + token.isComplete());
}

}

no “MQTT client” was defined in this code,how to reconnect

https://www.emqx.io/docs/zh/latest/connect-emqx/java.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant