Hi,

I need to get exception on send message in XA environment to rollback transaction. In production I use Spring 2.0 with Message-Driven POJO, Jencks (as XA-enabled connection pool only) and JOTM. Production configuration is complex, so I write very simple sending message example in standalone XA environment:

public class Producer {

        public static void main(String[] args) throws Exception {
                
                // start transaction manager
                TMService jotm = new Jotm(true, false);
                UserTransaction transaction = jotm.getUserTransaction();
                TransactionManager transactionManager = 
jotm.getTransactionManager();
                
                // start connection
                ActiveMQXAConnectionFactory connectionFactory =
                        new ActiveMQXAConnectionFactory("tcp://localhost:5000");
                XAConnection connection = 
connectionFactory.createXAConnection();
                XASession session = connection.createXASession();
                Destination destination = session.createQueue("error");
        MessageProducer producer = session.createProducer(destination);

        // send message
TextMessage message = session.createTextMessage("Test Message String");
        transaction.begin();

transactionManager.getTransaction().enlistResource(session.getXAResource());
        System.out.println(transactionManager.getTransaction());
        try {
                        producer.send(message);
                } catch (Exception e) {
                        System.out.println("EXCEPTION!!! : "+e);
                }
        transaction.commit();
        System.out.println("sent message : "+message.getJMSMessageID());

        // close connection
        session.close();
        connection.close();
        }

}

I can run ActiveMQ with authorization, so user can connect but can't send message or nobody can't send message to destination "queue://error". In this case I got:

INFO jotm - JOTM started with a local transaction factory which is not bound.
INFO  jotm - CAROL initialization
INFO ConfigurationRepository - No protocols were defined for property 'carol.protocols', trying with default protocol = 'jrmp'.
INFO  jta - JOTM 2.0.10
bb14:38:0:010f2192685af71b2c...f0a801:
WARN ActiveMQConnection - Async exception with no exception listener: java.lang.Exception: Error destination
java.lang.Exception: Error destination
        at simple.RestrictPlugin.send(RestrictPlugin.java:14)
at org.apache.activemq.broker.MutableBrokerFilter.send(MutableBrokerFilter.java:131) at org.apache.activemq.broker.AbstractConnection.processMessage(AbstractConnection.java:377) at org.apache.activemq.command.ActiveMQMessage.visit(ActiveMQMessage.java:603) at org.apache.activemq.broker.AbstractConnection.service(AbstractConnection.java:226) at org.apache.activemq.broker.TransportConnection$1.onCommand(TransportConnection.java:62) at org.apache.activemq.transport.ResponseCorrelator.onCommand(ResponseCorrelator.java:91) at org.apache.activemq.transport.TransportFilter.onCommand(TransportFilter.java:63) at org.apache.activemq.transport.WireFormatNegotiator.onCommand(WireFormatNegotiator.java:117) at org.apache.activemq.transport.InactivityMonitor.onCommand(InactivityMonitor.java:122) at org.apache.activemq.transport.TransportSupport.doConsume(TransportSupport.java:87) at org.apache.activemq.transport.tcp.TcpTransport.run(TcpTransport.java:127)
        at java.lang.Thread.run(Thread.java:595)
sent message : ID:prokopiev.stc.donpac.ru-51742-1158666713794-1:0:1:1:1


but I can't see EXCEPTION!!! row.

In more simple case without XA I see this exception:

public class Producer {

        public static void main(String[] args) throws Exception {
                
ActiveMQConnection connection = ActiveMQConnection.makeConnection("tcp://localhost:5000");
            connection.start();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
            Destination destination = session.createQueue("error");
MessageProducer producer = session.createProducer(destination);
            TextMessage message = session.createTextMessage("Test Message 
String");
            try {
                        producer.send(message);
                } catch (Exception e) {
                        System.out.println("EXCEPTION!!! : "+e);
                }
                session.close();
            connection.close();
}

In this case I see:

EXCEPTION!!! : javax.jms.JMSException: Error destination

Is it possible to get exception on send message in XA environment?

--
Thanks,
Eugene Prokopiev

Reply via email to