带有 paho 的 java.io.EOFException
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19813101/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
java.io.EOFException with paho
提问by tom
i want to make stress test on mosquitto, so i create some code as below
我想对 mosquitto 进行压力测试,所以我创建了一些代码如下
for (int i = 0; i < 800; i++) {
final int j = i;
Thread t = new Thread(new Runnable() {
@Override
public void run() {
System.out.println(j + " : ************");
try {
MqttClient client = new MqttClient("tcp://192.168.88.203", SERVER_CLIENTID_PREFIX + j);
client.connect();
MqttMessage message = new MqttMessage((j + ":me").getBytes());
message.setQos(2);
client.publish(TOPIC_PREFIX + j, message);
} catch (MqttSecurityException e) {
e.printStackTrace();
} catch (MqttException e) {
e.printStackTrace();
}
}
});
t.start();
}
But, I got some errors like EOFException
during run and some client is disconnect.
I want to know how many clients can publish messages at same time with one mosquitto server, and how can I make the stress test. Thanks!
但是,我EOFException
在运行期间遇到了一些错误,并且某些客户端断开连接。我想知道一个mosquitto服务器可以同时发布多少个客户端,以及如何进行压力测试。谢谢!
The detail exception is :
详细的例外是:
Connection lost (32109) - java.io.EOFException
at org.eclipse.paho.client.mqttv3.internal.CommsReceiver.run(CommsReceiver.java:162)
at java.lang.Thread.run(Thread.java:662)
Caused by: java.io.EOFException
at java.io.DataInputStream.readByte(DataInputStream.java:250)
at org.eclipse.paho.client.mqttv3.internal.wire.MqttInputStream.readMqttWireMessage(MqttInputStream.java:51)
at org.eclipse.paho.client.mqttv3.internal.CommsReceiver.run(CommsReceiver.java:121)
... 1 more
And I found some log from mosquitto server:
我从 mosquitto 服务器找到了一些日志:
1383736170: Socket read error on client Server-82, disconnecting.
Please help me, thanks!
请帮帮我,谢谢!
回答by Teixi
There's a 1024 files/sockets limit in linux but you can upset it,ulimit -n 4096
see:
mqtt mosquitto linux connection limit
linux 中有 1024 个文件/套接字限制,但您可以将其打乱,ulimit -n 4096
请参阅:
mqtt mosquitto linux connection limit
回答by Aidan
I got this exact same error using code similar to above. I found that changing the QOS to 0 fixed the problem.
我使用与上面类似的代码得到了完全相同的错误。我发现将 QOS 更改为 0 可以解决问题。
message.setQos(0);
[Edit] A bit more digging and I discovered that the MQTT plugin for RabbitMQ doesn't support a QOS of 2. http://www.rabbitmq.com/mqtt.html
[编辑]多一点挖掘,我发现MQTT插件RabbitMQ的不支持的2. QOS http://www.rabbitmq.com/mqtt.html
回答by Timmmm
In my case this was because I was accidentally using a tcp://...
URL instead of ssl://...
and the server was configured not to allow insecure connections.
就我而言,这是因为我不小心使用了tcp://...
URL 而不是,ssl://...
并且服务器被配置为不允许不安全的连接。
I also had to do as @Aidan said and reduce the QoS from 2 to 1.
我还必须按照@Aidan 所说的去做,将 QoS 从 2 降低到 1。
Edit: I'm not 100% sure, but I think the server I'm using is RabbitMQ, and that assigns a non-standard meaning to the QoS values. It's probably a more sensible meaning to be honest:
编辑:我不是 100% 确定,但我认为我使用的服务器是 RabbitMQ,它为QoS 值分配了一个非标准的含义。说实话,这可能是一个更合理的意思:
Transient (QoS0) subscription use non-durable, auto-delete queues that will be deleted when the client disconnects.
Durable (QoS1) subscriptions use durable queues. Whether the queues are auto-deleted is controlled by the client's clean session flag. Clients with clean sessions use auto-deleted queues, others use non-auto-deleted ones.
瞬态 (QoS0) 订阅使用非持久的、自动删除的队列,当客户端断开连接时,这些队列将被删除。
持久 (QoS1) 订阅使用持久队列。队列是否自动删除由客户端的干净会话标志控制。具有干净会话的客户端使用自动删除队列,其他客户端使用非自动删除队列。
回答by mastash3ff
My issue resulted from the clientId being the same for the publisher/subscriber. Was getting errors with Persistence datastore already being in use as well.
我的问题是由于发布者/订阅者的 clientId 相同。也正在使用持久性数据存储时出现错误。
回答by Gustavo Eduardo Belduma
client id is the problem, generating a random test
客户端 ID 是问题,生成随机测试
MqttClient.generateClientId ();
回答by Sakib Sami
Sometimes it happen when you will try to send large data set. Try to decrease dataset size. It solved problem in my case.
有时当您尝试发送大型数据集时会发生这种情况。尝试减小数据集大小。它解决了我的问题。
回答by Patricio Vergara
The solution is add MqttClient.generateClientId
解决方法是添加 MqttClient.generateClientId
MemoryPersistence persistence = new MemoryPersistence()
MqttClient client = new MqttClient("tcp://192.168.88.203",MqttClient.generateClientId(),persistence);
client.connect();
or
或者
MqttClient client = new MqttClient("tcp://192.168.88.203", MqttClient.generateClientId+SERVER_CLIENTID_PREFIX)
The identifier must be random. I had this problem in scala and that was my solution.
标识符必须是随机的。我在 Scala 中遇到了这个问题,这就是我的解决方案。