halfgaar / FlashMQ

FlashMQ is a fast light-weight MQTT broker/server, designed to take good advantage of multi-CPU environments
https://www.flashmq.org/
Open Software License 3.0
186 stars 23 forks source link

Plugins can't publish to `$SYS` topics #112

Open bigsmoke opened 2 months ago

bigsmoke commented 2 months ago

It would be nice if plugins could publish to $SYS topics, for plugin-specfic stats.

bigsmoke commented 2 months ago

Bonus point if this can be done from non-worker threads.

halfgaar commented 2 months ago

One issue with publishing directly to $SYS is that the topics appear at a different time from FlashMQ's own $SYS topics. What we can perhaps do, is expose GlobalStats::setExtra to the plugin. That also takes care of the publishing from any thread.

bigsmoke commented 2 months ago

I haven't quite glanced the overall role of GlobalStats yet. Are all these stats published simultaneously, with the same flags in terms of retention and such? If that's the case, I think that what you propose would be just what's needed for writing $SYS topics from plugins.

bigsmoke commented 2 months ago

Although I could think of scenarios in which plugins would want to GlobalStats.setExtra() at a higher frequency than that the whole GlobalStats collection is published, I can't think of a scenario in which it matters (much) if the occasional intermediate stat is missed. I'm guessing that at the very least your idea will be more than sufficient for the majority of cases. And otherwise it might still be preferable to up the GlobalStats publish frequency rather than making it possible for plugins to directly publish to $SYS topics.