使用nodejs在使用消息选择器时订阅ActiveMQ STOMP?
问题描述:
我想使用nodejs订阅activemq服务器。我现在面临的问题是,我现在的node-stomp-client(https://github.com/easternbloc/node-stomp-client)正在获取所有正在发布的消息,当我真的想使用“消息选择器”,以便我不会获得所有消息消息传到nodejs。有没有一种方法可以在nodej中使用消息选择器,就像使用Java订阅ActiveMQ一样? (Java中的消息选择器引用:http://timjansen.github.io/jarfiller/guide/jms/selectors.xhtml)使用nodejs在使用消息选择器时订阅ActiveMQ STOMP?
答
在订阅ActiveMQ代理的STOMP中,可以使用选项名称“selector”在伴随订阅调用的选项值中包含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');
});
很确定你可以用'patrun'工作,如果你正确地格式化了你的消息。 – Gntem