Author |
Message
|
broker_new |
Posted: Mon Jul 21, 2008 12:44 pm Post subject: Find No of messages In Input Queue |
|
|
 Yatiri
Joined: 30 Nov 2006 Posts: 614 Location: Washington DC
|
I have a very peculiar requirement.
I have to find the number of messages on a queue and get all the messages and merge all of them into one XML message.
Is there a way to do that using a compute node. |
|
Back to top |
|
 |
sridhsri |
Posted: Mon Jul 21, 2008 6:07 pm Post subject: |
|
|
Master
Joined: 19 Jun 2008 Posts: 297
|
One approach would be to use MQ Message Groups. With these, the application that puts the message would indicate that the message is part of a part (MQMD.MsgFlags) and make sure that all messages have the same group id. The last msg of the group would indicate that its the last message. You could then read these messages and construct a single message. |
|
Back to top |
|
 |
AkankshA |
Posted: Mon Jul 21, 2008 7:56 pm Post subject: |
|
|
 Grand Master
Joined: 12 Jan 2006 Posts: 1494 Location: Singapore
|
One way could be using MQGet node... keep getting messages till your flow comes to No message terminal...
The only flaw i see wrt this is how to trigger the flow.. since we can not use same queue for both MQInput and MQGet... _________________ Cheers |
|
Back to top |
|
 |
chrisc |
Posted: Mon Jul 21, 2008 10:53 pm Post subject: |
|
|
Voyager
Joined: 19 Mar 2006 Posts: 77
|
To be honest this sounds like something that would be handled much better using the MQ API, such as using Java. If you absolutely want a message flow to do this (i.e. to do something with the message afterwards) you could always write it as a Java plugin and incorporate it into a flow.
The MQ API would do exactly what you want because you can query a queue for its queue depth, then pull out all the messages in a simple loop.
Using Message Groups would rely on the sender(s) knowing that they were a group, which may not be an option if you don't control the source application.
The MQGet node is a possibility, but you would have to do some pretty tricky (read ugly) stuff to iterate through it multiple times, probably storing counters in the Environment or LocalEnvironment or something. If your criteria was "until the queue is empty" you could end up with race conditions, where the queue was getting fed as quickly as it was getting read off. A loop based on queue depth would have the advantage of having a definite cut-off point.
Hope that helps. |
|
Back to top |
|
 |
francoisvdm |
Posted: Wed Jul 23, 2008 10:25 pm Post subject: |
|
|
Partisan
Joined: 09 Aug 2001 Posts: 332
|
Send PCF message to MQ to get queue depth, then do a simple propagate loop to read with GetMQ node X messages. The only outstanding thing is to trigger the flow. If your backend knows when the X messages are sent then it can send a control message to a "trigger" queue to start this process.
If you need sample code to do PCF, let me know. _________________ If you do not know the answer or you get the urge to answer with "RTFM" or "Search better in this forum", please refrain from doing so, just move on to the next question. Much appreciated.
Francois van der Merwe |
|
Back to top |
|
 |
zpat |
Posted: Wed Jul 23, 2008 11:20 pm Post subject: |
|
|
 Jedi Council
Joined: 19 May 2001 Posts: 5866 Location: UK
|
It's normal to read a queue until it's empty (MQRC 2033) rather than query the depth.
MQGET node seems like the right approach. However the question is when should this flow be run?
You might set up a simple program to send a message (on a different queue) to start the flow. This program could be scheduled with cron or perhaps triggered on queue depth.
PCF is not needed to query queue depth. MQINQ does that. PCF should not be used by application programs. |
|
Back to top |
|
 |
AkankshA |
Posted: Wed Jul 23, 2008 11:51 pm Post subject: |
|
|
 Grand Master
Joined: 12 Jan 2006 Posts: 1494 Location: Singapore
|
you also need to ensure that when your flow is picking the message no other application is putting the message.... or may be u need to set some max count over here...
else it might happen that one single execution of flow would get 100's of messages (It ll pick as long as the msgs are there..)
I am sure you must have given a thought to all these factors before getting the requirement in your court
 _________________ Cheers |
|
Back to top |
|
 |
mlafleur |
Posted: Mon Jul 28, 2008 2:15 pm Post subject: |
|
|
Acolyte
Joined: 19 Feb 2004 Posts: 73
|
If you are using version 6.1, use the collector node. |
|
Back to top |
|
 |
|