Subscribing to topics and understanding notification events in Java
The onSuccess method prints a message indicating that the client has successfully connected with the MQTT server and then calls the mqttAsyncClient.subscribe
method with topic_for_led01
as the argument that specifies the topic filter to subscribe to 0
for the argument that specifies the desired QoS level, null
for the userContext
argument, and another anonymous class that implements the IMqttActionListener
interface as the value for the callback
argument. As happened with the connect
method, the subscribe
method requires the callback
argument of the org.eclipse.paho.client.mqttv3.IMqttActionListener
type. The anonymous class provides implementations for the previously explained two methods required by the IMqttActionListener
interface: onSuccess
and onFailure
.
The code in the onSuccess
method prints a message indicating that the client has subscribed to the topic filter and the granted QoS level. The asyncActionToken.getGrantedQoS...