| Author |
Message
|
| garonne |
Posted: Wed Mar 22, 2006 8:35 am Post subject: createXATopicSession problem |
|
|
Acolyte
Joined: 26 Jan 2006 Posts: 59
|
I have a program client of JOnAS. In the JNDI context of JOnAS, I have all the WebSphere MQ ConnectionFactory objects. My program try to receive messages from a MQ topic through these ConnectionFactory objects.
When I do:
Session session = tc.createSession(false, Session.AUTO_ACKNOWLEDGE);
or
Session session = tc.createSession(true, Session.AUTO_ACKNOWLEDGE);
It work! I can receive message
But It doesn't work when I do
Session session = tc.createXATopicSession();
and I receive no message, I don't see any exception
So, have anyone please explain this problem. Thanks alot!
Here is the code of my program:
// MsgReceptor.java
// JMS client program that will receive the messages published on the Topic
// by the EJB component
package jms;
import javax.jms.XATopicConnection;
import javax.jms.XATopicConnectionFactory;
import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.Message;
import javax.jms.MessageConsumer;
import javax.jms.MessageListener;
import javax.jms.ObjectMessage;
import javax.jms.Session;
import javax.jms.TextMessage;
import javax.jms.Topic;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
public class MsgReceptor {
//JNDI Context of JOnAS Application Server
private static Context ictx = null;
private static XATopicConnectionFactory cf = null;
private static Topic topic = null;
// JNDI name of the WebSphere MQ connection factory binded in JOnAS context
//private static String conFactName = "JCF";
//// JNDI name of the WebSphere MQ xa topic connection factory binded in JOnAS context
private static String conFactName = "wsmqXATCF";
// JNDI name of the Topic
private static String topicName = "sampleTopic";
public static void main(String[] arg) {
// Get InitialContext for JOnAS
try {
ictx = new InitialContext();
// lookup the TopicConnectionFactory through its JNDI name
cf = (XATopicConnectionFactory) ictx.lookup(conFactName);
System.out.println("JMS client: cf = " + cf.toString());
// lookup the Topic through its JNDI name
topic = (Topic) ictx.lookup(topicName);
System.out.println("JMS Topic topic = " + topic.toString());
} catch (NamingException e) {
e.printStackTrace();
System.exit(2);
}
try {
XATopicConnection tc = cf.createXATopicConnection();
System.out.println("JMS client: tc = " + tc.toString());
// this works!
//Session session = tc.createSession(false, Session.AUTO_ACKNOWLEDGE);
// this works!
Session session = tc.createSession(true, Session.AUTO_ACKNOWLEDGE);
// this DOES NOT work, I see NO EXCEPTION
//Session session = tc.createXATopicSession();
MessageConsumer mc = session.createConsumer(topic);
/* create and set a MessageListener */
MyListenerSimple listener = new MyListenerSimple();
mc.setMessageListener(listener);
System.out.println("JMS client: Waiting for messages ...");
tc.start();
System.in.read();
session.close();
tc.close();
} catch (Exception e) {
System.out.println("Exception in message reception operations");
e.printStackTrace();
}
}
} |
|
| Back to top |
|
 |
| fjb_saper |
Posted: Wed Mar 22, 2006 7:51 pm Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20773 Location: LI,NY
|
This looks very much like a stand alone JMS program.
You would have to run in a WebApplicationServer context to use XA.
Enjoy  _________________ MQ & Broker admin |
|
| Back to top |
|
 |
| garonne |
Posted: Wed Mar 22, 2006 11:23 pm Post subject: |
|
|
Acolyte
Joined: 26 Jan 2006 Posts: 59
|
| fjb_saper wrote: |
This looks very much like a stand alone JMS program.
You would have to run in a WebApplicationServer context to use XA.
Enjoy  |
OK,
But in fact it's nearly what happen in JOnAS when I try to receive message from a Message Driven Bean whose transport mode is transactional: as the Server Session start, the JMS Topic XASession run but the function onMessage of the MDB does not activated, message does not arrive... NO exception throwed; while it work well in the case with TopicSession and the non-transactional mode of the MDB. |
|
| Back to top |
|
 |
| fjb_saper |
Posted: Thu Mar 23, 2006 4:48 am Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20773 Location: LI,NY
|
That is exactly the problem. You need a J2EE container with the J2EE transaction manager to be able to do XA. If you just want a 2 phase commit with a Database check out the java base classes and the using java manual.
You should as well have a look at the admin manual as I believe some of the 2 phase commit with MQ as TM is explained in there.
Remember that the only 2 supported environments for a 2 phase commit with non MQ TM are: Websphere and Weblogic.
As well I would expect you to have to extract the session from the XASession. In your code it did not look like you were creating an XASession from the XAconnection.
| Code: |
XATopicConnection myconn = tcf.createXAConnection();
XASession xasess = myconn.createXASession(true, Session.AUTO_ACKNOWLEDGE);
Session mysess = xasess.getSession();
|
Enjoy  _________________ MQ & Broker admin |
|
| Back to top |
|
 |
| garonne |
Posted: Thu Mar 23, 2006 6:41 am Post subject: |
|
|
Acolyte
Joined: 26 Jan 2006 Posts: 59
|
| fjb_saper wrote: |
That is exactly the problem. You need a J2EE container with the J2EE transaction manager to be able to do XA. If you just want a 2 phase commit with a Database check out the java base classes and the using java manual.
You should as well have a look at the admin manual as I believe some of the 2 phase commit with MQ as TM is explained in there.
Remember that the only 2 supported environments for a 2 phase commit with non MQ TM are: Websphere and Weblogic.
As well I would expect you to have to extract the session from the XASession. In your code it did not look like you were creating an XASession from the XAconnection.
| Code: |
XATopicConnection myconn = tcf.createXAConnection();
XASession xasess = myconn.createXASession(true, Session.AUTO_ACKNOWLEDGE);
Session mysess = xasess.getSession();
|
Enjoy  |
thanks for your answer,
JOnAS has a transaction manager JOTM that can do XA. So I think that I have to write code to handle the interaction between JOnAS and MQ transaction managers in order to accomplish my program.
Do you think that's right??? |
|
| Back to top |
|
 |
| fjb_saper |
Posted: Thu Mar 23, 2006 1:34 pm Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20773 Location: LI,NY
|
Will JOnAS support user transaction?
Note JOnAS is only XA compatible. You can have MQ participate as an XA Resource. Make sure to extract the XA resource from the XASession.
I have had my own troubles with an XA Compliant TM (ATG).
Each week we have to force commit a number of messages and check them before moving them back into the flow....
Depending on the reliability of your TM you might get away with a single phase commit of both resources. (up to you and your architects).
I would not worry too much in case of an MDB as any other exception should get rethrown and ultimately trigger a rollback...
Enjoy  _________________ MQ & Broker admin |
|
| Back to top |
|
 |
| garonne |
Posted: Mon Mar 27, 2006 10:43 pm Post subject: |
|
|
Acolyte
Joined: 26 Jan 2006 Posts: 59
|
| fjb_saper wrote: |
I would not worry too much in case of an MDB as any other exception should get rethrown and ultimately trigger a rollback...
Enjoy  |
Sorry, I don't understand what you mean here. Can you clarify this?
In addition, can you explain how a transaction manager of an application server manage a JMS message reception XASession from WS MQ. |
|
| Back to top |
|
 |
| fjb_saper |
Posted: Tue Mar 28, 2006 4:32 am Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20773 Location: LI,NY
|
Read up on the J2EE model and bean managed /vs container managed transactions. Read up on JMS and MDB.
It will tell you much more in detail than I can.
Enjoy  _________________ MQ & Broker admin |
|
| Back to top |
|
 |
| garonne |
Posted: Tue Mar 28, 2006 4:45 am Post subject: |
|
|
Acolyte
Joined: 26 Jan 2006 Posts: 59
|
| fjb_saper wrote: |
Read up on the J2EE model and bean managed /vs container managed transactions. Read up on JMS and MDB.
It will tell you much more in detail than I can.
Enjoy  |
OK, Thanks alot. |
|
| Back to top |
|
 |
|
|