Send many publish message: Too many publishes in progress Error

丶灬走出姿态 提交于 2019-12-30 11:24:48

问题


Here is paho Async client:

    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();
        }
    });

Here I am sending messages in loop:

        while (iterator.hasNext()) {
            try {
               client.publish("user/" + userId + "/downstream", mqttMessage);
            } catch(Exception ex) {
                ex.printStackTrace();
            }
        }

Error:

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)

I am using Rabbitmq


回答1:


Looking at the source for the Paho client it looks like the default maximum number of inflight messages at any given time is 10.

So given how tight your publish loop is it will only take a small slow down in the network layer and your going to end up with more than 10 messages in the process of being sent at any given time. This will only get worse if you try to send at a QOS greater than 0.

You can change the default with the setMaxInflight(int n) method on the MQTTConnectionsOptions object that is passed to the client.connect() method.

I suggest you experiment to find a suitable value.



来源:https://stackoverflow.com/questions/38751546/send-many-publish-message-too-many-publishes-in-progress-error

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!