此处完全丢失,但是一旦我尝试连接到CloudMQTT,我的客户端就崩溃了。
3-05 16:22:54.541 9063-9078 / my.pkg.name D / MQTTCONN:即将连接
03-05 16:22:55.341 9063-9091 / my.pkg.name D / AlarmPingSender:取消注册警报接收者到MqttServiceourTestMqttSubId
03-05 16:22:55.375 9063-9063 / my.pkg.name E / MQTTFAIL:连接丢失
03-05 16:22:55.376 9063-9063 / my.pkg.name W / System.err:at org.eclipse.paho.client.mqttv3.internal.CommsReceiver.run(CommsReceiver.java:146)< / p>
03-05 16:22:55.377 9063-9063 / my.pkg.name W / System.err:at org.eclipse.paho.client.mqttv3.internal.wire.MqttInputStream.readMqttWireMessage(MqttInputStream.java:65 )
03-05 16:22:55.377 9063-9063 / my.pkg.name W / System.err:at org.eclipse.paho.client.mqttv3.internal.CommsReceiver.run(CommsReceiver.java:107)< / p>
这是我的代码:
final MqttAndroidClient mqttClient = new MqttAndroidClient(
argsService.getContext(),
(String) configService.getArg("mqttBroker"),
activeSubId.getSubId(),
new MemoryPersistence()
);
MqttConnectOptions options = new MqttConnectOptions();
options.setCleanSession(true);
options.setUserName((String) configService.getArg("mqttUser"));
options.setPassword(((String) configService.getArg("mqttPassword")).toCharArray());
options.setConnectionTimeout(9999);
Log.d("MQTTCONN", "About to connect");
mqttClient.connect(options, null, new IMqttActionListener() {
@Override
public void onSuccess(IMqttToken asyncActionToken) {
Log.d("MQTTCONN", "Connect ready");
mqttClient.setCallback(new MqttCallback() {
@Override
public void connectionLost(Throwable cause) {
// Someday, in case we want to recover our service
}
@Override
public void messageArrived(String topic, MqttMessage message) throws Exception {
receiveMessageIntent.enact(
new JSONObject(new String(message.getPayload())),
pubsub
);
}
@Override
public void deliveryComplete(IMqttDeliveryToken token) {
}
});
try {
mqttClient.subscribe(getSubId().getSubId(), QOS);
} catch (MqttException e) {
e.printStackTrace();
}
}
@Override
public void onFailure(IMqttToken asyncActionToken, Throwable exception) {
Log.e("MQTTFAIL", exception.getMessage());
exception.printStackTrace();
}
});
故障排除我已尝试过:
application
标记之前设置适当的Android权限(但我不使用持久性,因此它只需要互联网)MqttConnectOptions.MQTT_VERSION_3_1
ssl://
答案 0 :(得分:0)
对于将来可能偶然发现的人 - MQTT是一个相当简单,无障碍的协议。像这样的问题最有可能发生在服务器端。
就我而言,很可能 CloudMQTT的免费层连接/使用限制导致了这个问题。花了很多时间试图弄清楚Paho的胆量,我只是简单地使用一个方便的Ansible角色和AWS来运行我自己的Mosquitto实例,并且事情就像他们应该在几个小时前一样膨胀: - )
答案 1 :(得分:0)
我不使用CloudMQTT作为经纪人,但我遇到了与此不同的经纪人(RabbitMQ)的问题。在更改了持久(qos1 +)队列的TTL之后,我不得不删除所有现有队列并让客户端重新创建它们。推测改变clientid也会起作用。