【发布时间】:2017-07-27 11:21:53
【问题描述】:
我也是 MQTT 和 PAHO MQTT 客户端库的新手。我可以成功连接,但是当我订阅时,我无法收到成功消息。这是我的代码
String topic = "test123";
int qos = 2;
try {
IMqttToken subToken = client.subscribe(topic, qos);
subToken.setActionCallback(new IMqttActionListener() {
@Override
public void onSuccess(IMqttToken asyncActionToken) {
// The message was published
}
@Override
public void onFailure(IMqttToken asyncActionToken,
Throwable exception) {
// The subscription could not be performed, maybe the user was not
// authorized to subscribe on the specified topic e.g. using wildcards
}
});
} catch (MqttException e) {
e.printStackTrace();
}
【问题讨论】:
-
您发布的代码只是请求订阅,您需要添加回调来处理实际的消息到达。
-
你有解决方案吗,我也在尝试同样的方法,但无法成功?