[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 997
  • Last Modified:

Selectively pulling messages off of a JMS Queue in Spring

I am using Spring to interface with an asynchronous JMS queue. The Spring listeners that I have created pull all of the messages off of the queue as soon as they are placed there. I am trying to figure out how to find a particular message then retrieve it manually. I want the messages to sit on the queue then when I am ready I want to find a particular message then retrieve it. Does anyone know how to do this?    
0
texastemplar
Asked:
texastemplar
  • 3
  • 2
2 Solutions
 
girionisCommented:
If you are retrieving the messages using the receive() method I am afraid you will have to read them before you can decide if the messages are the ones you want. Maybe the API you ar using has methods to do what you ask for but I can't think of any solution using the standard JMS APIs.
0
 
texastemplarAuthor Commented:
What about JMSTemplate.receiveSelected(String messageSelector) method? According to the docs Ive read I can provide a string that will determine which messages this listener will receive. Im thinking about using the jmsmessageid header to pull the messages.

ex.  receiveSelected("jmsmessageid = 1234")
0
 
girionisCommented:
You can use this but this reads messages synchronously. It will block the queue until the message becomes available (or timeout has expired).
0
 
texastemplarAuthor Commented:
I figured it out. I added properties ( using message.setStringProperty() ) to each message that enables me to uniquely identify each message. Then I used receiveSelected( "property = value" ) to retrieve the message.
0
 
texastemplarAuthor Commented:
ok
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now