timeout – In Android MQTT how to Cancel a Publish request

I am using this Mqtt library in Android:

api 'com.github.hannesa2:paho.mqtt.android:4.1'

I am able to publish requests like this:

import org.eclipse.paho.client.mqttv3.*
...
val message = MqttMessage()
message.payload = msg.toByteArray()
message.qos = qos
message.isRetained = retained

mqttClient?.publish(topic, message)

I have 2 questions regarding this:

  1. After certain user action, I want to cancel the publish request if Mqtt hasn’t yet published successfully, or it is retrying due to slow internet. How to cancel a publish request?
  2. How to set timeout for publish request? So that I know that after THIS many seconds Mqtt will not try to publish again.

Read more here: Source link