In order to obtain 2pc between MQ and a database, you will need
a transaction monitor. A you don't want to use an application
server, I would suggest using Tyrex (see exolab site ;-) ).

I successfully made XA transactions between MQSeries and DB2. Some
of the steps needed are :
- define your datasources in Tyrex config file
- build a JNDI context (see tyrex doc) with jndi datasources,
UserTransaction and TransactionManager entries
- castor database config file must use jndi entries
- if needed, call jdo.setTransactionManager() to set the jndi
name where you registered the transaction manager
- create your XA queue session just as you did before
- *important* : enlist MQ XA ressource with your transaction manager
tm.enlistResource(xaqs.getXAResource());

You can then implement your transactions as if you were coding for an
application server (get UserTransaction, begin/commit, ...).

Do not use db.begin() : the transaction demarcation must be coded
via UserTransaction (global transaction).

BTW, I have read that there is no transaction journal implemented in
Tyrex => recover operation after a crash won't work... Is this right ?

[EMAIL PROTECTED] a �crit :
> 
> We need to do a transaction that involves deleting record from a
> table, and send a message to MQSeires queue. As it involves different
> resources, I need to have a transaction manager to coordinate database
> and MQSeries. As this is a standalone app, I don't plan to use
> Websphere or other App Server.I am not sure whether castor can be used
> as a transaction manager, I tried as the following way:
> 
> //First get the database
>                 _jdo = new JDO();
>                 _jdo.setLogWriter( writer );
>                 _jdo.setConfiguration(url.toString());
>                 _jdo.setDatabaseName("default");
> 
>                 db = _jdo.getDatabase();
> 
> //Then set up the mqseries
>         MQXAQueueConnectionFactory        factory = new
> MQXAQueueConnectionFactory();
> 
> factory.setTransportType(com.ibm.mq.jms.JMSC.MQJMS_TP_CLIENT_MQ_TCPIP);
> 
>                 factory.setQueueManager(p_queuemanagername);
>                 factory.setHostName(p_hostname);
>                 factory.setPort(p_port);
> 
>     XAQueueConnection connection = factory.createXAQueueConnection();
>     connection.start();
>         MQXAQueueSession    session =
> (MQXAQueueSession)((MQXAQueueConnection)connection).createXAQueueSession();
> 
>       queueSender = session.getQueueSession().createSender(ioQueue);
> 
> //Then I tried to invoke start operation
>             db.begin();
> 
>                 String q = "select c from " +
> GIMessage.class.getName() + " c";
>                 OQLQuery oql = db.getOQLQuery(q);
>                 QueryResults results = null;
> 
>                 results = oql.execute();
>                 while ( results.hasMore() ) {
>                     GIMessage o = (GIMessage)results.next();
>                     String s = o.getContent();
> 
>                        TextMessage outMessage =
> session.createTextMessage();
>                        outMessage.setText(s);
>                         queueSender.send(outMessage);
> 
>                         db.remove(o);
>                 }
>                 results.close();
>                 results = null;
> 
>         db.commit();
> 
> However, I get the error,
> [test] javax.jms.JMSException: MQJMS2014: Queue manager rejected XA
> client connection
> [test]         at
> com.ibm.mq.jms.services.ConfigEnvironment.newException(ConfigEnvironment.java:530)
> 
> [test]         at
> com.ibm.mq.jms.MQConnection.createQM(MQConnection.java:1098)
> [test]         at
> com.ibm.mq.jms.MQConnection.createQMXA(MQConnection.java:757)
> [test]         at
> com.ibm.mq.jms.MQQueueConnection.<init>(MQQueueConnection.java:209)
> [test]         at
> com.ibm.mq.jms.MQQueueConnection.<init>(MQQueueConnection.java:78)
> [test]         at
> com.ibm.mq.jms.MQXAQueueConnection.<init>(MQXAQueueConnection.java:46)
> 
> [test]         at
> 
>com.ibm.mq.jms.MQXAQueueConnectionFactory.createXAQueueConnection(MQXAQueueConnectionFactory.java:53)
> 
> Is there anything wrong with my program?
> Hope somebody can help me out,
> Thanks a lot

-- 
Mickael Guessant

----------------------------------------------------------- 
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
        unsubscribe castor-dev

Reply via email to