• Post Reply Bookmark Topic Watch Topic
  • New Topic

MDB synchronize onMessage  RSS feed

 
P Igor
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can we somehow synchronize the onMessage() method of MDB so that when a message is being processed, other messages are not processed?

I have a application which is receiving similar message from 2 interfacing applications, but from a seperate Q(listener). So, I want my MDB not to process message 2 from application 2 if it is processing message 1 from application 1. How can I achieve this?

Appreciate your help
 
Vinay Raj
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using Jboss as an example here. Probably something similiar should be available with your app. server.

Within the MDB tag definition Jboss provides two tags maximumSize and maximumMessages. Set both to 1 and it should achieve the functionality that you require. For Jboss tag specific details refer url.

The above replies the first part of your question. Note this will not work in a clustered environment.

For the second portion, easier option is to force both the applications to send messages on the same queue. Using the technique mentioned above you can control the processing in a non-clustered environment.

If that is not possible you will need to develop a locking mechanism using a database. Insert a row in the db for the message being processed and on completion reset the message flag to processed. This would work irrespective if the deployment is clustered or not.
 
P Igor
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Vinay.
I am using Websphere App Server 6.0. Any idea whether setting maxSize & maxMessage to 1 works in WAS6?
 
Vinay Raj
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did some research. Here are two links that might provide pointers. link1 and link2. Hope this proves to be useful.
If this works, think IBM should come up with an easier(user-friendly) way to do things.
 
P Igor
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks.
Setting maxSize and maxMessage to 1 will solve my problem or I should do as mentioned in link 1 and link 2?
[ November 27, 2006: Message edited by: P Igor ]
 
Vinay Raj
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Setting maxSize and maxMessage is JBoss specific. For WAS specific implementation use link1 and link2 options.
 
P Igor
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<listenerPorts connectionFactoryJNDIName="jms/QCF/IRMatchDriver" description="Listener port for the MDB" destinationJNDIName="jms/Q/IRMatchDriverRequest" maxMessages="1" maxRetries="0" maxSessions="1" name="IRListenerPort" xmi:id="ListenerPort_1153928187496">
<stateManagement initialState="START" xmi:id="StateManageable_1153928187546"/>
</listenerPorts>

This is from the server.xml file. As you see, it has maxSessions & maxMessages property & both are set to 1. Will this work?
 
keshav n
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am new to MDBs.. but should not the container take care of concurrency related stuff in EJBs? I would assume the default setting would be to make them thread safe?
 
Vinay Raj
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
P Igor,

If those settings are available in WAS, it should work. Note that you are still not taking care of a clustered environment.

Keshav N,

Yes, the application server is responsible for taking care of concurrency issues, but what Igor wants is more than that.
 
Bhaskar Rao
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

In WAS, the number of instances of the MDB that are maintained in the pool is configurable. If the pool size is set to 1, concurrency issue may be solved, but will definitely impact the performance.
 
P Igor
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In WAS, how do I configure so that the MDB instance in pool is 1? Performance is not a issue, for now.
 
Jeevan Philip
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Using thread synchronization within EJBs are not recommended. There can be undesirable effects.

Also you are defeating the purpose of using EJBs(scalability thru pooling) by allowing it to process only one request at a time. This effectively means that you can have only one listener, not a pool.

If your intention is to listen to a Q and process messages one at a time, use a POJO which implements MessageListener sync the onMessage() method.

Jeevan.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!