Author |
Message
|
himansupanda |
Posted: Fri Jan 25, 2008 10:45 am Post subject: get most recent message in the Queue |
|
|
Newbie
Joined: 25 Jan 2008 Posts: 2
|
Hi,
I have an requirement to read the most recent message put on the queue. Please Let me know How to do that using MQ JAVA API.
Thanks in advance,
Regards
Himansu |
|
Back to top |
|
 |
jefflowrey |
Posted: Fri Jan 25, 2008 1:39 pm Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
A queue is a first-in, first-out structure.
Your requirement is entirely wrong.
Any attempt to do this will lead to horrible performance issues and horrible stability issues, as well as breaking the "loose coupling" that MQ provides.
You need to re-examine the requirement that says that you must read a queue in last-in, first-out order. And then figure out what it's really trying to do, and a better way to do it.
If you at least post what the requirement is really trying to do, we can help you figure out a better way to do it. _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
Vitor |
Posted: Fri Jan 25, 2008 4:16 pm Post subject: Re: get most recent message in the Queue |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
himansupanda wrote: |
I have an requirement to read the most recent message put on the queue. |
Strange requirement. What happens to the other messages on the queue if you only read the most recent? Suppose 3 messages turn up in a block, what processes the other 2?
 _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
fjb_saper |
Posted: Sat Jan 26, 2008 11:50 am Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
Retained publication syndrome ?
For lack of language skills:
retained publication = last message in queue??  _________________ MQ & Broker admin |
|
Back to top |
|
 |
himansupanda |
Posted: Mon Jan 28, 2008 6:46 am Post subject: |
|
|
Newbie
Joined: 25 Jan 2008 Posts: 2
|
Hi,
Thanks for reply....
Requirement is like this. Some other application is sending message continuesly to our local Q. Our application needs only the Most recent message on demand. Message contains some live data. Everytime there is some changes in Message.This application doe not require all the messge, as it wants latest data.
Please let me know if any other solution.
Regards
Himansu |
|
Back to top |
|
 |
Vitor |
Posted: Mon Jan 28, 2008 6:54 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
himansupanda wrote: |
This application doe not require all the messge, as it wants latest data.
|
What you're describing is best satisfied by the suggestion of fjb_saper, a retained publication.
If (and only if) the data is sent continiously and on a regular cycle (e.g. every 60 seconds) then an alternative would be to set the expiry of the message to just under the cycle time (59 seconds in my example) so there's only ever 1 message on the queue and it's always the latest. _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
jefflowrey |
Posted: Mon Jan 28, 2008 7:12 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
The other alternative is to continually consume the messages, and cache the data of the last message read. Then "on demand", show the value from the cache. _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
PeterPotkay |
Posted: Mon Jan 28, 2008 10:35 am Post subject: |
|
|
 Poobah
Joined: 15 May 2001 Posts: 7722
|
another cheesy way would be for the putting app to delete its last message by doing a destructive get before putting the newest one back on the queue. Not as ideal or elegant as retained pubs, but maybe easier if there is no need to scale and this is just a one time low volume requirement. _________________ Peter Potkay
Keep Calm and MQ On |
|
Back to top |
|
 |
jefflowrey |
Posted: Mon Jan 28, 2008 10:42 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
PeterPotkay wrote: |
another cheesy way would be for the putting app to delete its last message by doing a destructive get |
Only if the putting app is capable of doing any kind of GET from the destination queue... _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
|