最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to get all topics in MQTT? - Stack Overflow

programmeradmin5浏览0评论

I have two questions:

1) How do I get a list of all the topics and perform certain actions in the browser, depending on whether a particular topic is open or not?

2) I join a broker and subscribe to his topics. But it updates the data once a minute. Respectively, the data in the browser is updated once a minute (I go to the page and see the old data, which is updated within a minute). Is it possible to somehow force the broker to return the data to me immediately after the subscription?

P.S. I'm using MQTT.JS

I have two questions:

1) How do I get a list of all the topics and perform certain actions in the browser, depending on whether a particular topic is open or not?

2) I join a broker and subscribe to his topics. But it updates the data once a minute. Respectively, the data in the browser is updated once a minute (I go to the page and see the old data, which is updated within a minute). Is it possible to somehow force the broker to return the data to me immediately after the subscription?

P.S. I'm using MQTT.JS

Share Improve this question edited Oct 15, 2019 at 16:20 ResponsiblyUnranked 1,8763 gold badges22 silver badges37 bronze badges asked Oct 15, 2019 at 15:44 user9675246user9675246 431 gold badge1 silver badge6 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 5
  1. No, because topics are effectively ephemeral, they only exist at the point a client publishes to them. At that point the broker looks down the list of topic patterns that all the connected clients have requested and sends that message to those that match. The closest you can do is subscribe to the topic pattern # which will mean you see all messages (but only when they are published). # is a global wildcard that will match multiple levels (it must always go at hte end of a topic pattern and can only match whole levels), there is also the + wildcard that matches a single level in a topic. This blog post explains how wildcards work in more detail: https://www.hivemq./blog/mqtt-essentials-part-5-mqtt-topics-best-practices/

  2. What you are looking for is called retained messages. Retained messages have a flag in the message header. When the broker sees this flag it will cache this message and deliver it at the point a new client subscribes to that topic before any other messages. This flag can only be set by the publisher at the point the message is published. The following blog post explains retained messages: https://www.hivemq./blog/mqtt-essentials-part-8-retained-messages/

发布评论

评论列表(0)

  1. 暂无评论