如何解决MQTT 的可靠性?
我正在开发一个 Uber 应用程序风格 (android),客户端/司机应用程序,他将在客户端和司机之间进行通信。
我将 RabbitMQ 用于 MQTT。以及适用于 android 的 paho 库。
implementation 'org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.2.5'
implementation 'org.eclipse.paho:org.eclipse.paho.android.service:1.1.1'
通信例如: 向司机发送行程请求, 接受司机的搭车, 由司机或客户取消行程, ...
为了进行客户端/驱动程序通信,我使用了 MQTT 协议。
我遇到的问题是有时消息无法到达收件人,例如比赛取消。即使我使用 QOS = 2 订阅主题或发送主题也是如此。
不使用此协议传递(或发送)消息是正常行为吗?
我对MQTT技术的选择感到疑惑。
Voici avec je me connecte :
private MqttConnectOptions createMqttConnectOptions() {
mqttConnectOptions = new MqttConnectOptions();
mqttConnectOptions.setAutomaticReconnect(true);
mqttConnectOptions.setCleanSession(false);
mqttConnectOptions.setKeepAliveInterval(0);
mqttConnectOptions.setConnectionTimeout(0);
mqttConnectOptions.setServerURIs(MQTT_SERVERS_URL);
mqttConnectOptions.setUserName(MQTT_USERNAME);
mqttConnectOptions.setPassword(MQTT_PASSWORD.toCharArray());
return mqttConnectOptions;
}
private MqttAndroidClient createMqttAndroidClient(String serveurUri) {
return mqttAndroidClient = new MqttAndroidClient(this,serveurUri,id,new MemoryPersistence());
}
public void connect(MqttConnectOptions mqttConnectOptions) {
try {
if (!mqttAndroidClient.isConnected()) {
final IMqttToken token = mqttAndroidClient.connect(mqttConnectOptions);
token.setActionCallback(new IMqttActionListener() {
@Override
public void onSuccess(IMqttToken asyncActionToken) {
DisconnectedBufferOptions disconnectedBufferOptions = new DisconnectedBufferOptions();
disconnectedBufferOptions.setBufferEnabled(true);
disconnectedBufferOptions.setBufferSize(1000);
disconnectedBufferOptions.setPersistBuffer(false);
disconnectedBufferOptions.setDeleteOldestMessages(true);
mqttAndroidClient.setBufferOpts(disconnectedBufferOptions);
subscribeToTopic(2,Constants.MQTT_TOPIC_DRIVER_REQUEST + mqttAndroidClient.getClientId());
}
@Override
public void onFailure(IMqttToken asyncActionToken,Throwable exception) {
Log.e(TAG,"Failed to connect to: " + mqttAndroidClient.getServerURI());
}
});
}
} catch (MqttException e) {
Log.e(TAG,"At connect method",e);
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com(将#修改为@)