----- Original Message -----
From: sbuster <stevebuster...@hotmail.com>
To: users@activemq.apache.org <users@activemq.apache.org>
Sent: Mon Sep 07 09:24:16 2009
Subject: Another XA Transaction question


I'm using ActiveMQ 5.2 with WebSphere 7.0 and Sun JavaDB 10.x.  Pretty
standard requirement, I have a message that arrives on a Queue, gets pulled
off with Message Drive Bean and needs to be directly insert into JavaDB. 
However, when I thrown an exception inside my MDB to test the rollback
capabilities, the database is rolled back, the the messages is never rolled
back. The message is never placed back on the queue, it gets consumed
somehow.   I have "transaction required" set in the MDB deployment file(see
below) and I've even tried changing the ra.xml file for ActiveMQ to
specifically state ActiveMQXAConnection factory.  Can anyone help?





ejb deployment file
<?xml version="1.0" encoding="UTF-8"?>
<ejb-jar id="ejb-jar_ID" version="2.1"
xmlns="http://java.sun.com/xml/ns/j2ee";
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd";>
        <display-name>MessageEngine2</display-name>
        <enterprise-beans>
                <message-driven id="EventConsumer">
                        <ejb-name>EventConsumer</ejb-name>
                        
<ejb-class>cat.cw.messaging.EventConsumerBean</ejb-class>
                        
<messaging-type>javax.jms.MessageListener</messaging-type>
                        <transaction-type>Container</transaction-type>
                        
<message-destination-type>javax.jms.Queue</message-destination-type>
                        <activation-config>
                                <activation-config-property>
                                
<activation-config-property-name>destinationType</activation-config-property-name>
                                
<activation-config-property-value>javax.jms.Queue</activation-config-property-value>
                                </activation-config-property>
                        </activation-config>
                        <resource-ref id="ResourceRef_1251986165885">
                                <description>
                                </description>
                                <res-ref-name>jdbc/NSSampleDB</res-ref-name>
                                <res-type>javax.sql.DataSource</res-type>
                                <res-auth>Container</res-auth>
                                <res-sharing-scope>Shareable</res-sharing-scope>
                        </resource-ref>
                </message-driven>
        </enterprise-beans>
        <assembly-descriptor>
                <container-transaction>
                        <method>
                                <ejb-name>EventConsumer</ejb-name>
                                <method-name>*</method-name>
                        </method>
                        <trans-attribute>Required</trans-attribute>
                </container-transaction>
        </assembly-descriptor>
</ejb-jar>


MDB
public void onMessage(javax.jms.Message msg) {
                
                
                InitialContext ctx = null;
                Connection con = null;
                PreparedStatement stmt = null;
                try {
                        String txtMsg = null;
                        if(msg instanceof BytesMessage){
                                txtMsg = readByteData((BytesMessage)msg);
                        }else{
                                txtMsg = ((TextMessage)msg).getText();
                        }
                        ctx = new InitialContext();
                        DataSource ds = 
(DataSource)ctx.lookup("jdbc/NSSampleDB");
                        con = ds.getConnection();
                        con.setAutoCommit(false);
                        stmt = con.prepareStatement("insert into 
app.messages(message)
values(?)");
                        
                        stmt.setString(1,txtMsg);
                        int result = stmt.executeUpdate();
                        if(txtMsg.equalsIgnoreCase("error")){
                                throw new Exception("error");
                        }
                        //con.commit();
                        System.out.println("inserted message:");
                        
                        
                } catch (Exception e) {
                        // TODO Auto-generated catch block
                        fMessageDrivenCtx.setRollbackOnly();
                        System.out.println(e.getMessage());
                }finally{
                        try{
                        stmt.close();
                        con.close();
                        }catch(Exception e){}
                }
        }
-- 
View this message in context: 
http://www.nabble.com/Another-XA-Transaction-question-tp25331346p25331346.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Reply via email to