2
votes

In my message queue contains several messages. This I want to group by specific properties. These all have a custom property "item-id"

This I would now certain values to: sports, movie ...

I do this like:

new MessageCreator() {
 ObjectMessage message = session.createObjectMessage();
 message.setObject(data);
 message.setStringProperty("item-id", "sports");
}

This value is also displayed in the Queue at the Properties.

When I try to retrieve the messages which contain this property I get no result.

First trial:

 Connection con = pc.createConnection();
 Session sess =con.createSession(false,Session.AUTO_ACKNOWLEDGE);       
 AmqMessagesQueryFilter queryFilter = new AmqMessagesQueryFilter(pc, queue); 
 con.start();
 String selector = "item-id = 'sports'";
 List messages = queryFilter.query(selector); 

But the list is empty

Second trial:

 Connection con = pc.createConnection();
 Session sess = con.createSession(false, Session.AUTO_ACKNOWLEDGE);

 AmqMessagesQueryFilter queryFilter = new AmqMessagesQueryFilter(pc, queue);

 QueueBrowser queueBrowser = sess.createBrowser(queue,"item-id = 'sports'");
 con.start();
 List messages=Collections.list(queueBrowser.getEnumeration());

Also the list is empty.

What is my mistake?

1
Did you put some messages in the queue before running your query filter ?ramp
yes and no. I tried with some messages in the queue before start and with an empty queue on start.fuerst
Disconnect all listeners, Put some messages in the queue that have an header 'item-id' and value 'sports' and then run your filter again.ramp

1 Answers

4
votes

I know that this is too late, but this will probably save someone a lot of hours wasted (and frustration).

Do not use dashes in your message selector. Use underscores if needed. Lookup "Identifiers" here: https://docs.oracle.com/javaee/1.4/api/javax/jms/Message.html