hello world
hello world

Reputation: 211

View Messages on Queue

How can I view/browse the message on the queue programmatically? I don't want to consume the message.

Below is the code I am using to send the message:

@Autowired
private JmsTemplate producerJmsTemplate;

@Value("${.jms.host}")
private String jmsHost;

public void sendMessage(String message, String destQueue) {
    this.producerJmsTemplate.convertAndSend(destQueue, message);
}

Upvotes: 2

Views: 1724

Answers (1)

Justin Bertram
Justin Bertram

Reputation: 35162

If you're using JMS then you can use a QueueBrowser. The Solace documentation has additional details:

  1. Create a QueueBrowser object.

    Call Session.createBrowser(...) and pass in the queue that you want to browse.

    Optionally, you can also pass in a selector string for the Selector property. Using a selector enables the client to only browse messages that match a selector. Note that it could take longer for the message bus to evaluate spooled messages against a selector, especially if the selector used is complex. For more information on selectors, refer to Selectors.

  2. Use the QueueBrowser to get an Enumeration object that can be used to browse the current queue messages in the order they were received (from oldest to newest) by the queue.

    Call QueueBrowser.getEnumeration().

  3. Iterate over the messages on the queue.

    Call Enumeration.hasMoreElements(). This method returns true if there is at least one message available in the browser’s local message buffer; otherwise, it returns false.

    If it returns false, it does not necessarily mean that the queue is empty, rather the local buffer does not currently contain any messages. Subsequent calls to Enumeration.hasMoreElements() or Enumeration.nextElement() could return true and return a message, respectively.

Upvotes: 1

Related Questions