2017-04-17 302 views
3

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

+0

很确定你可以用'patrun'工作,如果你正确地格式化了你的消息。 – Gntem

回答

1

在订阅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'); 
}); 
+0

你能提供一个例子吗?我不知道这是如何转化为nodejs库中的某些东西的。 – Rolando

+0

我不会做JavaScript,所以我不能帮助Node.js,但我敢肯定,如果你试试或者可能使用一些Google搜索,你可以找出它。 –

+0

尽管我可以看到如何使用Java类和XML来完成它,但似乎没有人这么做。希望有人能够阐明一些看法。 – Rolando

相关问题