I’m a newb building an Android app using HiveMQ to communicate with an IoT broker.
My stand-alone unit test works great: I can subscribe to a topic, publish a message, and see the response come into my subscription callback:
Mqtt3AsyncClient mqttClient = ...
mqttClient.subscribeWith()
.topicFilter(this.clientResponseTopic)
.callback(published -> {
Log.d(TAG, "subscribe: callback: enter");
String string = new String(published.getPayloadAsBytes(), StandardCharsets.UTF_8);
Log.d(TAG, "subscribe: callback: topic=" + published.getTopic() + "\n" + string);
})
.send()
.whenComplete((ack, exception) -> {
if(exception == null) {
Log.d(TAG, "subscribe: success");
}
else {
Log.w(TAG, "subscribe: failure", exception);
}
});
// ... on to publishing a message to broker
// ... that causes it to publish a message back to my subscription
And the unit test logs show the output:
subscribe: success
subscribe: callback: enter
subscribe: callback: topic=/app/2208401-0744fb78a23042d1fada1647c1a8576e/subscribe
However, when I run my App, I can see the subscription request sent successfully, but I never ever hear any messages in my callback:
subscribe: success
... (crickets) ...
I’ve tested both in an emulator, and on my personal device.
I’ve read the HiveMQ Andriod Guide, and I’ve checked all of that twice.
I feel like something is either blocking responses from coming in, or Android is killing whatever it is HiveMQ stands up to listen for responses.
If someone can suggest what I might be doing wrong, I’d appreciate it. If not, I’d also appreciate any HiveMQ/Android debug/diagnostic/triage tips. I’ve already added org.slf4j:slf4j-android:1.7.30
to my Gradle project in hopes of getting HiveMQ’s logging to show up, but it seems that is flawed.