在 Eclipse-hono 中使用通配符订阅所有租户

Subscribe to all tenants using a wildcard in Eclipse-hono

我正在尝试使用来自 hono 的数据。我按照 hono 文档中 Starting a consumer 上的指南进行操作。
我目前正在尝试通过在 mvn 命令末尾添加 --tenant.id=* 来订阅所有租户。这导致以下命令:

mvn spring-boot:run -Drun.arguments=--hono.client.host=localhost,--hono.client.username=consumer@HONO,--hono.client.password=verysecret,--destination.TopicTemplate=gw/\!{tenant}/\!{device}/alp,--destination.Hoscalhost,--destination.Port=11883,--tenant.id=*

当我这样订阅时,我没有收到任何消息。当我使用示例命令(仅适用于 DEFAULT_TENANT)订阅时,我正在使用消息。
当前用户权限如下所示:

"consumer@HONO": {
      "mechanism": "PLAIN",
      "password": "verysecret",
      "authorities": [ "application" ]
    }

当前的应用程序角色如下所示:

"application": [
  {
    "resource": "telemetry/*",
    "activities": [ "READ" ]
  },
  {
    "resource": "event/*",
    "activities": [ "READ" ]
  },
  {
    "resource": "control/*",
    "activities": [ "READ", "WRITE" ]
  }

两者都是Hono github的原创。

编辑:消费者也订阅了event/tenant。在我的例子中,这是 event/。消耗了在主题 event/DEFAULT_TENANT 和 event/MY_TENANT 上发布的事件。但是,telemetry/ 的消费者似乎没有注册。

我终于知道是怎么回事了。
由于以下错误,消息似乎在 QPID 调度路由器中被阻止:"Parse tree match not found".
这可以通过更改 qpid 配置来解决。在此配置中,您应该能够找到以下记录:

["linkRoute", {
    "prefix": "event/",
    "direction": "in",
    "connection": "broker"
  }],

  ["linkRoute", {
    "prefix": "event/",
    "direction": "out",
    "connection": "broker"
  }],

  ["address", {
    "prefix": "telemetry/",
    "distribution": "balanced"
  }],

它为事件主题而不是遥测主题创建链接路由(输入和输出)。为遥测主题添加这些记录可解决问题。

["linkRoute", {
    "prefix": "event/",
    "direction": "in",
    "connection": "broker"
  }],

  ["linkRoute", {
    "prefix": "event/",
    "direction": "out",
    "connection": "broker"
  }],

  ["linkRoute", {
    "prefix": "telemetry/",
    "direction": "in",
    "connection": "broker"
  }],

  ["linkRoute", {
    "prefix": "telemetry/",
    "direction": "out",
    "connection": "broker"
  }],

  ["address", {
    "prefix": "telemetry/",
    "distribution": "balanced"
  }],

Hono(目前)不支持消费所有租户的消息。消费者始终仅限于单个租户。这也反映在(北行)Telemetry and Event API 规范中。

不支持使用通配符接收 multiple/all 个租户的数据。您对 Dispatch Router 配置所做的更改可能使您相信它确实有效。但是,定义 telemetry 地址以使用 link routing 而不是默认的 message routing有一些您应该注意的后果:

  • 所有 遥测消息将被路由到消息代理 (Artemis),而不是直接路由到连接到 Dispatch Router 的消费者。这意味着所有消息都将 写入 到 Artemis 中的 queue/topic。根据 Artemis 配置,这也可能意味着(遥测)消息被持久化,这将对吞吐量产生相当大的负面影响。
  • 您的 clients/consumers 现在将明确依赖于 (Artemis) 经纪人对 AMQP 1.0 link 源地址中使用的通配符的支持,以接收来自多个地址的消息。虽然这可能是您首先想要实现的目标,但请注意它将您的应用程序与 AMQP 消息传递网络(在本例中为 Artemis)的特定实现联系起来,它是 not 的一部分Hono.