Reputation: 430
I have to browse messages from a message queue before they are consumed by consumers. (using activemq
as broker)
There are some consumers waiting for the message in the queue.
I have to browse the message and using that message info I have to perform some work but the problem is messages are consumed as soon as they come in queue.
Is there any way to get an alert as soon as message comes in the queue and to ensure that messages are browsed before they are actually consumed by other consumers?
Upvotes: 1
Views: 4282
Reputation: 13008
You can create a queue browser, possibly using a message selector:
this.queueBrowser = getQueueSession().createBrowser(getQueue(),
selector);
A selector is like a "where clause" for selecting messages.
Update
If you have one queue with a "normal" consumer, and you like to browse the queue before the real consumer consumes the message. If the real consumer consumes first, your browser won't see the message. That's not reliable.
Therefore you should use two queues. Your browsing application acts as a "man in the middle" or like a bridge, it will always get all messages posted into the 1st queue, and it has to send it on a 2nd queue. The real consumer is connecting to the 2nd queue. So both consume normally.
Another possibility is to change the sender: It could send the message on two queues, one for the real consumer, one for your browsing application only.
Upvotes: 2
Reputation: 15283
I have read about composite destinations of ActiveMQ. Using the composite destinations you can make a message to be routed to multiple destinations. You can have a combination of queue and topics in a virtual destination. ActiveMQ will route messages based on the values defined in <forwardTo>
attribute. So for the pattern you are trying to implement, the normal consumer will receive messages from one queue and the browser from another topic. This way both will get the same message data.
Please have a look at the example given in the link.
Upvotes: 1