0

背景:我有一个用 C++ 实现的微服务,带有 REST 和 WebSocket API 以及 pub/sub 功能。现在我需要支持 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

4

1 回答 1

2

使用 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"}
于 2020-05-20T05:43:05.953 回答