Author |
Message
|
balareddy |
Posted: Fri Feb 17, 2006 2:44 am Post subject: Session Transaction in JMS along with Oracle Transaction |
|
|
Acolyte
Joined: 06 Feb 2006 Posts: 54
|
Hi all,
I have stand alone Java application with JMS with Websphere MQ Queue as Message store. I wanted to implement Transactions on Oracle and JMS. As i came to know that distributed transaction is difficult to use without any application server like Websphere or Weblogic to support both Oracle and JMS.
How about JMS Session transaction?
connection.createQueueSession(true,Session.AUTO_ACKNOWLEDGE) whether can we use Oracle transaction and Session transaction both in parellel? If there is any rollback, Transactio.rollback() and session.rollback(). and for commit, transaction.commit() and session.commit()
Please tell me is session tranx wrong along with Oracle tranx? _________________ bala |
|
Back to top |
|
 |
BenR |
Posted: Fri Feb 17, 2006 2:49 am Post subject: |
|
|
Acolyte
Joined: 31 Jan 2006 Posts: 60 Location: Hursley, UK
|
If the session is transacted but you aren't using distributed transactions, then a JMS commit call won't cause Oracle to commit, you would have to do that separately with a JDBC commit call - i.e. you would have two separate transactions, rather than one distributed transaction. It may be that you can write your application in a way that makes this safe, but it needs great care.
The usual way to do this would be to use distributed transactions. For JMS these need to use an application server (at least to be supported by IBM), but the base Java API can do what you need without needing an application server (WMQ can act as an XA transaction manager). |
|
Back to top |
|
 |
balareddy |
Posted: Fri Feb 17, 2006 3:13 am Post subject: |
|
|
Acolyte
Joined: 06 Feb 2006 Posts: 54
|
BenR wrote: |
If the session is transacted but you aren't using distributed transactions, then a JMS commit call won't cause Oracle to commit, you would have to do that separately with a JDBC commit call - i.e. you would have two separate transactions, rather than one distributed transaction. It may be that you can write your application in a way that makes this safe, but it needs great care.
The usual way to do this would be to use distributed transactions. For JMS these need to use an application server (at least to be supported by IBM), but the base Java API can do what you need without needing an application server (WMQ can act as an XA transaction manager). |
Could you pls give me sample code/help on how WMQ can act as an XA transaction manager ??? _________________ bala |
|
Back to top |
|
 |
BenR |
Posted: Fri Feb 17, 2006 9:08 am Post subject: |
|
|
Acolyte
Joined: 31 Jan 2006 Posts: 60 Location: Hursley, UK
|
|
Back to top |
|
 |
balareddy |
Posted: Sun Feb 19, 2006 11:14 pm Post subject: |
|
|
Acolyte
Joined: 06 Feb 2006 Posts: 54
|
BenR wrote: |
http://www-128.ibm.com/developerworks/websphere/library/techarticles/0601_ritchie/0601_ritchie.html |
Sorry, it may not be useful for me because i am using Standard JMS accessing MQ with JNDI. so with Standard JMS how can i get MQQueueManager in my code? if i use that , it will not be pure JMS right??
Help me if i am wrong.
hope i explained clearly.. Pls let tell me what kind of tranx i can use for both Oracle and JMS.... _________________ bala |
|
Back to top |
|
 |
BenR |
Posted: Sun Feb 19, 2006 11:27 pm Post subject: |
|
|
Acolyte
Joined: 31 Jan 2006 Posts: 60 Location: Hursley, UK
|
If you *must* use JMS, then my understanding is that you have to use either WebLogic or WebSphere application server to do distributed transactions.
Outside the application server environment, WMQ JMS is limited to local transactions - distributed transactions with WMQ as transaction manager are not available. If you use local transactions, then instructing Oracle to commit will not make WMQ commit, and vice versa. You can write applications this way, but it takes very great care and isn't recommended if the data is of any great importance because there will usually be small windows where a system failure can leave your data in an inconsistent state.
If you don't have to use JMS, then you can do distributed transactions without the need for an application server if you use the base Java API. In this case, MQ acts as transaction manager, no application server is needed and your data will remain in a consistent state in the event of any system failure - but this function is not available to JMS.
Hope this helps. |
|
Back to top |
|
 |
balareddy |
Posted: Mon Feb 20, 2006 1:21 am Post subject: |
|
|
Acolyte
Joined: 06 Feb 2006 Posts: 54
|
what will happen if i use Transacted JMS session and session.commit() or session.rollback() along with Oracle transaction?
In case of critical problem like system crash/JVM error, Oracle Transaction will be rolled back if autocommit option is set. The same way, JMS session also will be rolled back right(if JMS Session is transacted)?
for example:::
session = connection.createQueueSession(true, Session. AUTO_ACKNOWLEDGE);
transaction.begin();
try{
----
----
transaction.commit();
session.commit();
}
catch(Exception e)
{
transaction.rollback();
session. rollback();
}
Please tell me is this implementation wrong? _________________ bala |
|
Back to top |
|
 |
markt |
Posted: Mon Feb 20, 2006 1:37 am Post subject: |
|
|
 Knight
Joined: 14 May 2002 Posts: 508
|
Transaction Processing 101: think about what happens if the system fails between the two commit() lines.
Hint: once a transaction has been committed it cannot be rolled back.
The result might be adequate for some applications, but it's almost certainly not what you expect or want. |
|
Back to top |
|
 |
fjb_saper |
Posted: Mon Feb 20, 2006 6:32 am Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
2 phase commit with JMS and the J2EE transaction server is truely supported by IBM only for WAS and Weblogic environments.
You can try it from another J2EE / XA compliant transaction manager but it is at your own risks and may not work exactly as you'd expect it.
To be able to do a 2 phase commit with MQ as an XA resource you need to have MQ on the same machine as the TransactionManager or use the transactional client (same $$ as having a server on that machine)...
Enjoy  _________________ MQ & Broker admin |
|
Back to top |
|
 |
balareddy |
Posted: Fri Feb 24, 2006 1:31 am Post subject: |
|
|
Acolyte
Joined: 06 Feb 2006 Posts: 54
|
Is it possible to handle Both Transactions(Oracle and JMS) with One single User defined Java Class?. Like, our class should merge both Tranx into One Tranx and controll full transaction model.
If possible, Please give me suggestion/sample how to implement our Own class to handle both Tranxs... _________________ bala |
|
Back to top |
|
 |
markt |
Posted: Fri Feb 24, 2006 1:41 am Post subject: |
|
|
 Knight
Joined: 14 May 2002 Posts: 508
|
Read a book such as Grey and Reuter (Principles of Transaction Processing). That gives you all the information you need on how to implement a transaction manager. |
|
Back to top |
|
 |
BenR |
Posted: Fri Feb 24, 2006 2:31 am Post subject: |
|
|
Acolyte
Joined: 31 Jan 2006 Posts: 60 Location: Hursley, UK
|
Quote: |
If possible, Please give me suggestion/sample how to implement our Own class to handle both Tranxs... |
It would be much, much easier to use the base Java API and let WMQ do the work for you.
I'd say that any time you're thinking of doing you're own transaction management it's a clue that your application design is wrong. You've got WMQ, which comes with very good support, so why throw that away by using the code in an unsupported way? |
|
Back to top |
|
 |
balareddy |
Posted: Fri Feb 24, 2006 2:40 am Post subject: |
|
|
Acolyte
Joined: 06 Feb 2006 Posts: 54
|
Quote: |
It would be much, much easier to use the base Java API and let WMQ do the work for you.
|
With base Java API, we can do it. WMQ will do everything.
But my concern is, I have to Impliment standard JMS with MQ as Q persistance. One more problem is i dont have to use any application server in my application. _________________ bala |
|
Back to top |
|
 |
BenR |
Posted: Fri Feb 24, 2006 2:50 am Post subject: |
|
|
Acolyte
Joined: 31 Jan 2006 Posts: 60 Location: Hursley, UK
|
If your requirements are :
- use distributed transactions with Oracle
- write a stand-alone application (i.e. don't use an application server)
- use JMS
- use WMQ
then one of those has to give. They don't fit together. The easiest IMHO would be to use the base Java API rather than JMS. |
|
Back to top |
|
 |
mvic |
Posted: Fri Feb 24, 2006 3:37 am Post subject: |
|
|
 Jedi
Joined: 09 Mar 2004 Posts: 2080
|
BenR wrote: |
If your requirements are :
- use distributed transactions with Oracle
- write a stand-alone application (i.e. don't use an application server)
- use JMS
- use WMQ
then one of those has to give. They don't fit together. The easiest IMHO would be to use the base Java API rather than JMS. |
It's a simpler calculation than that. You can't do distributed transactions in a stand-alone pure JMS application, period. Because there's no beginTransaction method. Or did I miss it? As far as I'm aware the support for distributed transactions in JMS is via the wider J2EE runtime environment.
Someone please correct me if I'm wrong. |
|
Back to top |
|
 |
|