问题描述
我正在通过Web套接字使用Paho Android Service for MQTT.
I am using Paho Android Service for MQTT over web sockets.
https://www.hivemq.com /blog/mqtt-client-library-enyclopedia-paho-android-service
我的问题是如何设置其中具有查询参数的Broker WSS URI.
My question is how do I set the Broker WSS URI which has a query parameter in it.
例如: wss://test.amazon.com:80/mqtt?query1 = value& query2 = value
修改
如果添加完整的URL,则PAHO客户端库将引发以下异常:
If we add the complete URL, the PAHO client library throws following exception:
MqttException (0) - java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String java.lang.String.toLowerCase()' on a null object reference
W/System.err: at org.eclipse.paho.client.mqttv3.internal.ExceptionHelper.createMqttException(ExceptionHelper.java:38)
W/System.err: at org.eclipse.paho.client.mqttv3.internal.ClientComms$ConnectBG.run(ClientComms.java:664)
W/System.err: at java.lang.Thread.run(Thread.java:761)
W/System.err: Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String java.lang.String.toLowerCase()' on a null object reference
W/System.err: at org.eclipse.paho.client.mqttv3.internal.websocket.WebSocketHandshake.receiveHandshakeResponse(WebSocketHandshake.java:133)
W/System.err: at org.eclipse.paho.client.mqttv3.internal.websocket.WebSocketHandshake.execute(WebSocketHandshake.java:74)
W/System.err: at org.eclipse.paho.client.mqttv3.internal.websocket.WebSocketSecureNetworkModule.start(WebSocketSecureNetworkModule.java:77)
W/System.err: at org.eclipse.paho.client.mqttv3.internal.ClientComms$ConnectBG.run(ClientComms.java:650)
编辑2
CLIENT = new MqttAndroidClient(this, "wss://test.amazon.com:80/mqtt?query1=value&query2=value", clientId, new MemoryPersistence());
CLIENT.setCallback(this);
MQTT_CONNECTION_OPTIONS = new MqttConnectOptions();
MQTT_CONNECTION_OPTIONS.setCleanSession(true);
try {
IMqttToken token = CLIENT.connect(MQTT_CONNECTION_OPTIONS);
token.setActionCallback(new IMqttActionListener() {
@Override
public void onSuccess(IMqttToken asyncActionToken) {
Log.v("tag", "onsuccess");
}
@Override
public void onFailure(IMqttToken asyncActionToken, Throwable exception) {
exception.printStackTrace();
}
});
} catch (MqttException e) {
e.printStackTrace();
}
推荐答案
更改版本
编译'org.eclipse.paho:org.eclipse.paho.client.mqttv3: 1.1.0 '
compile 'org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.1.0'
到
编译'org.eclipse.paho:org.eclipse.paho.client.mqttv3: 1.2.0 '
compile 'org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.2.0'
解决了此问题.他们已在v1.2.0中修复了此问题
resolved this issue. They have fixed this issue in v1.2.0
这篇关于Android中的Websockets上的MQTT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!