在 emqx 订阅订阅更新

Subscribe to subscription updates in emqx

背景:我有一个用 C++ 实现的微服务,具有 REST 和 WebSocket API 以及发布/订阅功能。现在我需要支持 MQTT,事情变得更加复杂,因为出于可扩展性的原因,我的微服务必须跟踪活动订阅。例如,为了限制向主题和订阅传递消息,每个客户端可能有几个自己的主题。

我找到了 REST API 端点来列出订阅和路由: https://docs.emqx.io/broker/v3/en/rest.html#subscriptions

https://docs.emqx.io/broker/v3/en/rest.html#routes

这可能允许我在自己的服务中启动订阅。不过,我需要的是一种拦截订阅的有效方法。

有没有一种方法可以“订阅”已订阅和未订阅的事件挂钩,而无需在 Erlang 中编写扩展?例如。将这些事件转发到我的微服务可以作为 MQTT 客户端订阅的 MQTT 主题?

Emqx hooks 文档: https://docs.emqx.io/enterprise/latest/en/advanced/hooks.html

使用 emqx-web-hook:

https://github.com/emqx/emqx-web-hook

web.hook.rule.client.connect.1       = {"action": "on_client_connect"}
web.hook.rule.client.connack.1       = {"action": "on_client_connack"}
web.hook.rule.client.connected.1     = {"action": "on_client_connected"}
web.hook.rule.client.disconnected.1  = {"action": "on_client_disconnected"}
web.hook.rule.client.subscribe.1     = {"action": "on_client_subscribe"}
web.hook.rule.client.unsubscribe.1   = {"action": "on_client_unsubscribe"}
web.hook.rule.session.subscribed.1   = {"action": "on_session_subscribed"}
web.hook.rule.session.unsubscribed.1 = {"action": "on_session_unsubscribed"}
web.hook.rule.session.terminated.1   = {"action": "on_session_terminated"}
web.hook.rule.message.publish.1      = {"action": "on_message_publish"}
web.hook.rule.message.delivered.1    = {"action": "on_message_delivered"}
web.hook.rule.message.acked.1        = {"action": "on_message_acked"}