You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by Ihsan Ecemis <mi...@gmail.com> on 2017/02/02 22:34:32 UTC

Using JMS Message Groups with TomEE

Hi,

In our application, we have a dozen JMS queues and corresponding MDBs, running against an external ActiveMQ server.  All this is running reliably.

Recently, we had to add a new queue with the following requirement:  Some messages should not get processed concurrently. 

It looked like ActiveMQ Message Groups is built for this purpose so we added JMSXGroupID to messages that shouldn’t get processed concurrently  (Reference: http://activemq.apache.org/message-groups.html <http://activemq.apache.org/message-groups.html>)

However, this has not worked as we expected:  Even though the container is using a single MessageConsumer (which may be respecting our JMSXGroupID settings),  the onMessage method of multiple MDB instances are getting called concurrently for the same JMSXGroupID — and that is not acceptable per our requirement. 

Is there a way around this using MDBs?  E.g. some kind of TomEE or ActiveMQ setting?

If this is not possible using MDBs, what kind of architecture can be used to solve this problem?  (We thought about creating our own MessageConsumer in a Singleton and have it continuously poll this new queue but we are not excited about it.  This would not scale well and we don’t like the idea to manage transactions on our own.  Another idea we had was to use ReentrantLocks, but we realized that we have to release the lock after transaction is completed and we don’t have access to that from a stateless session bean.  That solution is messy in other fronts as well so again, we are not excited about it).

Any help will be greatly appreciated.

Thanks,

Ihsan. 

Re: Using JMS Message Groups with TomEE

Posted by Romain Manni-Bucau <rm...@gmail.com>.
I see

It is not really about concurrency then cause mdb will start multiple
consumers per class.

Not using mdb or redesigning the subflow behind can help.



Le 3 févr. 2017 02:30, "Ihsan Ecemis" <mi...@gmail.com> a écrit :


Not exactly…  We want to serialize message processing for a given Message
Group.

Let me give a concrete examples:  Say our messages are User Requests and we
have 10,000 Users sending us 1K messages/sec.

We want to process these messages in parallel overall,  but serially for a
given User.

If we use 1 MDB, then all the User Requests (1K messages/sec) will be
processed by 1 Thread.  which is not what we want.  We want to process them
with many MDBs but we don’t want 2 MDBs to process a request from the same
User in parallel.

Message Group solution is to set JMSXGroupID = User Id, but as far as I
understand that works for MessageConsumers and not for MessageListeners..
Oracle documentation is a little confusing around this cause it sometimes
refers MessageListeners as Message Consumers  (And many other people follow
the same confusing nomenclature).

Hope the example above is clear.  Let me know if you have any questions.


> On Feb 2, 2017, at 6:26 PM, Romain Manni-Bucau <rm...@gmail.com>
wrote:
>
> Hi
>
> You just want to serialize the message processing? Why not using a
> container of 1 mdb instance?
>
> Le 2 févr. 2017 23:34, "Ihsan Ecemis" <mi...@gmail.com> a écrit :
>
>>
>> Hi,
>>
>> In our application, we have a dozen JMS queues and corresponding MDBs,
>> running against an external ActiveMQ server.  All this is running
reliably.
>>
>> Recently, we had to add a new queue with the following requirement:  Some
>> messages should not get processed concurrently.
>>
>> It looked like ActiveMQ Message Groups is built for this purpose so we
>> added JMSXGroupID to messages that shouldn’t get processed concurrently
>> (Reference: http://activemq.apache.org/message-groups.html <
>> http://activemq.apache.org/message-groups.html>)
>>
>> However, this has not worked as we expected:  Even though the container
is
>> using a single MessageConsumer (which may be respecting our JMSXGroupID
>> settings),  the onMessage method of multiple MDB instances are getting
>> called concurrently for the same JMSXGroupID — and that is not acceptable
>> per our requirement.
>>
>> Is there a way around this using MDBs?  E.g. some kind of TomEE or
>> ActiveMQ setting?
>>
>> If this is not possible using MDBs, what kind of architecture can be used
>> to solve this problem?  (We thought about creating our own
MessageConsumer
>> in a Singleton and have it continuously poll this new queue but we are
not
>> excited about it.  This would not scale well and we don’t like the idea
to
>> manage transactions on our own.  Another idea we had was to use
>> ReentrantLocks, but we realized that we have to release the lock after
>> transaction is completed and we don’t have access to that from a
stateless
>> session bean.  That solution is messy in other fronts as well so again,
we
>> are not excited about it).
>>
>> Any help will be greatly appreciated.
>>
>> Thanks,
>>
>> Ihsan.

Re: Using JMS Message Groups with TomEE

Posted by Ihsan Ecemis <mi...@gmail.com>.
Not exactly…  We want to serialize message processing for a given Message Group.

Let me give a concrete examples:  Say our messages are User Requests and we have 10,000 Users sending us 1K messages/sec.

We want to process these messages in parallel overall,  but serially for a given User.  

If we use 1 MDB, then all the User Requests (1K messages/sec) will be processed by 1 Thread.  which is not what we want.  We want to process them with many MDBs but we don’t want 2 MDBs to process a request from the same User in parallel. 

Message Group solution is to set JMSXGroupID = User Id, but as far as I understand that works for MessageConsumers and not for MessageListeners..  Oracle documentation is a little confusing around this cause it sometimes refers MessageListeners as Message Consumers  (And many other people follow the same confusing nomenclature). 

Hope the example above is clear.  Let me know if you have any questions. 


> On Feb 2, 2017, at 6:26 PM, Romain Manni-Bucau <rm...@gmail.com> wrote:
> 
> Hi
> 
> You just want to serialize the message processing? Why not using a
> container of 1 mdb instance?
> 
> Le 2 févr. 2017 23:34, "Ihsan Ecemis" <mi...@gmail.com> a écrit :
> 
>> 
>> Hi,
>> 
>> In our application, we have a dozen JMS queues and corresponding MDBs,
>> running against an external ActiveMQ server.  All this is running reliably.
>> 
>> Recently, we had to add a new queue with the following requirement:  Some
>> messages should not get processed concurrently.
>> 
>> It looked like ActiveMQ Message Groups is built for this purpose so we
>> added JMSXGroupID to messages that shouldn’t get processed concurrently
>> (Reference: http://activemq.apache.org/message-groups.html <
>> http://activemq.apache.org/message-groups.html>)
>> 
>> However, this has not worked as we expected:  Even though the container is
>> using a single MessageConsumer (which may be respecting our JMSXGroupID
>> settings),  the onMessage method of multiple MDB instances are getting
>> called concurrently for the same JMSXGroupID — and that is not acceptable
>> per our requirement.
>> 
>> Is there a way around this using MDBs?  E.g. some kind of TomEE or
>> ActiveMQ setting?
>> 
>> If this is not possible using MDBs, what kind of architecture can be used
>> to solve this problem?  (We thought about creating our own MessageConsumer
>> in a Singleton and have it continuously poll this new queue but we are not
>> excited about it.  This would not scale well and we don’t like the idea to
>> manage transactions on our own.  Another idea we had was to use
>> ReentrantLocks, but we realized that we have to release the lock after
>> transaction is completed and we don’t have access to that from a stateless
>> session bean.  That solution is messy in other fronts as well so again, we
>> are not excited about it).
>> 
>> Any help will be greatly appreciated.
>> 
>> Thanks,
>> 
>> Ihsan.


Re: Using JMS Message Groups with TomEE

Posted by Romain Manni-Bucau <rm...@gmail.com>.
Hi

You just want to serialize the message processing? Why not using a
container of 1 mdb instance?

Le 2 févr. 2017 23:34, "Ihsan Ecemis" <mi...@gmail.com> a écrit :

>
> Hi,
>
> In our application, we have a dozen JMS queues and corresponding MDBs,
> running against an external ActiveMQ server.  All this is running reliably.
>
> Recently, we had to add a new queue with the following requirement:  Some
> messages should not get processed concurrently.
>
> It looked like ActiveMQ Message Groups is built for this purpose so we
> added JMSXGroupID to messages that shouldn’t get processed concurrently
> (Reference: http://activemq.apache.org/message-groups.html <
> http://activemq.apache.org/message-groups.html>)
>
> However, this has not worked as we expected:  Even though the container is
> using a single MessageConsumer (which may be respecting our JMSXGroupID
> settings),  the onMessage method of multiple MDB instances are getting
> called concurrently for the same JMSXGroupID — and that is not acceptable
> per our requirement.
>
> Is there a way around this using MDBs?  E.g. some kind of TomEE or
> ActiveMQ setting?
>
> If this is not possible using MDBs, what kind of architecture can be used
> to solve this problem?  (We thought about creating our own MessageConsumer
> in a Singleton and have it continuously poll this new queue but we are not
> excited about it.  This would not scale well and we don’t like the idea to
> manage transactions on our own.  Another idea we had was to use
> ReentrantLocks, but we realized that we have to release the lock after
> transaction is completed and we don’t have access to that from a stateless
> session bean.  That solution is messy in other fronts as well so again, we
> are not excited about it).
>
> Any help will be greatly appreciated.
>
> Thanks,
>
> Ihsan.