Closed KMACEL closed 1 year ago
the process is not completed
How do you know? (what is the output from your test program?). The broker may well accept the subscription request and just not deliver any messages (that's what Mosquitto would do). Alternatively it may, in some cases, drop the connection.
I tried it with mosquitto_pub, mosquitto_sub, flutter. They all give an error
What error? (and if you have tested with these tools then it's beneficial to provide the full commands/responses).
Without a more info it's not really possible to help. As per the readme this section is really intended for bugs and you need to provide significantly more info (e.g. enable logging, provide broker information etc).
@MattBrittan Thank you so much for reply.
What error? (and if you have tested with these tools then it's beneficial to provide the full commands/responses).
Here are the feedbacks I got:
mosquitto_sub -h {{BROKER}} -p 1884 -t "{{TOPIC}}" -u ({{USER}}) -P ({{PASSWORD}})
All subscription requests were denied.
client.onSubscribeFail = (topic) {
conenctionStatus.value = ConenctionStatus.disconnected;
debugPrint("onSubscribeFail $topic");
};
I likewise in Go, I want to handle if unable to subscibe or send message due to an error.
[client] Connect()
[store] memorystore initialized
[client] about to write new connect msg
[client] socket connected to broker
[client] Using MQTT 3.1.1 protocol
[net] connect started
[net] received connack
[client] startCommsWorkers called
[client] client is connected/reconnected
[net] incoming started
[net] startIncomingComms started
[net] outgoing started
[net] startComms started
[client] startCommsWorkers done
[store] memorystore wiped
[client] exit startClient
[client] enter Subscribe
[net] outgoing waiting for an outbound message
[net] logic waiting for msg on ibound
[net] startIncomingComms: inboundFromStore complete
[net] logic waiting for msg on ibound
Connected : SetOnConnectHandler
[pinger] keepalive starting
[client] SUBSCRIBE: dup: false qos: 1 retain: false rLength: 0 MessageID: 1 topics: [846EF1D4-5259-511E-9E2C-31B3884265B9_AGENT_LISTEN]
[client] sending subscribe message, topic: 846EF1D4-5259-511E-9E2C-31B3884265B9_AGENT_LISTEN
[client] enter Publish
[client] exit Subscribe
[client] sending publish message, topic: 846EF1D4-5259-511E-9E2C-31B3884265B9_AGENT_ANSWER
[net] obound priority msg to write, type *packets.SubscribePacket
[net] outgoing waiting for an outbound message
[net] obound msg to write 2
[net] obound wrote msg, id: 2
[net] outgoing waiting for an outbound message
[net] startIncoming Received Message
[net] startIncomingComms: got msg on ibound
[store] memorystore del: message 1 not found
[net] startIncomingComms: received suback, id: 1
[net] startIncomingComms: granted qoss [128]
[net] logic waiting for msg on ibound
Subscribe Successfull
[net] startIncoming Received Message
[net] startIncomingComms: got msg on ibound
[store] memorystore del: message 2 was deleted
[net] startIncomingComms: received puback, id: 2
[net] logic waiting for msg on ibound
``
That's all as expected. The subscription request was successfully processed (i.e. the broker received the request and responded). It's subjective whether a failure response from the broker is an error or not (it's a valid response!) and this library does not treat it as an error (that would get confusing when there are multiple subscriptions in the one request).
If you want to check what action the broker took then you need to check the result i.e.:
token := client.Subscribe(topic, qos, msgHandler)
if token.Wait() && token.Error() != nil {
panic(err)
}
m := token.(*MQTT.SubscribeToken).Result()
if m == nil {
panic("unexpected token type)")
}
result := m.Result()
// Result will be a `map[string]byte` where the `string` is the topic and the `byte` is the QOS level the broker granted (or `128` if the broker reported a failure).
@MattBrittan Thank you so much for reply. It is work for me.
Hi.
I have a broker. {{USER}} is not authorized to any topic at my broker. But when I subscribe or send a message to a topic, the process is not completed. But it doesn't give any error either.
I was wondering if it's a problem with the broker and I tried it with mosquitto_pub, mosquitto_sub, flutter. They all give an error. If I could not subscribe to a topic or send the message, how can I handle this situation?