gpt4 book ai didi

node.js - 使用消息选择器时使用 nodejs 订阅 ActiveMQ STOMP?

转载 作者:搜寻专家 更新时间:2023-10-31 23:59:05 25 4
gpt4 key购买 nike

我想使用 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)

最佳答案

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

引用ActiveMQ STOMP documentation .

从 STOMP 客户端网站订阅将 header 作为参数。

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');
});

关于node.js - 使用消息选择器时使用 nodejs 订阅 ActiveMQ STOMP?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43459841/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com