使用emqx发布消息过多报错,下面是报错问题

RuntimeException: 正在进行过多的发布 (32202)
at com.iot.protocol.service.impl.EmqxServiceImpl.sendDeviceUploadMsg(EmqxServiceImpl.java:38)
at com.iot.protocol.run.DeviceQueueConsumer.lambda$startConsumers$0(DeviceQueueConsumer.java:45)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)

建议找sdk 社区去反馈一下

解决方案

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.