【问题标题】:Use nodejs to subscribe to ActiveMQ STOMP while using Message Selectors?在使用消息选择器时使用 nodejs 订阅 ActiveMQ STOMP?
【发布时间】:2017-09-13 13:33:17
【问题描述】:

我想使用 nodejs 订阅一个 activemq 服务器。我遇到的问题是,我的 node-stomp-client (https://github.com/easternbloc/node-stomp-client) 目前正在获取所有从 MQ 发布的消息,而我真的想使用“消息选择器”,所以我不获取所有发送到 nodejs 的消息。有没有一种方法可以像使用 Java 订阅 ActiveMQ 一样在 nodejs 中使用消息选择器? (Java 中的消息选择器参考:http://timjansen.github.io/jarfiller/guide/jms/selectors.xhtml

【问题讨论】:

  • 如果你正确格式化你的消息,你可以使用patrun

标签: node.js activemq


【解决方案1】:

在 STOMP 中订阅 ActiveMQ 代理时,您可以使用选项名称“选择器”在伴随订阅调用的选项值中包含 JMS 样式的消息选择器。然后,代理将应用选择器并过滤发送到客户订阅的消息。

参考 ActiveMQ STOMP documentation

从 STOMP 客户端网站,订阅将标头作为参数。

var Stomp = require('stomp-client');
var destination = '/queue/someQueueName';
var client = new Stomp('127.0.0.1', 61613, 'user', 'pass');

client.connect(function(sessionId) {
    client.subscribe(destination, function(body, headers) {
        console.log('This is the body of a message on the subscribed queue:', body);
    });

    client.publish(destination, 'Oh herrow');
});

【讨论】:

  • 你能举个例子吗?我不确定这如何转化为 nodejs 库中的内容。
  • 似乎没有人这样做过,尽管我可以看到如何使用 Java 类和 XML 来做到这一点。希望有人能解释一下。
猜你喜欢
  • 2014-03-28
  • 2019-08-04
  • 2020-01-07
  • 2017-04-23
  • 2018-10-31
  • 2021-06-17
  • 2017-01-24
  • 2020-12-17
  • 2017-01-01
相关资源
最近更新 更多