ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » IBM MQ Java / JMS » createXATopicSession problem

Post new topic  Reply to topic
 createXATopicSession problem « View previous topic :: View next topic » 
Author Message
garonne
PostPosted: Wed Mar 22, 2006 8:35 am    Post subject: createXATopicSession problem Reply with quote

Acolyte

Joined: 26 Jan 2006
Posts: 59

I have a program client of contact admin. In the JNDI context of contact admin, 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 contact admin 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 contact admin context
//private static String conFactName = "JCF";

//// JNDI name of the WebSphere MQ xa topic connection factory binded in contact admin 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 contact admin
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
View user's profile Send private message
fjb_saper
PostPosted: Wed Mar 22, 2006 7:51 pm    Post subject: Reply with quote

Grand High Poobah

Joined: 18 Nov 2003
Posts: 20756
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
View user's profile Send private message Send e-mail
garonne
PostPosted: Wed Mar 22, 2006 11:23 pm    Post subject: Reply with quote

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 contact admin 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
View user's profile Send private message
fjb_saper
PostPosted: Thu Mar 23, 2006 4:48 am    Post subject: Reply with quote

Grand High Poobah

Joined: 18 Nov 2003
Posts: 20756
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
View user's profile Send private message Send e-mail
garonne
PostPosted: Thu Mar 23, 2006 6:41 am    Post subject: Reply with quote

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,

contact admin has a transaction manager JOTM that can do XA. So I think that I have to write code to handle the interaction between contact admin and MQ transaction managers in order to accomplish my program.

Do you think that's right???
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Thu Mar 23, 2006 1:34 pm    Post subject: Reply with quote

Grand High Poobah

Joined: 18 Nov 2003
Posts: 20756
Location: LI,NY

Will contact admin support user transaction?

Note contact admin 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
View user's profile Send private message Send e-mail
garonne
PostPosted: Mon Mar 27, 2006 10:43 pm    Post subject: Reply with quote

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
View user's profile Send private message
fjb_saper
PostPosted: Tue Mar 28, 2006 4:32 am    Post subject: Reply with quote

Grand High Poobah

Joined: 18 Nov 2003
Posts: 20756
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
View user's profile Send private message Send e-mail
garonne
PostPosted: Tue Mar 28, 2006 4:45 am    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » IBM MQ Java / JMS » createXATopicSession problem
Jump to:  



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
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.