2017-04-17 76 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

相關問題