B4J Question MQTT Subscribe Suback

lip

Active Member
Licensed User
Longtime User
Does the B4J MQTT Library use Suback to confirm that subscription was successful? What happens if not? Is there any way to listen for the Suback and check the response? I'm trying to debug a situation where Subscribe does not throw any error, but subsequent messages published to the same topic do not fire. This is probably due to something I've got wrong with using a CA certificate, but being able to see if the response to Subscribe would be useful. I can see the Subscribe event on the Broker's logs, but not its response.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Code to get the subscription response:
B4X:
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
    mqtt.Initialize("mqtt", "tcp://localhost:51044", "ttt")
    mqtt.Connect
    Wait For mqtt_Connected (Success As Boolean)
    If Success Then
        SubscribeWithActionListener("test", mqtt.QOS_2_EXACTLY_ONCE)
    End If
End Sub

Private Sub SubscribeWithActionListener(Topic As String, QOS As Int)
    Dim client As JavaObject = mqtt.As(JavaObject).GetField("client")
    Dim ActionListener As Object = client.CreateEventFromUI("org.eclipse.paho.client.mqttv3.IMqttActionListener", "ActionListener", Null)
    client.RunMethod("subscribe", Array(Topic, QOS, Null, ActionListener))
    Wait For ActionListener_Event (MethodName As String, Args() As Object)
    Log(MethodName & ": " & Args.As(List))
    If MethodName = "onSuccess" Then
        Dim token As JavaObject = Args(0)
        Dim grantedQos() As Int = token.RunMethod("getGrantedQos", Null)
        Log(grantedQos(0))
    End If
End Sub

I think that the grantedQos will be 128 when it fails.
 
Upvote 0
Top