You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@activemq.apache.org by tnine <to...@gmail.com> on 2007/04/10 19:58:21 UTC
Input queue and output queue grouping and sequences question
Hi All,
I'll be writing a process that uses parallel grid processing to process
message groups. I'm new to Active MQ and could use some help in finding
documentation or examples.
I'll be running in the following environment
Java 1.6
JBoss 4
Active MQ 4.1.1
RHEL4
I know I will be performing the following operations.
1. Create a text message with the following format. [company-name]-[ISO
Date]
2. Push all text messages into this group
3. When I'm done producing all of the messages, I'll perform the
message.setIntProperty("JMSXGroupSeq", 0); to close the group.
I have have the following questions.
Producer/Consumer
1. Is it possible to insert multiple messages into the queue in a single XA
transaction? If so is there an example? Since the input is a large flat
file, I want either all messages to be inserted or none.
2. Is there a way for me to detect on the MDB side when the last message is
sent? Can I simply perform the message.getIntProperty("JMSXGroupSeq") and
search for the value 0 to find the last message?
3. I have 2 queues, one input queue, and one output queue. Both queues need
to be processed in the exact same order. As the MDB reads from the input
queue, can I put the same JMSXGroupSeq number into the output queue message
and still have the same ordering semantics without screwing up the Group
processing in Active MQ?
Monitoring
I want to write a simple webapp that shows the percentage of message in the
queues. Is it possible to read the groups, and for each group show the
messages on the queue?
Thanks,
Todd
--
View this message in context: http://www.nabble.com/Input-queue-and-output-queue-grouping-and-sequences-question-tf3554541s2354.html#a9924973
Sent from the ActiveMQ - User mailing list archive at Nabble.com.
Re: Input queue and output queue grouping and sequences question
Posted by James Strachan <ja...@gmail.com>.
On 4/12/07, tnine <to...@gmail.com> wrote:
>
> Ok, if that's the case I seem to have completely missed the point of Message
> Grouping. It states that the following semantics are applied according to
> the description in the "Impliations" section here
> http://activemq.apache.org/message-groups.html.
>
> # partioning the traffic
> # load balancing of message groups across consumers
>
>
> Doesn't this mean that I can have multiple instances of my MDBs, each in its
> own thread, consuming a message off of the queue?
Yes
> In other words, won't
> Active MQ give the next message to whatever consumer requests a message?
It load balances messages across all available consumers on a queue concurrently
> So, can't I have message 1 read from the queue, and while that transaction
> is processing, another node reads and begins processing message 2 BEFORE the
> transaction commits for the message 1 read? Otherwise, it becomes a
> sequential consumer, which I don't want.
We totally support concurrent processing. The whole point of Message
Groups is that it makes the processing of a single message group
(JMSXGroupID) sequential in a single thread to avoid concurrency
problems - but messages are processed concurrently for different
message groups (values of JMSXGroupID).
If you don't want any kind of sequential processing guarrentees, just
don't use message groups; then messages will be processed in parallel
across different consumers in a kinda random order (due to the usual
multithreading issues)
--
James
-------
http://radio.weblogs.com/0112098/
Re: Input queue and output queue grouping and sequences question
Posted by tnine <to...@gmail.com>.
Ok, if that's the case I seem to have completely missed the point of Message
Grouping. It states that the following semantics are applied according to
the description in the "Impliations" section here
http://activemq.apache.org/message-groups.html.
# partioning the traffic
# load balancing of message groups across consumers
Doesn't this mean that I can have multiple instances of my MDBs, each in its
own thread, consuming a message off of the queue? In other words, won't
Active MQ give the next message to whatever consumer requests a message?
So, can't I have message 1 read from the queue, and while that transaction
is processing, another node reads and begins processing message 2 BEFORE the
transaction commits for the message 1 read? Otherwise, it becomes a
sequential consumer, which I don't want. I need the ability to process
multiple messages concurrently across multiple nodes, but just have them
ordered in the same way on the output queue as they were when they were
inserted into the input queue. Ordering off of the input queue is not as
important, only that they end up in order when they are put in the output
queue, which I thought I could do by copying the message sequence number.
I guess my problem boils down to I'm having trouble distinguishing between
normal grid processing where multiple MDB instances read from a JMS queue,
and multiple MDB instances attempting to read from the same queue group in
Active MQ. Here would be my current understanding of what you described.
Thank you for your patience with me, I'll eventually get this through my
thick skull, if I only had a virtual white board this would be much
easier....
What I thought the documentation said.
FileReader1 -> Creates message on input queue group named "Biz1-ISODate" -->
Multiple MDB threads processing at the same time, but each MDB thread gets a
new message AFTER the previous message has been read by an MDB (so we get
concurrent processing)-> Creates message on output queue group named
"Biz1-ISODate" --> Single threaded consumer receives messages in order.
What I understand from your post.
FileReader1 -> Creates message on input queue group named "Biz1-ISODate" -->
A single MDB thread processing one message at a time sequentially (for
single threaded processing) -> Creates message on output queue group named
"Biz1-ISODate" --> Single threaded consumer receives messages in order.
Which one is correct?
Thanks again for your help.
Todd
James.Strachan wrote:
>
> On 4/12/07, tnine <to...@gmail.com> wrote:
>>
>> Let me give a clearer example. Lets say I have 4 "real" messages, that
>> contain data. I have a 5th message that contains no data but closes the
>> group on the input queue. I need to replicate the order of items from
>> the
>> input queue to the order on the output queue because the consumer of the
>> output queue needs to know when the group is finished in order to flush
>> the
>> output file to the system. Here is the scenario I was describing
>> explained
>> a bit clearer, (I hope since I included a bit of source)
>>
>> Step 1: messages 1 through 3 are processed normally and put on the output
>> queue.
>> Step 2: message 4 begins processing, then message 5, the "close group"
>> message gets processed simultaneously. Message 5 will most likely be
>> inserted on the output queue before message 4 since there will be no
>> processing of the closing message.
>
>
> So here's the cool thing about Message Groups. The contract is 1
> thread in the entire cluster of processes & threads gets the messages
> for a single message group. So you will always process message 4
> first, then message 5. So there will be no out-of-order issues. Cool
> eh? :)
>
> --
>
> James
> -------
> http://radio.weblogs.com/0112098/
>
>
--
View this message in context: http://www.nabble.com/Input-queue-and-output-queue-grouping-and-sequences-question-tf3554541s2354.html#a9964482
Sent from the ActiveMQ - User mailing list archive at Nabble.com.
Re: Input queue and output queue grouping and sequences question
Posted by James Strachan <ja...@gmail.com>.
On 4/12/07, tnine <to...@gmail.com> wrote:
>
> Let me give a clearer example. Lets say I have 4 "real" messages, that
> contain data. I have a 5th message that contains no data but closes the
> group on the input queue. I need to replicate the order of items from the
> input queue to the order on the output queue because the consumer of the
> output queue needs to know when the group is finished in order to flush the
> output file to the system. Here is the scenario I was describing explained
> a bit clearer, (I hope since I included a bit of source)
>
> Step 1: messages 1 through 3 are processed normally and put on the output
> queue.
> Step 2: message 4 begins processing, then message 5, the "close group"
> message gets processed simultaneously. Message 5 will most likely be
> inserted on the output queue before message 4 since there will be no
> processing of the closing message.
So here's the cool thing about Message Groups. The contract is 1
thread in the entire cluster of processes & threads gets the messages
for a single message group. So you will always process message 4
first, then message 5. So there will be no out-of-order issues. Cool
eh? :)
--
James
-------
http://radio.weblogs.com/0112098/
Re: Input queue and output queue grouping and sequences question
Posted by tnine <to...@gmail.com>.
Let me give a clearer example. Lets say I have 4 "real" messages, that
contain data. I have a 5th message that contains no data but closes the
group on the input queue. I need to replicate the order of items from the
input queue to the order on the output queue because the consumer of the
output queue needs to know when the group is finished in order to flush the
output file to the system. Here is the scenario I was describing explained
a bit clearer, (I hope since I included a bit of source)
Step 1: messages 1 through 3 are processed normally and put on the output
queue.
Step 2: message 4 begins processing, then message 5, the "close group"
message gets processed simultaneously. Message 5 will most likely be
inserted on the output queue before message 4 since there will be no
processing of the closing message. In other words, input message 4 will not
be in the group in the output queue since it will already be closed. This
will cause the last record of the input queue to be lost on the output
queue. Is there any way to avoid doing this. I've included the code I'm
envisioning to do the duplication from one queue to the other.
//read from input queue(passed to the MDB)
TextMessage text = (TextMessage)message;
String groupId = message.getStringProperty("JMSXGroupID");
int sequenceNumber = message.getIntProperty("JMSXGroupSeq");
String result = null;
//call POJO processing that integrates multiple systems, will probably take
around 5-10 seconds to process
if(sequenceNumber != 0){
result = pojo.process(text.getText());
}
//now lookup our output queue and send the message. Hopefully in order
Mesasge message = session.createTextMessage(result);
message.setStringProperty("JMSXGroupID", groupId);
message.setIntProperty("JMSXGroupSeq", sequenceNumber );
producer.send(message);
As you can see from the code above, message 5 will always beat message 4
onto the queue if they're received simultaneously by both nodes. How can I
get around loosing the last "real" message?
Thanks,
Todd
James.Strachan wrote:
>
> On 4/12/07, tnine <to...@gmail.com> wrote:
>>
>> Excellent! Thank you for the help. I may have a race condition that
>> I've
>> thought of that may cause problems, but this may be taken care of my the
>> grouping. If you could give me some advice, I would really appreciate
>> it.
>>
>> It pertains to the grid processing and the nth and n-1 messages in a
>> group
>> in a 2 node or greater environment. Lets say we have n messages in the
>> group, where the last message (n) sets the sequence number to 0 to close
>> the
>> group. When my n-1 message is consumed off the input queue, it will take
>> a
>> few seconds to process. The nth message is to signal the group is
>> closed,
>> so the receiving MDB will simply push a new message with the sequence 0
>> on
>> to the output queue. The message with 0 will be on the output queue
>> before
>> the n-1 sequence is pushed. Won't my n-1 message get excluded from the
>> group since its inserted after 0?
>
> I don't quite follow. Note that the sequence number is not used to
> reorder the messages in the group. The zero is only used to close a
> group. (To be honest there's no real need to close a group since we're
> using hash buckets under the covers by default so there's little cost
> to keeping a group open).
>
>
>> This is an implementation detail, but an
>> important one. Below is an ASCII diagram of my queues and MDB
>>
>> Standalone file reader--->Input Queue (jms/StatInput)--> MDB >-- Output
>> Queue(jms/StatOutput) --> Consumer
>>
>> As you can see, I have 2 queues for round trip communication, will this
>> cause the sequences issues I described above? If so, do you have any
>> ideas
>> on how I can get around them?
>
> Each queue is separate and wil be ordered based on the order in which
> messages (within a group) are published; so it all sounds fine to me
>
> --
>
> James
> -------
> http://radio.weblogs.com/0112098/
>
>
--
View this message in context: http://www.nabble.com/Input-queue-and-output-queue-grouping-and-sequences-question-tf3554541s2354.html#a9961009
Sent from the ActiveMQ - User mailing list archive at Nabble.com.
Re: Input queue and output queue grouping and sequences question
Posted by James Strachan <ja...@gmail.com>.
On 4/12/07, tnine <to...@gmail.com> wrote:
>
> Excellent! Thank you for the help. I may have a race condition that I've
> thought of that may cause problems, but this may be taken care of my the
> grouping. If you could give me some advice, I would really appreciate it.
>
> It pertains to the grid processing and the nth and n-1 messages in a group
> in a 2 node or greater environment. Lets say we have n messages in the
> group, where the last message (n) sets the sequence number to 0 to close the
> group. When my n-1 message is consumed off the input queue, it will take a
> few seconds to process. The nth message is to signal the group is closed,
> so the receiving MDB will simply push a new message with the sequence 0 on
> to the output queue. The message with 0 will be on the output queue before
> the n-1 sequence is pushed. Won't my n-1 message get excluded from the
> group since its inserted after 0?
I don't quite follow. Note that the sequence number is not used to
reorder the messages in the group. The zero is only used to close a
group. (To be honest there's no real need to close a group since we're
using hash buckets under the covers by default so there's little cost
to keeping a group open).
> This is an implementation detail, but an
> important one. Below is an ASCII diagram of my queues and MDB
>
> Standalone file reader--->Input Queue (jms/StatInput)--> MDB >-- Output
> Queue(jms/StatOutput) --> Consumer
>
> As you can see, I have 2 queues for round trip communication, will this
> cause the sequences issues I described above? If so, do you have any ideas
> on how I can get around them?
Each queue is separate and wil be ordered based on the order in which
messages (within a group) are published; so it all sounds fine to me
--
James
-------
http://radio.weblogs.com/0112098/
Re: Input queue and output queue grouping and sequences question
Posted by tnine <to...@gmail.com>.
Excellent! Thank you for the help. I may have a race condition that I've
thought of that may cause problems, but this may be taken care of my the
grouping. If you could give me some advice, I would really appreciate it.
It pertains to the grid processing and the nth and n-1 messages in a group
in a 2 node or greater environment. Lets say we have n messages in the
group, where the last message (n) sets the sequence number to 0 to close the
group. When my n-1 message is consumed off the input queue, it will take a
few seconds to process. The nth message is to signal the group is closed,
so the receiving MDB will simply push a new message with the sequence 0 on
to the output queue. The message with 0 will be on the output queue before
the n-1 sequence is pushed. Won't my n-1 message get excluded from the
group since its inserted after 0? This is an implementation detail, but an
important one. Below is an ASCII diagram of my queues and MDB
Standalone file reader--->Input Queue (jms/StatInput)--> MDB >-- Output
Queue(jms/StatOutput) --> Consumer
As you can see, I have 2 queues for round trip communication, will this
cause the sequences issues I described above? If so, do you have any ideas
on how I can get around them?
As far as my message size, each one is between .5k and 1.5 k.
Thank you for all your help, it is greatly appreciated.
Todd
James.Strachan wrote:
>
> On 4/10/07, tnine <to...@gmail.com> wrote:
>>
>> Hi All,
>> I'll be writing a process that uses parallel grid processing to process
>> message groups. I'm new to Active MQ and could use some help in finding
>> documentation or examples.
>>
>> I'll be running in the following environment
>> Java 1.6
>> JBoss 4
>> Active MQ 4.1.1
>> RHEL4
>>
>> I know I will be performing the following operations.
>>
>> 1. Create a text message with the following format. [company-name]-[ISO
>> Date]
>> 2. Push all text messages into this group
>> 3. When I'm done producing all of the messages, I'll perform the
>> message.setIntProperty("JMSXGroupSeq", 0); to close the group.
>>
>> I have have the following questions.
>>
>> Producer/Consumer
>>
>> 1. Is it possible to insert multiple messages into the queue in a single
>> XA
>> transaction?
>
> Yes - whether using JMS or XA transactions, you can send or receive
> multiple messages; its up to you when you do the commit
>
>
>> If so is there an example? Since the input is a large flat
>> file, I want either all messages to be inserted or none.
>
> How large is the file?
>
>
>> 2. Is there a way for me to detect on the MDB side when the last message
>> is
>> sent? Can I simply perform the message.getIntProperty("JMSXGroupSeq") and
>> search for the value 0 to find the last message?
>
> Sure. Or just add your own header to indicate the last message if you
> prefer
>
>
>> 3. I have 2 queues, one input queue, and one output queue. Both queues
>> need
>> to be processed in the exact same order. As the MDB reads from the input
>> queue, can I put the same JMSXGroupSeq number into the output queue
>> message
>> and still have the same ordering semantics without screwing up the Group
>> processing in Active MQ?
>
> The 2 queues are processed separately by different consumer groups;
> but sure order would be guarrenteed if you use the same JMSGroupID
>
>
>> Monitoring
>>
>> I want to write a simple webapp that shows the percentage of message in
>> the
>> queues. Is it possible to read the groups, and for each group show the
>> messages on the queue?
>
> Not efficiently; you could write your own Interceptor to do just that
>
> http://activemq.apache.org/interceptors.html
>
> but you could inefficiently do it by just browsing the queue via the
> QueueBrowser on JMS to figure out the numbers etc
>
> --
>
> James
> -------
> http://radio.weblogs.com/0112098/
>
>
--
View this message in context: http://www.nabble.com/Input-queue-and-output-queue-grouping-and-sequences-question-tf3554541s2354.html#a9950154
Sent from the ActiveMQ - User mailing list archive at Nabble.com.
Re: Input queue and output queue grouping and sequences question
Posted by James Strachan <ja...@gmail.com>.
On 4/10/07, tnine <to...@gmail.com> wrote:
>
> Hi All,
> I'll be writing a process that uses parallel grid processing to process
> message groups. I'm new to Active MQ and could use some help in finding
> documentation or examples.
>
> I'll be running in the following environment
> Java 1.6
> JBoss 4
> Active MQ 4.1.1
> RHEL4
>
> I know I will be performing the following operations.
>
> 1. Create a text message with the following format. [company-name]-[ISO
> Date]
> 2. Push all text messages into this group
> 3. When I'm done producing all of the messages, I'll perform the
> message.setIntProperty("JMSXGroupSeq", 0); to close the group.
>
> I have have the following questions.
>
> Producer/Consumer
>
> 1. Is it possible to insert multiple messages into the queue in a single XA
> transaction?
Yes - whether using JMS or XA transactions, you can send or receive
multiple messages; its up to you when you do the commit
> If so is there an example? Since the input is a large flat
> file, I want either all messages to be inserted or none.
How large is the file?
> 2. Is there a way for me to detect on the MDB side when the last message is
> sent? Can I simply perform the message.getIntProperty("JMSXGroupSeq") and
> search for the value 0 to find the last message?
Sure. Or just add your own header to indicate the last message if you prefer
> 3. I have 2 queues, one input queue, and one output queue. Both queues need
> to be processed in the exact same order. As the MDB reads from the input
> queue, can I put the same JMSXGroupSeq number into the output queue message
> and still have the same ordering semantics without screwing up the Group
> processing in Active MQ?
The 2 queues are processed separately by different consumer groups;
but sure order would be guarrenteed if you use the same JMSGroupID
> Monitoring
>
> I want to write a simple webapp that shows the percentage of message in the
> queues. Is it possible to read the groups, and for each group show the
> messages on the queue?
Not efficiently; you could write your own Interceptor to do just that
http://activemq.apache.org/interceptors.html
but you could inefficiently do it by just browsing the queue via the
QueueBrowser on JMS to figure out the numbers etc
--
James
-------
http://radio.weblogs.com/0112098/