diff --git a/examples/jms/pom.xml b/examples/jms/pom.xml index d5efa761ad..b7928dec41 100644 --- a/examples/jms/pom.xml +++ b/examples/jms/pom.xml @@ -128,7 +128,6 @@ under the License. xa-heuristic xa-receive xa-send - xa-with-jta diff --git a/examples/jms/xa-with-jta/pom.xml b/examples/jms/xa-with-jta/pom.xml deleted file mode 100644 index baf9b1abf8..0000000000 --- a/examples/jms/xa-with-jta/pom.xml +++ /dev/null @@ -1,137 +0,0 @@ - - - - - 4.0.0 - - - org.apache.activemq.examples.jms - jms-examples - 6.0.0-SNAPSHOT - - - activemq-jms-xa-with-jta-example - jar - ActiveMQ6 JMS XA with JTA Example - - - - org.apache.activemq.examples.jms - activemq-jms-examples-common - ${project.version} - - - org.apache.geronimo.specs - geronimo-jms_2.0_spec - - - org.apache.geronimo.specs - geronimo-ejb_3.0_spec - - - org.apache.geronimo.specs - geronimo-jta_1.1_spec - 1.1.1 - - - - - - - org.apache.activemq - activemq-maven-plugin - - - start - - start - - - - - build.directory - ${basedir}/target/ - - - - - - runClient - - runClient - - - org.apache.activemq.jms.example.XAwithJTAExample - - - - stop - - stop - - - - - - org.apache.activemq.examples.jms - activemq-jms-xa-with-jta-example - ${project.version} - - - org.apache.activemq - activemq-core-client - ${project.version} - - - org.apache.activemq - activemq-server - ${project.version} - - - org.apache.activemq - activemq-jms-client - ${project.version} - - - org.apache.activemq - activemq-jms-server - ${project.version} - - - io.netty - netty-all - ${netty.version} - - - org.apache.geronimo.specs - geronimo-jms_2.0_spec - ${geronimo.jms.2.spec.version} - - - - false - ${basedir}/target/classes/activemq/server0 - - - - - - diff --git a/examples/jms/xa-with-jta/readme.html b/examples/jms/xa-with-jta/readme.html deleted file mode 100644 index 8a77a37f61..0000000000 --- a/examples/jms/xa-with-jta/readme.html +++ /dev/null @@ -1,220 +0,0 @@ - - - - - ActiveMQ JMS XA with JTA Example - - - - - -

JMS XA with JTA Example

- -

This example shows you how to use JTA interfaces to control transactions with ActiveMQ. JTA provides - facilities to start and stop a transaction and enlist XA resources into a transaction.

- -

ActiveMQ is JTA aware, meaning you can use ActiveMQ in a XA transactional environment - and participate in XA transactions. It provides the javax.transaction.xa.XAResource interface for that - purpose. Users can get a XAConnectionFactory to create XAConnections and XASessions.

- -

In this example we get a transaction manager from JBoss JTA to control the transactions. First we create an XASession - for receiving and a normal session for sending. Then we start a new xa transaction and enlist the receiving - XASession through its XAResource. We then send two words, 'hello' and 'world', receive them, and let the - transaction roll back. The received messages are cancelled back to the queue. Next we start - a new transaction with the same XAResource enlisted, but this time we commit the transaction after receiving the - messages. Then we check that no more messages are to be received. In each transaction a dummy XAResource is also - enlisted to show the transaction processing information.

- -

Example step-by-step

-

To run the example, simply type mvn verify from this directory. It will download the JBoss JTA jars before - it launches the example.

- -
    -
  1. First we need to get an initial context so we can look-up the JMS connection factory and destination objects from JNDI. This initial context will get it's properties from the client-jndi.properties file in the directory ../common/config
  2. -
    -           InitialContext initialContext = getContext(0);
    -        
    - -
  3. We look-up the JMS queue object from JNDI
  4. -
    -           Queue queue = (Queue) initialContext.lookup("/queue/exampleQueue");
    -        
    - -
  5. We perform a lookup on the XA Connection Factory
  6. -
    -           XAConnectionFactory cf = (XAConnectionFactory) initialContext.lookup("/XAConnectionFactory");
    -        
    - -
  7. We create a JMS XAConnection
  8. -
    -           connection = cf.createXAConnection();
    -        
    - -
  9. We Start the connection
  10. -
    -           connection.start();
    -        
    - -
  11. We create a JMS XASession
  12. -
    -          XASession xaSession = connection.createXASession();
    -       
    - -
  13. We create a normal session
  14. -
    -          Session normalSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    -       
    - -
  15. We create a normal Message Producer
  16. -
    -           
    -           MessageProducer normalProducer = normalSession.createProducer(queue);
    -           
    -       
    - -
  17. We get the JMS Session
  18. -
    -          Session session = xaSession.getSession();
    -       
    - -
  19. We create a message consumer
  20. -
    -          MessageConsumer xaConsumer = session.createConsumer(queue); 
    -       
    - -
  21. We create two Text Messages
  22. -
    -          
    -          TextMessage helloMessage = session.createTextMessage("hello");
    -          TextMessage worldMessage = session.createTextMessage("world");
    -          
    -       
    - -
  23. We get the Transaction Manager
  24. -
    -          javax.transaction.TransactionManager txMgr = TransactionManager.transactionManager();
    -       
    - -
  25. We start a transaction
  26. -
    -          txMgr.begin();
    -       
    - -
  27. We get the JMS XAResource
  28. -
    -          XAResource xaRes = xaSession.getXAResource();
    -       
    - -
  29. We enlist the resources in the Transaction work
  30. -
    -          
    -          Transaction transaction = txMgr.getTransaction();
    -          transaction.enlistResource(new DummyXAResource());
    -          transaction.enlistResource(xaRes);
    -          
    -       
    - -
  31. We send two messages.
  32. -
    -          
    -         normalProducer.send(helloMessage);
    -         normalProducer.send(worldMessage);
    -          
    -       
    - -
  33. We receive the messages
  34. -
    -          
    -          TextMessage rm1 = (TextMessage)xaConsumer.receive();
    -          System.out.println("Message received: " + rm1.getText());
    -          TextMessage rm2 = (TextMessage)xaConsumer.receive();
    -          System.out.println("Message received: " + rm2.getText());
    -          
    -       
    - -
  35. We roll back the transaction
  36. -
    -          txMgr.rollback();
    -       
    - -
  37. We create another transaction
  38. -
    -          
    -          txMgr.begin();
    -          transaction = txMgr.getTransaction();
    -          
    -       
    - -
  39. We enlist the resources to start the transaction work
  40. -
    -                   
    -          transaction.enlistResource(new DummyXAResource());
    -          transaction.enlistResource(xaRes);
    -          
    -       
    - -
  41. We receive those messages again
  42. -
    -           
    -           rm1 = (TextMessage)xaConsumer.receive();
    -           System.out.println("Message received again: " + rm1.getText());
    -           rm2 = (TextMessage)xaConsumer.receive();
    -           System.out.println("Message received again: " + rm2.getText());
    -            
    -       
    - -
  43. We commit
  44. -
    -          txMgr.commit();
    -       
    - -
  45. We check that no more messages are received.
  46. -
    -          
    -          TextMessage rm3 = (TextMessage)xaConsumer.receive(2000);
    -          if (rm3 == null)
    -          {
    -             System.out.println("No message received after commit.");
    -          }
    -          else
    -          {
    -             result = false;
    -          }
    -          
    -       
    - -
  47. And finally, always remember to close your JMS connections and resources after use, in a finally block. Closing a JMS connection will automatically close all of its sessions, consumers, producer and browser objects
  48. - -
    -           finally
    -           {
    -              if (initialContext != null)
    -              {
    -                initialContext.close();
    -              }
    -              if (connection != null)
    -              {
    -                 connection.close();
    -              }
    -           }
    -        
    -
- - diff --git a/examples/jms/xa-with-jta/src/main/java/org/apache/activemq/jms/example/XAwithJTAExample.java b/examples/jms/xa-with-jta/src/main/java/org/apache/activemq/jms/example/XAwithJTAExample.java deleted file mode 100644 index abeed14bb0..0000000000 --- a/examples/jms/xa-with-jta/src/main/java/org/apache/activemq/jms/example/XAwithJTAExample.java +++ /dev/null @@ -1,220 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.activemq.jms.example; - -import javax.jms.MessageConsumer; -import javax.jms.MessageProducer; -import javax.jms.Queue; -import javax.jms.Session; -import javax.jms.TextMessage; -import javax.jms.XAConnection; -import javax.jms.XAConnectionFactory; -import javax.jms.XASession; -import javax.naming.InitialContext; -import javax.transaction.Transaction; -import javax.transaction.xa.XAException; -import javax.transaction.xa.XAResource; -import javax.transaction.xa.Xid; - -import org.apache.activemq.common.example.ActiveMQExample; - -/** - * A simple JMS example showing the ActiveMQ XA support with JTA. - * - * @author Howard Gao - */ -public class XAwithJTAExample extends ActiveMQExample -{ - private volatile boolean result = true; - - public static void main(final String[] args) - { - new XAwithJTAExample().run(args); - } - - @Override - public boolean runExample() throws Exception - { - XAConnection connection = null; - InitialContext initialContext = null; - try - { - // Step 1. Create an initial context to perform the JNDI lookup. - initialContext = new InitialContext(); - - // Step 2. Lookup on the queue - Queue queue = (Queue)initialContext.lookup("queue/exampleQueue"); - - // Step 3. Perform a lookup on the XA Connection Factory - XAConnectionFactory cf = (XAConnectionFactory)initialContext.lookup("XAConnectionFactory"); - - // Step 4.Create a JMS XAConnection - connection = cf.createXAConnection(); - - // Step 5. Start the connection - connection.start(); - - // Step 6. Create a JMS XASession - XASession xaSession = connection.createXASession(); - - // Step 7. Create a normal session - Session normalSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); - - // Step 8. Create a normal Message Producer - MessageProducer normalProducer = normalSession.createProducer(queue); - - // Step 9. Get the JMS Session - Session session = xaSession.getSession(); - - // Step 10. Create a message consumer - MessageConsumer xaConsumer = session.createConsumer(queue); - - // Step 11. Create two Text Messages - TextMessage helloMessage = session.createTextMessage("hello"); - TextMessage worldMessage = session.createTextMessage("world"); - - // Step 12. Get the Transaction Manager - javax.transaction.TransactionManager txMgr = TransactionManager.transactionManager(); - - // Step 13. Start a transaction - txMgr.begin(); - - // Step 14. Get the JMS XAResource - XAResource xaRes = xaSession.getXAResource(); - - // Step 15. enlist the resource in the Transaction work - Transaction transaction = txMgr.getTransaction(); - transaction.enlistResource(new DummyXAResource()); - transaction.enlistResource(xaRes); - - // Step 16. Send two messages. - normalProducer.send(helloMessage); - normalProducer.send(worldMessage); - - // Step 17. Receive the message - TextMessage rm1 = (TextMessage)xaConsumer.receive(); - System.out.println("Message received: " + rm1.getText()); - TextMessage rm2 = (TextMessage)xaConsumer.receive(); - System.out.println("Message received: " + rm2.getText()); - - // Step 18. Roll back the transaction - txMgr.rollback(); - - // Step 19. Create another transaction - txMgr.begin(); - transaction = txMgr.getTransaction(); - - // Step 20. Enlist the resources to start the transaction work - transaction.enlistResource(new DummyXAResource()); - transaction.enlistResource(xaRes); - - // Step 21. receive those messages again - rm1 = (TextMessage)xaConsumer.receive(); - System.out.println("Message received again: " + rm1.getText()); - rm2 = (TextMessage)xaConsumer.receive(); - System.out.println("Message received again: " + rm2.getText()); - - // Step 22. Commit! - txMgr.commit(); - - // Step 23. Check no more messages are received. - TextMessage rm3 = (TextMessage)xaConsumer.receive(2000); - if (rm3 == null) - { - System.out.println("No message received after commit."); - } - else - { - result = false; - } - - return result; - } - finally - { - // Step 24. Be sure to close our JMS resources! - if (initialContext != null) - { - initialContext.close(); - } - if (connection != null) - { - connection.close(); - } - } - } - - public static class DummyXAResource implements XAResource - { - - public DummyXAResource() - { - } - - public void commit(final Xid xid, final boolean arg1) throws XAException - { - System.out.println("DummyXAResource commit() called, xid: " + xid); - } - - public void end(final Xid xid, final int arg1) throws XAException - { - System.out.println("DummyXAResource end() called, xid: " + xid); - } - - public void forget(final Xid xid) throws XAException - { - System.out.println("DummyXAResource forget() called, xid: " + xid); - } - - public int getTransactionTimeout() throws XAException - { - return 0; - } - - public boolean isSameRM(final XAResource arg0) throws XAException - { - return this == arg0; - } - - public int prepare(final Xid xid) throws XAException - { - return XAResource.XA_OK; - } - - public Xid[] recover(final int arg0) throws XAException - { - return null; - } - - public void rollback(final Xid xid) throws XAException - { - System.out.println("DummyXAResource rollback() called, xid: " + xid); - } - - public boolean setTransactionTimeout(final int arg0) throws XAException - { - return false; - } - - public void start(final Xid xid, final int arg1) throws XAException - { - System.out.println("DummyXAResource start() called, Xid: " + xid); - } - - } - -} diff --git a/examples/jms/xa-with-jta/src/main/resources/activemq/server0/activemq-configuration.xml b/examples/jms/xa-with-jta/src/main/resources/activemq/server0/activemq-configuration.xml deleted file mode 100644 index 9f7ef1c0f8..0000000000 --- a/examples/jms/xa-with-jta/src/main/resources/activemq/server0/activemq-configuration.xml +++ /dev/null @@ -1,54 +0,0 @@ - - - - - - ${build.directory}/server0/data/messaging/bindings - - ${build.directory}/server0/data/messaging/journal - - ${build.directory}/server0/data/messaging/largemessages - - ${build.directory}/server0/data/messaging/paging - - - - - org.apache.activemq.core.remoting.impl.netty.NettyAcceptorFactory - - - - - - - - - - - - - - - - - - diff --git a/examples/jms/xa-with-jta/src/main/resources/activemq/server0/activemq-jms.xml b/examples/jms/xa-with-jta/src/main/resources/activemq/server0/activemq-jms.xml deleted file mode 100644 index 8ca9fd6e26..0000000000 --- a/examples/jms/xa-with-jta/src/main/resources/activemq/server0/activemq-jms.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - - - - diff --git a/examples/jms/xa-with-jta/src/main/resources/activemq/server0/activemq-users.xml b/examples/jms/xa-with-jta/src/main/resources/activemq/server0/activemq-users.xml deleted file mode 100644 index f63079de03..0000000000 --- a/examples/jms/xa-with-jta/src/main/resources/activemq/server0/activemq-users.xml +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - - - - diff --git a/examples/jms/xa-with-jta/src/main/resources/jbossts-properties.xml b/examples/jms/xa-with-jta/src/main/resources/jbossts-properties.xml deleted file mode 100644 index 8eb68a4220..0000000000 --- a/examples/jms/xa-with-jta/src/main/resources/jbossts-properties.xml +++ /dev/null @@ -1,175 +0,0 @@ - - - - - - - - YES - - - PutObjectStoreDirHere - - - ON - - - 1 - - - 1 - - - com.arjuna.ats.internal.jta.recovery.arjunacore.JTATransactionLogXAResourceOrphanFilter - com.arjuna.ats.internal.jta.recovery.arjunacore.JTANodeNameXAResourceOrphanFilter - - - - 0 - - - - - - com.arjuna.ats.internal.arjuna.recovery.AtomicActionRecoveryModule - com.arjuna.ats.internal.txoj.recovery.TORecoveryModule - com.arjuna.ats.internal.jts.recovery.transactions.TopLevelTransactionRecoveryModule - com.arjuna.ats.internal.jts.recovery.transactions.ServerTransactionRecoveryModule - com.arjuna.ats.internal.jta.recovery.jts.XARecoveryModule - - - - - com.arjuna.ats.internal.arjuna.recovery.ExpiredTransactionStatusManagerScanner - com.arjuna.ats.internal.jts.recovery.contact.ExpiredContactScanner - com.arjuna.ats.internal.jts.recovery.transactions.ExpiredToplevelScanner - com.arjuna.ats.internal.jts.recovery.transactions.ExpiredServerScanner - - - - - - 4712 - - - - - 0 - - - - - - YES - - - - com.arjuna.ats.internal.jts.orbspecific.recovery.RecoveryEnablement - - - com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionManagerImple - - com.arjuna.ats.internal.jta.transaction.arjunacore.UserTransactionImple - - com.arjuna.ats.internal.jta.transaction.jts.TransactionSynchronizationRegistryImple - - - CONFIGURATION_FILE - - - - com.arjuna.orbportability.orb.PreInit1=com.arjuna.ats.internal.jts.context.ContextPropagationManager - - com.arjuna.orbportability.orb.PostInit=com.arjuna.ats.jts.utils.ORBSetup - - com.arjuna.orbportability.orb.PostInit2=com.arjuna.ats.internal.jts.recovery.RecoveryInit - - com.arjuna.orbportability.orb.PostSet1=com.arjuna.ats.jts.utils.ORBSetup - - - - 4711 - - - - - - diff --git a/examples/jms/xa-with-jta/src/main/resources/jndi.properties b/examples/jms/xa-with-jta/src/main/resources/jndi.properties deleted file mode 100644 index 6364ce46d9..0000000000 --- a/examples/jms/xa-with-jta/src/main/resources/jndi.properties +++ /dev/null @@ -1,20 +0,0 @@ -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. - -java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory -java.naming.provider.url=tcp://localhost:5445 -queue.queue/exampleQueue=exampleQueue