高速公路:订阅具有正则表达式或通配符模式的频道

Autobahn: Subscribing to channels with regex or wildcard pattern

我的问题非常简单明了。在 RabbitMQ 中,我们可以使用正则表达式或通配符模式("Topic" 类型订阅)来订阅频道。那么有没有可能在高速公路上实现这一点?

WAMP 规范分为两部分:

  1. basic profile,它是稳定且强制性的,所有实施都必须完全实施。
  2. advanced profile,这是正在进行的工作,此处的功能对于实现提供是可选的。

Pattern-based subscriptions are part of the WAMP "Advanced Profile", but not yet (2015/01) in the Autobahn WAMP client libraries or the e.g. the Crossbar.io WAMP router (see here).

现在更详细地解释了基于模式的订阅in its own document which is also referenced from the WAMP IETF draft. Here's an example, quoting from the current AutobahnJS reference

Pattern-Based Subscriptions

As a default, topic URIs in subscriptions are matched exactly.

It is possible to change the matching policy to either prefix or wildcard matching via an option when subscribing, e.g.

session.subscribe('com.myapp', on_event_all, { match: 'prefix' })
session.subscribe('com.myapp..update', on_event_update, { match: 'wildcard' })

In the first case, events for all publications where the topic contains the prefix com.myapp will be received, in the second events for all publications which match the wildcard pattern, e.g. com.myapp.user121.update and com.myapp.sensor_23.update.

鉴于以上示例来自官方 AutobahnJS 文档,我推测 crossbar.io WAMP 路由器现在也必须内置支持。

至于任何其他 WAMP 库,您的里程可能会有所不同。