Reputation: 211
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
Reputation: 35162
If you're using JMS then you can use a QueueBrowser. The Solace documentation has additional details:
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.
Use the
QueueBrowser
to get anEnumeration
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()
.Iterate over the messages on the queue.
Call
Enumeration.hasMoreElements()
. This method returnstrue
if there is at least one message available in the browser’s local message buffer; otherwise, it returnsfalse
.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 toEnumeration.hasMoreElements()
orEnumeration.nextElement()
could returntrue
and return a message, respectively.
Upvotes: 1