activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "James Strachan" <james.strac...@gmail.com>
Subject Re: Groups
Date Fri, 12 Jan 2007 09:00:13 GMT
On 1/11/07, JohnRobinson <john.robinson@gtech.com> wrote:
>
>
>
> James.Strachan wrote:
> >
> > On 1/10/07, JohnRobinson <john.robinson@gtech.com> wrote:
> >>
> >> Hi folks,
> >>
> >> I'm hoping someone here can help me out.  I've got ActiveMQ setup in
> >> JBoss,
> >> with two queues, one in and one out.
> >>
> >> I've got one MDB per queue.
> >>
> >> I'm using the JCA approach for configuring ActiveMQ in JBoss, and I'm
> >> using
> >> the VM broker.
> >>
> >> While I have one outbound queue, and one outbound MDB, each message can
> >> go
> >> to a different destination, and for a variety of reasons its not feasible
> >> to
> >> create one queue per concrete destination.
> >
> > -I don't understand what that means :). A queue is a concrete destination?
> >
> > LOL!  Let me see if I can explain.  When the message arrives at the MDB it
> > is dispatched via a SOAP call to one of several different destinations.
> > So I have one outbound queue, one MDB consuming messages from that, and
> > when I have a simple case where there is only one destination (and hence
> > one group ID) my messages arrive at the destination out of order (each
> > message has a sequence number on it).
> >
> > I've turned on the logging in AMQ via log4j and I see the messages are
> > arriving in the queue in order (it would be difficult for them not to, but
> > I thought I should check that).  Additionally, as the MDB processes the
> > messages I put a log statement in that does a toString on the MDB and I
> > see multiple instances of the MDB running simultaneously.
> >
> > The code that sends the message is in a Stateless Session EJB and uses the
> > stock JMS apis, not the ActiveMQ apis.  It looks like this:
> >
> > .....
> > import javax.jms.JMSException;
> > import javax.jms.ObjectMessage;
> > import javax.jms.Queue;
> > import javax.jms.QueueConnection;
> > import javax.jms.QueueConnectionFactory;
> > import javax.jms.QueueSender;
> > import javax.jms.QueueSession;
> > ......
> >         InitialContext initCtx = new InitialContext();
> >
> >
> >         QueueConnectionFactory qcf = (QueueConnectionFactory)
> > initCtx.lookup(
> >             "java:comp/env/jms/QueueConnectionFactory");
> >
> >         QueueConnection qcon = qcf.createQueueConnection();
> >         String groupId = internalMessage.getGroupId();
> >         QueueSession qsession = qcon.createQueueSession(true, 0);
> >
> >         Queue q = (Queue) initCtx.lookup(queueName);
> >         QueueSender qsender = qsession.createSender(q);
> >
> >         ObjectMessage message = qsession.createObjectMessage();
> >         message.setObject((Serializable) internalMessage);
> >
> >         message.setStringProperty("JMSXGroupID",groupId);
> >
> >         qsender.setTimeToLive(30000);
> >         qsender.send(message);
> >         qsender.close();
> >         qsession.close();
> >         qcon.close();
> >
> > Messages are sent to the queue as soon as they are ready, in sequence (1,
> > 2, 3, 4, etc) but show up at the SOAP destination out of order (1, 4, 3, 2
> > for example) which suggests that they are being processed in parallel.
> > The MDB that processes the messages from the queue has a maximum pool size
> > of 100.  My understanding is that AMQ should be dispatching all of the
> > messages for a single group to a single instance of the MDB, allowing
> > other instances to process messages to other groups.
> >
> >> I've been setting the JMSXGroupID on outbound messages but it doesn't
> >> appear
> >> to be doing any good.  Based on my debug output outbound messages to the
> >> same target group are handled by multiple instances of the MDB, so
> >> messages
> >> to the same destination are handled in parallel, which is not what I
> >> expected to see with the JMSXGroupID.  I was expecting to see that
> >> messages
> >> to different destinations (in different groups) would be handled in
> >> parallel, while messages to the same group would be processed serially.
> >
> >
> > -Hmm, I wonder if there's some issue with the JCA container and Message
> > -Groups. Are you sure you are using the same value of JMSXGroupID and
> > -messages are being processed concurrently for the same value?
> >
> > The exact same value is being used for the JMSXGroupID every time.  At the
> > moment I'm working with a single group.
> >
> >> Have I misunderstood the expected behavior of groups, or do I just not
> >> have
> >> it setup properly?  I haven't done anything special to enable
> >> ExclusiveConsumer, but I see groups are mentioned as an extension of
> >> that.
> >> Does that mean that ActiveMQ has to be configured for ExclusiveConsumer
> >> before grouping will work as expected?  If so, how does one do that using
> >> the JCA interface, or can one?
> >
> > -No - the existence of a JMSXGroupID on a message is enough to enable
> > -message groups.
> >
> > That's what I thought.
> >
> > -I'm wondering if there's some issue with the JCA RA and message
> > -groups. You could experiment switching the RA to something like
> > -genericjmsra to see if that does any good; or trying switching to the
> > -pure JMS client API (rather than MDBs with RAs) to see if that fixes
> > -it.
> >
> > I can try that, in fact I'm going to see if I can replicate this problem
> > in a small testbed.  But ultimately we want the MDBs as the messages are
> > transactional.
> >
> > Given that groups are implemented in the broker, does the choice of broker
> > matter?   Should I perhaps be using the tcp broker and starting it
> > separately?

The type of transport doesn't matter at all - vm, tcp or whatever. I'm
confident things would work fine if you just created, say, 100
MessageListeners (each with their own session so they can support
parallel consuming).

I'd definitely try make a simpler test case - taking out points of
complication which could affect the order (like having multiple EJBs
or parallel soap requests which could all break order). Given a number
of messages on the queue, placed in order with the same JMSXGroupID -
we should just test if the RA dispatches them in order. I've a feeling
the RA may ignore the message groups contract and parallelize the
dispatching to concurrent MDBs.

-- 

James
-------
http://radio.weblogs.com/0112098/

Mime
View raw message