mochi-mqtt / server

The fully compliant, embeddable high-performance Go MQTT v5 server for IoT, smarthome, and pubsub
MIT License
1.29k stars 222 forks source link

[ask] Subscribe topic without create client #277

Closed annlumia closed 1 year ago

annlumia commented 1 year ago

How to subscribe to certain topics directly without using MQTT Client anymore?

As for publishing messages, I can use

server. Publish(topic, payload, false, 0)
werbenhu commented 1 year ago

Are you suggesting that you want to subscribe to topics directly on the Mochi broker side? Why would there be a need to subscribe to topics on the server? If you have such a requirement, you can create your own hook plugin and handle the messages you want to subscribe to within the OnPublish() interface of the hook. You can refer to the ExampleHook in the examples directory: https://github.com/mochi-mqtt/server/blob/main/examples/hooks/main.go

annlumia commented 1 year ago

I have such a need for an application I am developing, including to monitor the health status of microservices.

Hahaha, the hook seems to fit, I didn't think of it before, thanks for the suggestion.