Search in sources :

Example 1 with ActiveMQXAConnectionFactory

use of org.apache.activemq.artemis.jms.client.ActiveMQXAConnectionFactory in project activemq-artemis by apache.

the class JMSBridgeReconnectionTest method performCrashAndReconnect.

private void performCrashAndReconnect(boolean restart) throws Exception {
    cff1xa = new ConnectionFactoryFactory() {

        @Override
        public Object createConnectionFactory() throws Exception {
            ActiveMQXAConnectionFactory cf = (ActiveMQXAConnectionFactory) ActiveMQJMSClient.createConnectionFactoryWithHA(JMSFactoryType.XA_CF, new TransportConfiguration(INVM_CONNECTOR_FACTORY, params1));
            // Note! We disable automatic reconnection on the session factory. The bridge needs to do the reconnection
            cf.setReconnectAttempts(-1);
            cf.setBlockOnNonDurableSend(true);
            cf.setBlockOnDurableSend(true);
            cf.setCacheLargeMessagesClient(true);
            return cf;
        }
    };
    DummyTransactionManager tm = new DummyTransactionManager();
    DummyTransaction tx = new DummyTransaction();
    tm.tx = tx;
    JMSBridgeImpl bridge = new JMSBridgeImpl(cff0xa, cff1xa, sourceQueueFactory, targetQueueFactory, null, null, null, null, null, 1000, -1, QualityOfServiceMode.ONCE_AND_ONLY_ONCE, 10, 5000, null, null, false).setBridgeName("test-bridge");
    addActiveMQComponent(bridge);
    bridge.setTransactionManager(tm);
    bridge.start();
    // Now crash the dest server
    JMSBridgeReconnectionTest.log.info("About to crash server");
    jmsServer1.stop();
    if (restart) {
        jmsServer1.start();
    }
    // Wait a while before starting up to simulate the dest being down for a while
    JMSBridgeReconnectionTest.log.info("Waiting 5 secs before bringing server back up");
    Thread.sleep(TIME_WAIT);
    JMSBridgeReconnectionTest.log.info("Done wait");
    bridge.stop();
    if (restart) {
        assertTrue(tx.rolledback);
        assertTrue(tx.targetConnected);
    } else {
        assertTrue(tx.rolledback);
        assertFalse(tx.targetConnected);
    }
}
Also used : DummyTransactionManager(org.apache.activemq.artemis.tests.integration.ra.DummyTransactionManager) JMSBridgeImpl(org.apache.activemq.artemis.jms.bridge.impl.JMSBridgeImpl) ConnectionFactoryFactory(org.apache.activemq.artemis.jms.bridge.ConnectionFactoryFactory) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) HeuristicRollbackException(javax.transaction.HeuristicRollbackException) SystemException(javax.transaction.SystemException) RollbackException(javax.transaction.RollbackException) HeuristicMixedException(javax.transaction.HeuristicMixedException) ActiveMQXAConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQXAConnectionFactory)

Example 2 with ActiveMQXAConnectionFactory

use of org.apache.activemq.artemis.jms.client.ActiveMQXAConnectionFactory in project activemq-artemis by apache.

the class BridgeTestBase method setUpAdministeredObjects.

protected void setUpAdministeredObjects() throws Exception {
    cff0LowProducerWindow = new ConnectionFactoryFactory() {

        @Override
        public ConnectionFactory createConnectionFactory() throws Exception {
            ActiveMQConnectionFactory cf = ActiveMQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF, new TransportConfiguration(INVM_CONNECTOR_FACTORY));
            // Note! We disable automatic reconnection on the session factory. The bridge needs to do the reconnection
            cf.setReconnectAttempts(0);
            cf.setBlockOnNonDurableSend(true);
            cf.setBlockOnDurableSend(true);
            cf.setCacheLargeMessagesClient(true);
            cf.setProducerWindowSize(100);
            return cf;
        }
    };
    cff0 = new ConnectionFactoryFactory() {

        @Override
        public ConnectionFactory createConnectionFactory() throws Exception {
            ActiveMQConnectionFactory cf = ActiveMQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF, new TransportConfiguration(INVM_CONNECTOR_FACTORY));
            // Note! We disable automatic reconnection on the session factory. The bridge needs to do the reconnection
            cf.setReconnectAttempts(0);
            cf.setBlockOnNonDurableSend(true);
            cf.setBlockOnDurableSend(true);
            cf.setCacheLargeMessagesClient(true);
            return cf;
        }
    };
    cff0xa = new ConnectionFactoryFactory() {

        @Override
        public Object createConnectionFactory() throws Exception {
            ActiveMQXAConnectionFactory cf = (ActiveMQXAConnectionFactory) ActiveMQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.XA_CF, new TransportConfiguration(INVM_CONNECTOR_FACTORY));
            // Note! We disable automatic reconnection on the session factory. The bridge needs to do the reconnection
            cf.setReconnectAttempts(0);
            cf.setBlockOnNonDurableSend(true);
            cf.setBlockOnDurableSend(true);
            cf.setCacheLargeMessagesClient(true);
            return cf;
        }
    };
    cf0 = (ConnectionFactory) cff0.createConnectionFactory();
    cf0xa = (XAConnectionFactory) cff0xa.createConnectionFactory();
    cff1 = new ConnectionFactoryFactory() {

        @Override
        public ConnectionFactory createConnectionFactory() throws Exception {
            ActiveMQJMSConnectionFactory cf = (ActiveMQJMSConnectionFactory) ActiveMQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF, new TransportConfiguration(INVM_CONNECTOR_FACTORY, params1));
            // Note! We disable automatic reconnection on the session factory. The bridge needs to do the reconnection
            cf.setReconnectAttempts(0);
            cf.setBlockOnNonDurableSend(true);
            cf.setBlockOnDurableSend(true);
            cf.setCacheLargeMessagesClient(true);
            return cf;
        }
    };
    cff1xa = new ConnectionFactoryFactory() {

        @Override
        public XAConnectionFactory createConnectionFactory() throws Exception {
            ActiveMQXAConnectionFactory cf = (ActiveMQXAConnectionFactory) ActiveMQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.XA_CF, new TransportConfiguration(INVM_CONNECTOR_FACTORY, params1));
            // Note! We disable automatic reconnection on the session factory. The bridge needs to do the reconnection
            cf.setReconnectAttempts(0);
            cf.setBlockOnNonDurableSend(true);
            cf.setBlockOnDurableSend(true);
            cf.setCacheLargeMessagesClient(true);
            return cf;
        }
    };
    cf1 = (ConnectionFactory) cff1.createConnectionFactory();
    cf1xa = (XAConnectionFactory) cff1xa.createConnectionFactory();
    sourceQueueFactory = new DestinationFactory() {

        @Override
        public Destination createDestination() throws Exception {
            return (Destination) context0.lookup("/queue/sourceQueue");
        }
    };
    sourceQueue = (Queue) sourceQueueFactory.createDestination();
    targetQueueFactory = new DestinationFactory() {

        @Override
        public Destination createDestination() throws Exception {
            return (Destination) context1.lookup("/queue/targetQueue");
        }
    };
    targetQueue = (Queue) targetQueueFactory.createDestination();
    sourceTopicFactory = new DestinationFactory() {

        @Override
        public Destination createDestination() throws Exception {
            return (Destination) context0.lookup("/topic/sourceTopic");
        }
    };
    sourceTopic = (Topic) sourceTopicFactory.createDestination();
    localTargetQueueFactory = new DestinationFactory() {

        @Override
        public Destination createDestination() throws Exception {
            return (Destination) context0.lookup("/queue/localTargetQueue");
        }
    };
    localTargetQueue = (Queue) localTargetQueueFactory.createDestination();
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory) DestinationFactory(org.apache.activemq.artemis.jms.bridge.DestinationFactory) Destination(javax.jms.Destination) ActiveMQXAConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQXAConnectionFactory) ActiveMQJMSConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQJMSConnectionFactory) ActiveMQConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory) XAConnectionFactory(javax.jms.XAConnectionFactory) ConnectionFactory(javax.jms.ConnectionFactory) ActiveMQJMSConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQJMSConnectionFactory) ConnectionFactoryFactory(org.apache.activemq.artemis.jms.bridge.ConnectionFactoryFactory) ActiveMQXAConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQXAConnectionFactory) XAConnectionFactory(javax.jms.XAConnectionFactory) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) ActiveMQXAConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQXAConnectionFactory)

Example 3 with ActiveMQXAConnectionFactory

use of org.apache.activemq.artemis.jms.client.ActiveMQXAConnectionFactory in project activemq-artemis by apache.

the class JMSBridgeTest method testCrashDestStopBridge.

@Test
public void testCrashDestStopBridge() throws Exception {
    cff1xa = new ConnectionFactoryFactory() {

        @Override
        public Object createConnectionFactory() throws Exception {
            ActiveMQXAConnectionFactory cf = (ActiveMQXAConnectionFactory) ActiveMQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.XA_CF, new TransportConfiguration(INVM_CONNECTOR_FACTORY, params1));
            cf.setReconnectAttempts(-1);
            cf.setCallFailoverTimeout(-1);
            cf.setCallTimeout(10000);
            cf.setBlockOnNonDurableSend(true);
            cf.setBlockOnDurableSend(true);
            cf.setCacheLargeMessagesClient(true);
            return cf;
        }
    };
    JMSBridgeImpl bridge = new JMSBridgeImpl(cff0xa, cff1xa, sourceQueueFactory, targetQueueFactory, null, null, null, null, null, 1000, -1, QualityOfServiceMode.ONCE_AND_ONLY_ONCE, 10, 5000, null, null, false).setBridgeName("test-bridge");
    addActiveMQComponent(bridge);
    bridge.setTransactionManager(newTransactionManager());
    bridge.start();
    // Now crash the dest server
    JMSBridgeTest.log.info("About to crash server");
    jmsServer1.stop();
    // Now stop the bridge while the failover is happening
    JMSBridgeTest.log.info("About to stop the bridge");
    bridge.stop();
    // Shutdown the source server
    jmsServer0.stop();
}
Also used : JMSBridgeImpl(org.apache.activemq.artemis.jms.bridge.impl.JMSBridgeImpl) ConnectionFactoryFactory(org.apache.activemq.artemis.jms.bridge.ConnectionFactoryFactory) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) ActiveMQXAConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQXAConnectionFactory) Test(org.junit.Test)

Aggregations

TransportConfiguration (org.apache.activemq.artemis.api.core.TransportConfiguration)3 ConnectionFactoryFactory (org.apache.activemq.artemis.jms.bridge.ConnectionFactoryFactory)3 ActiveMQXAConnectionFactory (org.apache.activemq.artemis.jms.client.ActiveMQXAConnectionFactory)3 JMSBridgeImpl (org.apache.activemq.artemis.jms.bridge.impl.JMSBridgeImpl)2 ConnectionFactory (javax.jms.ConnectionFactory)1 Destination (javax.jms.Destination)1 XAConnectionFactory (javax.jms.XAConnectionFactory)1 HeuristicMixedException (javax.transaction.HeuristicMixedException)1 HeuristicRollbackException (javax.transaction.HeuristicRollbackException)1 RollbackException (javax.transaction.RollbackException)1 SystemException (javax.transaction.SystemException)1 DestinationFactory (org.apache.activemq.artemis.jms.bridge.DestinationFactory)1 ActiveMQConnectionFactory (org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory)1 ActiveMQJMSConnectionFactory (org.apache.activemq.artemis.jms.client.ActiveMQJMSConnectionFactory)1 DummyTransactionManager (org.apache.activemq.artemis.tests.integration.ra.DummyTransactionManager)1 Test (org.junit.Test)1