Implement XMPP Presence in MQTT

I am currently working on a project, a chat application that uses MQTT, where there are 3 clients A, B, C. When each client joins, they initially subscribe to 2 topics for A, his AB, AC, and B subscribes on AB, BC and c subscribe to t0 AC and BC. these are topics on which messages are sent and chat messages are received. Now I want to add presence support to let me know if the user is offline or online. Is there a built-in mechanism supported by the MQTT broker to achieve this.

+4
source share
1 answer

Some broker implementations may provide suitable interceptors for connection / disconnect events to enable this, but this is not a requirement for the protocol for brokers.

You can create a presence support system using the protocol features

You can read more here: https://github.com/mqtt/mqtt.imtqy.com/wiki/presence

In conclusion, when the client connects, he must define the message "Last Wish" 0for publication in the subject client/[client-id]with the flag saved. Then he must publish the message stored in the subject client/[client-id]with the value 1.

This means that anyone can subscribe to client/+and receive the current status of all known customers:

  • 1 client/A , A
  • 0 client/A , A

, , . , . - , .

+10

Source: https://habr.com/ru/post/1539082/


All Articles