发送许多发布消息:进行中的发布过多错误 [英] Send many publish message: Too many publishes in progress Error

查看:1719
本文介绍了发送许多发布消息:进行中的发布过多错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是paho异步客户端:

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

错误:

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)

我正在使用Rabbitmq

推荐答案

查看

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

因此,考虑到您的发布循环有多么紧密,在网络层上的传输速度只会稍有降低,并且在任何给定时间发送过程中最终将收到10条以上的消息.如果您尝试以大于0的QOS进行发送,这只会变得更糟.

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.

您可以使用传递给client.connect()方法的MQTTConnectionsOptions对象上的setMaxInflight(int n)方法更改默认设置.

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.

这篇关于发送许多发布消息:进行中的发布过多错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆