|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
 |
|
Design question on MDBs |
« View previous topic :: View next topic » |
Author |
Message
|
anveshita |
Posted: Fri Aug 22, 2008 1:56 pm Post subject: Design question on MDBs |
|
|
Master
Joined: 27 Sep 2004 Posts: 254 Location: Jambudweepam
|
Hi:
We have a legacy Java application that runs as stand alone.
Following is the flow of the application:
1. Program starts and spans two threads, theread 1 and thread 2
2. Thread 1 monitors a queue Q1 on local QM QM1. It basically makes a server connection to the
QM1,keeps monitoring the queue for every 10 seconds. Once a message is found on the queue, thread1
reads the message validates the message then spans another thread3 to process the message. Once the
message is handed over to thread3, the thread1 resumes montioring the queue.
3. Thread 2 monitors a queue Q2 on local QM QM1 and it follows the same process as Thread1, but at
a different time interval
Now I am asked to to convert this application to use MDBs in place of Thread1 and Thread 2 to monitor the queue.
I have basic understanding of MDBs, but not extensive knowledge. Can any one describe how the application may have
to modified to use the MDBs? A general view is helpful. If you have undertaken same problem, please share your thoughts.
Thanks |
|
Back to top |
|
 |
fjb_saper |
Posted: Sat Aug 23, 2008 4:32 am Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
The problem with MDB like processing, which is what you were doing, is the correct handling of transactionality... This can rapidly turn into a nightmare.
To make this easier, look into JMS and the MessageListener pattern.
You can use this as stand alone.
The difference with an MDB is that it runs within the J2EE container and some operations are automatically handled for you:
- transactionality of the MDB. Best done with transaction at container level and in the deployment descriptor. The onMessage method should have requires new in the transactionality.
- Thread safety -- processing of multiple messages in parallel.
This is here a combination of coding and J2EE container handling
- Scalability --
Running multiple instances of the MDB means that you have on thread watching for messages and up to the max instances defined threads processing. Remember that to achieve scalability your application cannot be dependent on message affinity.
Enjoy  _________________ MQ & Broker admin |
|
Back to top |
|
 |
anveshita |
Posted: Tue Aug 26, 2008 7:27 am Post subject: |
|
|
Master
Joined: 27 Sep 2004 Posts: 254 Location: Jambudweepam
|
Thanks fjb_saper.
Correct me if I am wrong, based on your suggestions, I should go with using MDBs. Right?
Quote: |
To make this easier, look into JMS and the MessageListener pattern.
|
Can you please suggest a document/redbook that has the above patterns listed? I will google for it, but if you have a book that is most useful, it helps.
Quote: |
Scalability --
Running multiple instances of the MDB means that you have on thread watching for messages and up to the max instances defined threads processing. Remember that to achieve scalability your application cannot be dependent on message affinity.
|
Could you please explain this further. I fear i did not understand the message affinity part?
Based on my requirement in original posting, do I end up re-writing the whole code? My program besides watching for message, is carrying out other tasks as well. With my limited knowledge of MDBs, I thought I could invoke MDB to start listening to a port for messages and stop it when not needed. If this possible then, I could just plug in logic to invoke MDBs in place of Thread1 and Thread2. Please let me know |
|
Back to top |
|
 |
fjb_saper |
Posted: Tue Aug 26, 2008 8:57 pm Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
[quote="anveshita"]Thanks fjb_saper.
Correct me if I am wrong, based on your suggestions, I should go with using MDBs. Right?
Quote: |
To make this easier, look into JMS and the MessageListener pattern.
|
Can you please suggest a document/redbook that has the above patterns listed? I will google for it, but if you have a book that is most useful, it helps.
Quote: |
Any decent JMS tutorial should cover the subject. It should also be covered in your J2EE server doc.
anveshita wrote: |
Scalability --
Running multiple instances of the MDB means that you have on thread watching for messages and up to the max instances defined threads processing. Remember that to achieve scalability your application cannot be dependent on message affinity.
|
Could you please explain this further. I fear i did not understand the message affinity part? |
Message affinity is when you need to process messages in a specific order.
This excludes scalability because a second thread would no longer respect the message sequence.
anveshita wrote: |
Based on my requirement in original posting, do I end up re-writing the whole code? My program besides watching for message, is carrying out other tasks as well. With my limited knowledge of MDBs, I thought I could invoke MDB to start listening to a port for messages and stop it when not needed. If this possible then, I could just plug in logic to invoke MDBs in place of Thread1 and Thread2. Please let me know |
You no longer need to watch for messages. The MDB will fire up the onMessage method whenever a message arrives. You should then process the message from within the current thread. The MDB setup takes care of all the threading issues.
Enjoy  _________________ MQ & Broker admin |
|
Back to top |
|
 |
anveshita |
Posted: Thu Aug 28, 2008 9:08 am Post subject: |
|
|
Master
Joined: 27 Sep 2004 Posts: 254 Location: Jambudweepam
|
Thanks.
Quote: |
You no longer need to watch for messages. The MDB will fire up the onMessage method whenever a message arrives. You should then process the message from within the current thread. The MDB setup takes care of all the threading issues.
|
I guess I am still not clear. My application is a stand alone jave application which does some processing besides spanning the threads for monitoring the queues. We control the application through scripts and start/stop it using the scripts. When we stop the application we also stop the threads that monitor the queues. Now if I use MDBs in place of threads which monitor the queueus, how do I achieve the same functionality for the stand alone application I am currently having for controlling the message monitoring part? Is there a way one can start the message listener for MDBs from stand aone alpplication? Bit confused.
Please let me know. |
|
Back to top |
|
 |
fjb_saper |
Posted: Thu Aug 28, 2008 2:58 pm Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
anveshita wrote: |
Thanks.
Quote: |
You no longer need to watch for messages. The MDB will fire up the onMessage method whenever a message arrives. You should then process the message from within the current thread. The MDB setup takes care of all the threading issues.
|
I guess I am still not clear. My application is a stand alone jave application which does some processing besides spanning the threads for monitoring the queues. We control the application through scripts and start/stop it using the scripts. When we stop the application we also stop the threads that monitor the queues. Now if I use MDBs in place of threads which monitor the queueus, how do I achieve the same functionality for the stand alone application I am currently having for controlling the message monitoring part? Is there a way one can start the message listener for MDBs from stand aone alpplication? Bit confused.
Please let me know. |
Sorry... Adding a MessageListener to your receiver is kind of the same thing as the MDB. What you will need to manage on your own there is connection, session and transactionality, as well as a ConnectionListener for errors on the connection... For the rest the onMessage method would act the same. You might want to run multiple threads... each thread should have its own connection. The qcf/tcf can be shared.
Enjoy  _________________ MQ & Broker admin |
|
Back to top |
|
 |
|
|
 |
|
Page 1 of 1 |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|
|
|