java.io.EOFException with paho

不羁岁月 提交于 2019-12-09 05:54:37

问题


i want to make stress test on mosquitto, so i create some code as below

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!

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:

1383736170: Socket read error on client Server-82, disconnecting.

Please help me, thanks!


回答1:


I got this exact same error using code similar to above. I found that changing the QOS to 0 fixed the problem.

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




回答2:


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.




回答3:


client id is the problem, generating a random test

MqttClient.generateClientId ();



回答4:


There's a 1024 files/sockets limit in linux but you can upset it,ulimit -n 4096 see: mqtt mosquitto linux connection limit




回答5:


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.

I also had to do as @Aidan said and reduce the QoS from 2 to 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:

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.




回答6:


Sometimes it happen when you will try to send large data set. Try to decrease dataset size. It solved problem in my case.




回答7:


The solution is add 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.



来源:https://stackoverflow.com/questions/19813101/java-io-eofexception-with-paho

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