thingsboard / thingsboard-edge

Apache License 2.0
100 stars 74 forks source link

Edge MQTT publish and subscribe to same topic #10

Closed ricktauss closed 2 years ago

ricktauss commented 2 years ago

Edge MQTT broker

Description Is it possible to publish and subscribe to the same topic with one client? The only possible topic for subscribing is following: v1/devices/me/attributes

If a message is sent to the topic, there is no reply also when subscribed.

What could be the problem here?

6

volodymyr-babak commented 2 years ago

@ricktauss hello, TB edge and server MQTT broker is not a regular broker by design. Implementation based on netty MQTT framework with following most of the MQTT protocol design documents, but TB edge and server brokers are not providing regular publish/subscribe models. So you can't just subscribe to one topic and send the message to the same topic from another client and expect the result to arrive in the initial subscribed client. The possible subscribe / publish topics are available here: https://thingsboard.io/docs/reference/mqtt-api/

Please let me know if that answers your question.

ricktauss commented 2 years ago

@volodymyr-babak Is the topic fixed? In the documentation (https://thingsboard.io/docs/reference/mqtt-api/#subscribe-to-attribute-updates-from-the-server) there is explained that you can subscribe to the following topic: "v1/devices/me/attributes". I thought the topic is just a sample topic for documentation.

What i generally want to do is to measure the round trip time from device over tb-edge to tb-server. So i wanted to publish and subscribe with one client to any topic to mirror the message back. Maybe it is also better to make rule which mirros or publishes the message back to the client.

volodymyr-babak commented 2 years ago

@ricktauss 'v1/devices/me/attributes' is a hardcoded topic name. You cannot subscribe to any topic, except the one, that is hardcoded. Here is the list of these topics: https://github.com/thingsboard/thingsboard/blob/master/common/transport/mqtt/src/main/java/org/thingsboard/server/transport/mqtt/MqttTransportHandler.java#L606

Here is the steps that you should do in your test case:

  1. Subscribe to topic 'v1/devices/me/attributes' from the device.
  2. Publish any timeseries or attribute message from the device.
  3. Send this message to the cloud. Here is a sample how to configure edge root rule chain to publish message to the cloud: https://thingsboard.io/docs/edge/use-cases/data-filtering-traffic-reduce/#configure-edge-rule-engine-to-push-filtered-data-to-the-cloud
  4. On the cloud modify root rule chain to send back some attributes update message to the edge. You should use 'push to edge' node for this image
  5. Once the attribute update message will arrive to the edge you should see this message on the device.
ricktauss commented 2 years ago

@volodymyr-babak Ok if is hardcoded it is also fine. Thank you for the instruction!