vaj oja
vaj oja

Reputation: 1161

mosquitto mqtt got too many publishes in progress error

We use mosquitto in our project to connect our IoT devices to cloud.

However, we always got "too many publishes in progress" error when there are only 30 devices(The server has 3.1 CPU and 8G RAM).

We tried setting the qos to 0,1,2. However, none worked.

Can anyone give some advices how to fix it?

publishmesssage

public static void publishMessage(MqttPubMsg config) {
    String clientId = MqttClient.generateClientId();
    MemoryPersistence persistence = new MemoryPersistence();

    MqttClient sampleClient = new MqttClient(config.getBroker(), clientId, persistence);
    MqttConnectOptions connOpts = new MqttConnectOptions();
    connOpts.setCleanSession(true);
    connOpts.setUserName(config.getUsername());
    connOpts.setPassword(config.getPassword().toCharArray());
    connOpts.setConnectionTimeout(mqttConnectTimeout);
    connOpts.setKeepAliveInterval(mqttKeppAliveInterval);

    sampleClient.connect(connOpts);
    MqttMessage message = new MqttMessage(config.getContent());
    message.setQos(0);
    sampleClient.publish(config.getTopic(), message);
    System.out.println("Message published");
}

mosquitto.conf

max_inflight_messages 0
max_queued_messages   0
max_connections -1

subscribemessage

public static void subscribeMessage(MqttSubMsg config) {
    System.out.println(config.getBroker());
    String clientId = MqttClient.generateClientId();

    MemoryPersistence persistence = new MemoryPersistence();

    MqttClient sampleClient = new MqttClient(config.getBroker(), clientId, persistence);
    MqttConnectOptions connOpts = new MqttConnectOptions();
    connOpts.setCleanSession(true);
    connOpts.setUserName(config.getUsername());
    connOpts.setPassword(config.getPassword().toCharArray());
    connOpts.setConnectionTimeout(mqttConnectTimeout);
    connOpts.setKeepAliveInterval(mqttKeppAliveInterval);

    System.out.println("run receive...");
    sampleClient.setCallback(new controllers.PushCallback());
    MqttTopic mtopic = sampleClient.getTopic(config.getTopic());
    connOpts.setWill(mtopic, "close".getBytes(), 0, true);
    sampleClient.connect(connOpts);

    int[] Qos = {0};
    String[] topic1 = {config.getTopic()};
    sampleClient.subscribe(topic1, Qos);
}

Upvotes: 0

Views: 1322

Answers (2)

Alexander Farber
Alexander Farber

Reputation: 23018

Let me show, how to solve such problems yourself -

Open the Github web page for Paho client and search for the "too many publishes in progress":

browser screenshot

This leads you to the "32202" string, search for it again.

This leads you (after skipping few localization files) to the constant in the Java source code file MqttException.java:

public static final short REASON_CODE_MAX_INFLIGHT = 32202;

And again, search for the "REASON_CODE_MAX_INFLIGHT" - which finally brings you to the file ClientState.java:

    if (actualInFlight >= this.maxInflight) {
        //@TRACE 613= sending {0} msgs at max inflight window
        log.fine(CLASS_NAME, methodName, "613", new Object[]{new Integer(actualInFlight)});

        throw new MqttException(MqttException.REASON_CODE_MAX_INFLIGHT);
    }

So you need to adjust the maxInflight property.

Few more searches and you find out that it can be set by calling the setMaxInflight(int maxInflight) method on an MqttConnectionOptions object that you pass to the connect method of a Paho client.

Upvotes: 2

ralight
ralight

Reputation: 11618

This is nothing to do with mosquitto, it is the client you are using. See this answer: Send many publish message: Too many publishes in progress Error

Upvotes: 1

Related Questions