Kotlin - AWS IoT Core(Subscribe issue)
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
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?
Thanks @mattcreaser for the response. Callback receives success for each topics. Although not getting the messages for few subscribed topics.
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
@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?
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.