Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to help business systems perceive whether credentials are online in real time #127

Closed
baigod opened this issue Jun 19, 2024 · 4 comments
Assignees
Labels
question Further information is requested

Comments

@baigod
Copy link

baigod commented Jun 19, 2024

Component

  • Core

Description
We maintain a list of devices in our business system and create unique MQTT credentials for each device, matching them one-to-one with TBMQ credentials. Now, we want our business system to be able to know in real-time whether a device is online. What are the best practices or solutions for interacting with TBMQ to achieve this?

Environment

  • OS: docker
  • TBMQ: 1.3.0
@baigod baigod added the question Further information is requested label Jun 19, 2024
@dmytro-landiak
Copy link
Contributor

Hi @baigod!

Thank you for reaching out! You can achieve real-time monitoring of device statuses using the TBMQ API. The API allows you to check the online status of a device by querying its client session. Here's an example of how to do this using a curl command:

curl -X 'GET' \
  'https://HOSTNAME/api/client-session?clientId=CLIENT_ID' \
  -H 'accept: application/json' \
  -H 'X-Authorization: Bearer TOKEN'

Replace the HOSTNAME to your actual one and the CLIENT_ID parameter with the actual client ID of the device you want to check. The X-Authorization header should contain a valid JWT token for authentication.

In addition, you can choose another API like below:

curl -X 'GET' \
  'https://HOSTNAME/api/client-session?pageSize=100&page=0' \
  -H 'accept: application/json' \
  -H 'X-Authorization: Bearer TOKEN'

If you need further assistance or have any questions, feel free to ask!

@baigod
Copy link
Author

baigod commented Jun 20, 2024

Hi @baigod!

Thank you for reaching out! You can achieve real-time monitoring of device statuses using the TBMQ API. The API allows you to check the online status of a device by querying its client session. Here's an example of how to do this using a curl command:

curl -X 'GET' \
  'https://HOSTNAME/api/client-session?clientId=CLIENT_ID' \
  -H 'accept: application/json' \
  -H 'X-Authorization: Bearer TOKEN'

Replace the HOSTNAME to your actual one and the CLIENT_ID parameter with the actual client ID of the device you want to check. The X-Authorization header should contain a valid JWT token for authentication.

In addition, you can choose another API like below:

curl -X 'GET' \
  'https://HOSTNAME/api/client-session?pageSize=100&page=0' \
  -H 'accept: application/json' \
  -H 'X-Authorization: Bearer TOKEN'

If you need further assistance or have any questions, feel free to ask!

Thank you for your reply, but I think I prefer events like Connect Event and Disconnect Event in thingsboard. I can proactively inform the business system through Kafka or HTTP. Based on my estimation, when I have millions of devices connected to TBMQ, if I call through HTTP https://HOSTNAME/api/client-session The interface and timeliness may suffer significant losses.
I have an idea. Is it feasible for me to subscribe to topics such as tbmq.client.session. through a new subscription group to consume tbmq's session events, so that the business system can perceive real-time changes in device connection status?

@dmytro-landiak
Copy link
Contributor

@baigod,

Thank you for your feedback. Your approach of subscribing to tbmq.client.session topic for real-time session events is indeed better suited for your use case, especially with a large number of devices.

You can connect to Kafka with a separate process, creating a new consumer group to read from the tbmq.client.session topic. Please be aware of the payload format. We use Protobuf for serialization. You can find the object definition for ClientSessionInfoProto here.

I believe you understand the importance of staying up-to-date with the schema definition, which may not be the most convenient option. However, currently, we do not have any other mechanisms to send notifications about the status changes of the devices.

@dmytro-landiak
Copy link
Contributor

I am closing this issue due to inactivity. Please feel free to reopen it if you have any more questions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants