简体   繁体   中英

Using ngx-mqtt in angular project not giving old data(behaves like hot observable)

I have used ngx-mqtt in angular project. There is another project which created data, and send data to particular topic.When im subscribing to this topic from angular application, i always get data from time of subscription whichever data is published later to topic.I m not getting old data which data source has published to topic before i subscribed to topic.

for example) data source created 1 to 10 data like 1,2,3,4,5,6,7,8,9,10 new subscriber is added to topic(using angular app if i subscribe) after emitting 5 data point.. I m getting data from 6(6,7,8,9,10) but i need data from 1 to 10

How to get all data from topic, whenever i subscribe to any new topic

Is this default way mqtt behaves?

In angular i hav heard about hot and cold observables. Is it possible to make mqtt behave as cold observable? (send all data whenever new subscriber s subscribed)

Use shareReplay() operator which is for these kind of scenarios all the late subscribes will get all the values emitted. https://www.learnrxjs.io/learn-rxjs/operators/multicasting/sharereplay

MQTT will only queue data for clients with a persistent session (See the HiveMQ blog post for details on persistent sessions).

This means the client needs to have already been connected to the broker and subscribed to the topic in question at QOS 1 or 2.

When it reconnects it needs to use the same client id and make sure that the clean session flag is set to false.

MQTT is a pub/sub protocol, not a generic message queuing system.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM