aws / aws-iot-device-sdk-java-v2

Next generation AWS IoT Client SDK for Java using the AWS Common Runtime
Apache License 2.0
116 stars 76 forks source link

MQTT subscriber stops consuming messages after some inactivity time #246

Closed agupta0105 closed 2 years ago

agupta0105 commented 2 years ago

Describe the issue

I have been running a service which is based on this sdk. This service connects to MQTT broker using certs and AwsIotMqttConnectionBuilder to get the connection object. Lately I am observing that subscriber stops consuming messages from the broker even though there are messages getting published. It happens only when there is an inactivity time gap b/w messages.

I have checked the trace logs of sdk but could not find anything which can give details on this subscriber issue. Only way to solve this is to restart that connection/service.

Below are the details:

<dependency>
            <groupId>software.amazon.awssdk.iotdevicesdk</groupId>
            <artifactId>aws-iot-device-sdk</artifactId>
            <version>1.6.1</version>
        </dependency>

JDK : 1.8

Steps to Reproduce


private final Runnable mqttConsumerTask = new Runnable() {
        @Override
        public void run() {
            try {
                connection.subscribe(Constants.TOPIC, QualityOfService.AT_MOST_ONCE, mqttConsumer);
            } catch (Exception e) {
                logger.error("Error while subscribing the topic {}", Constants.TOPIC_CMD_RESP);
            }
        }
    };

    private final Consumer<MqttMessage> mqttConsumer = new Consumer<MqttMessage>() {
        @Override
        public void accept(MqttMessage msg) {
            ....
        }
    };

    private void startMsgReceiver() {
        asyncExecutors.execute(mqttConsumerTask);

    }


### Current behavior

_No response_

### aws-iot-device-sdk-java-v2 version used

1.6.1

### JDK version used

openjdk version "1.8.0_252" OpenJDK Runtime Environment (build 1.8.0_252-b09) OpenJDK 64-Bit Server VM (build 25.252-b09, mixed mode)

### Operating System and version

Ubuntu 5.4.0-1024-aws #24-Ubuntu SMP Sat Sep 5 06:19:55 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
bretambrose commented 2 years ago

As it stands this is too vague to be very actionable. My suggestion would be to use wireshark or a similar tool to verify that the client/connection is actually receiving packets. Even better would be to verify/repro against a local mosquitto install where you could use a plaintext connection and see the packet internals. If you can repro under such circumstances and verify that you are receiving the packets but not getting callbacks, then please also include the trace logs and packet timings.