Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kotlin - AWS IoT Core(Subscribe issue) #3653

Open
veer9002 opened this issue Jan 3, 2025 · 5 comments
Open

Kotlin - AWS IoT Core(Subscribe issue) #3653

veer9002 opened this issue Jan 3, 2025 · 5 comments
Labels
bug Something isn't working iot Issues with the AWS Android SDK for Internet of Things (IoT)

Comments

@veer9002
Copy link

veer9002 commented Jan 3, 2025

Subscribed topics are not getting data from MQTT
After successful connection, I am trying to connect 300 topics using for-loop. But I am receiving data from 80 topics then sometimes 60 topics. It is happening randomly so I am not able to debug it from Android Studio.

To Reproduce
A code sample or steps:

 fun subscribe(context: Context, topic: AWSTopics, awsMqttListener: MqttActionListener) {
        awsIotMqttManager.subscribeToTopic(topic.topicPath, AWSIotMqttQos.QOS1, object :
            AWSIotMqttSubscriptionStatusCallback {
            override fun onSuccess() {
                LogManager.genericMessage("subscribeToTopic ${topic.topicPath} success")
                awsMqttListener.onSuccess()
            }

            override fun onFailure(exception: Throwable?) {
                LogManager.genericMessage("subscribeToTopic $topic failed")
                awsMqttListener.onFailed()
            }

        }) { topicOnMessage, data ->
            val jsonObject = data?.toString(Charsets.UTF_8)?.let { JSONObject(it) }
            LogManager.genericMessage(
                context,
                "AWS onMessageArrived - Topic - $topicOnMessage || message ${
                    jsonObject?.toString(4)
                }"
            )
            val mqttMessage = MqttMessage()
            mqttMessage.payload = data
            try {
                val messageArrived = MessageArrived(mqttMessage, topicOnMessage)
                // Get a handler that can be used to post to the main thread
                val mainHandler = Handler(Looper.getMainLooper());

                mainHandler.post {
                    messageReceivedLiveData.value = messageArrived
                }
            } catch (e: Exception) {
                e.printStackTrace()
            }
        }
    }

Subscribe code below:

  fun subscribeToEvents(vehicleIds: List<PairedResponse.Data.Item.AssignVehicleId>, isReconnect: Boolean = false) {
        // Sort and filter vehicle IDs
        val sortedVehicleIds = vehicleIds.map { it.ab_id }.sorted()
        Log.e("Sorted Array", "SORTED VEHICLES ::: $sortedVehicleIds")

        // Subscribe to each vehicle topic sequentially
        for ((position, item) in sortedVehicleIds.withIndex()) {
            println("Position: $position, Vehicle abId: $item")
            subscribeToTopicsSequentially(item)
        }
    }

Topics code:

sealed class AWSTopics(val topicPath: String) {
    class EventLive(abId: String) : AWSTopics("topicName1/$abId")
    class ManualResolveEvent(abId: String) : AWSTopics("topicName2/$abId")
    class PairedAsset(abId: String) : AWSTopics("topicName3/$abId")
    class Custom(topic: String) : AWSTopics(topic)
}

Which AWS service(s) are affected?
AWS IoT Core

Expected behavior
Expected result should be that once I subscribed to all 300+ topics, I will receive the data from all 300+ topics.

Environment Information (please complete the following information):

  • AWS Android SDK Version: Android sdk version is v2.77.1
  • Device: All devices
  • Android Version: 8.0+ android versions
  • Specific to simulators: No
@github-actions github-actions bot added pending-triage Issue is pending triage pending-maintainer-response Issue is pending response from an Amplify team member labels Jan 3, 2025
@mattcreaser
Copy link
Member

Thanks for your report @veer9002. For IoT we strongly recommend you use the AWS IoT Device SDK for Java v2 - that library is actively maintained and you will be able to get better support there. There is documentation about using that library on Android to help you get started. It's possible that your issue is already resolved in that newer library.

In terms of this specific issue, do you see the failure callback triggered for the topics that don't receive updates?

@github-actions github-actions bot removed the pending-maintainer-response Issue is pending response from an Amplify team member label Jan 3, 2025
@mattcreaser mattcreaser added bug Something isn't working iot Issues with the AWS Android SDK for Internet of Things (IoT) pending-community-response Issue is pending response from the issue requestor and removed pending-triage Issue is pending triage labels Jan 3, 2025
@veer9002
Copy link
Author

veer9002 commented Jan 6, 2025

Thanks @mattcreaser for the response.
Callback receives success for each topics. Although not getting the messages for few subscribed topics.

@github-actions github-actions bot added pending-maintainer-response Issue is pending response from an Amplify team member and removed pending-community-response Issue is pending response from the issue requestor labels Jan 6, 2025
@tylerjroach
Copy link
Member

Is it possible you are bumping up against a quota? https://docs.aws.amazon.com/general/latest/gr/iot-core.html

I'm seeing a subscriptions per connection limit at 50

@github-actions github-actions bot removed the pending-maintainer-response Issue is pending response from an Amplify team member label Jan 6, 2025
@mattcreaser mattcreaser added the pending-community-response Issue is pending response from the issue requestor label Jan 7, 2025
@veer9002
Copy link
Author

veer9002 commented Jan 13, 2025

@tylerjroach Thanks for the response.
I am also expecting it is bumping up, but am receiving the messages from the topic number 82-99 sometimes, if it is a limit then why it is happening?

@github-actions github-actions bot added pending-maintainer-response Issue is pending response from an Amplify team member and removed pending-community-response Issue is pending response from the issue requestor labels Jan 13, 2025
@tylerjroach
Copy link
Member

This is something I wouldn't be able to answer and it may be best to reach out to IoT service team if it appears you may be running into a quota issue. If the SDK appears to be working fine at < 50 subscriptions, it appears likely that the issue is some sort of quota being hit.

Are you not seeing any subscribeToTopic $topic failed messages? If you are, there is an exception you could be logging that may provide more context.

@github-actions github-actions bot removed the pending-maintainer-response Issue is pending response from an Amplify team member label Jan 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working iot Issues with the AWS Android SDK for Internet of Things (IoT)
Projects
None yet
Development

No branches or pull requests

3 participants