这是paho Async客户端:
client = new MqttAsyncClient(appProps.getProperty("mqtt.broker"),
appProps.getProperty("mqtt.clientId"), new MemoryPersistence());
client.setCallback(this);
client.connect(null, new IMqttActionListener() {
@Override
public void onSuccess(IMqttToken imt) {
try {
client.subscribe(Constants.internalTopics, Constants.internalTopicQOS);
} catch (MqttException ex) {
ex.printStackTrace();
}
}
@Override
public void onFailure(IMqttToken imt, Throwable thrwbl) {
thrwbl.printStackTrace();
}
});
Run Code Online (Sandbox Code Playgroud)
我在这里循环发送消息:
while (iterator.hasNext()) {
try {
client.publish("user/" + userId + "/downstream", mqttMessage);
} catch(Exception ex) {
ex.printStackTrace();
}
}
Run Code Online (Sandbox Code Playgroud)
错误:
Too many publishes in progress (32202)
at org.eclipse.paho.client.mqttv3.internal.ClientState.send(ClientState.java:436)
at org.eclipse.paho.client.mqttv3.internal.ClientComms.internalSend(ClientComms.java:121)
at org.eclipse.paho.client.mqttv3.internal.ClientComms.sendNoWait(ClientComms.java:139)
at org.eclipse.paho.client.mqttv3.MqttAsyncClient.publish(MqttAsyncClient.java:858)
at org.eclipse.paho.client.mqttv3.MqttAsyncClient.publish(MqttAsyncClient.java:836)
Run Code Online (Sandbox Code Playgroud)
我在用 …