mqtt 发送消息过多,发送许多发布消息:进行中的发布过多错误

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

解决方案

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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值