1
votes

I am using ActiveMQ 5.15.8. I am connecting to it using STOMP protocol in node.js with library stompit.

Producer Code Snippet:

var headers = {
'destination':'/topic/xyz',
'persistent':'true',
'content-type':'binary/octet-stream',
'content-length':9999,
'selector': "key = 'A'"
}
var frame = client.send(headers)

Consumer Code Subscribe Snippet:

client.subscribe({'ack':'client-individual',
'activemq.retroactive':'true',
'activemq.subscriptionName':'name',
'destination':'/topic/xyz',
'selector':"key = 'A'"},(err,msg)=>{})

The problem is I am not able to get the selectors right. I am not able to receive any message using the above code. I also tried using:

'selector':'key=A'

With this I receive all the messages but not filtered on the key.

Could someone please help me with getting this selector right. Again I am using Node.js library stompit.

Thanks

1

1 Answers

1
votes

When you send a message you don't apply a selector header. You simply apply a key/value, e.g:

var headers = {
'destination':'/topic/xyz',
'persistent':'true',
'content-type':'binary/octet-stream',
'content-length':9999,
'key': "A"
}
var frame = client.send(headers)

Then your consumer's selector will operate on that header. Keep your consumer's selector definition the same. It should work once you update the producer.

For what it's worth, selectors use a subset of the SQL92 conditional expression syntax described here (scroll down to the "Message Selectors" section). It may seem strange to cite JMS documentation for this, but the STOMP specification doesn't define anything related to selectors. However, brokers who already implement it for their JMS clients (like ActiveMQ) expose it to the STOMP clients for convenience.