Java Code Examples for org.apache.activemq.artemis.jms.client.ActiveMQJMSConnectionFactory#setReconnectAttempts()

The following examples show how to use org.apache.activemq.artemis.jms.client.ActiveMQJMSConnectionFactory#setReconnectAttempts() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JMSBridgeImplTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
private static ConnectionFactory createConnectionFactory() {

      ActiveMQJMSConnectionFactory cf = (ActiveMQJMSConnectionFactory) ActiveMQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF, new TransportConfiguration(InVMConnectorFactory.class.getName()));
      // 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);
      return cf;
   }
 
Example 2
Source File: JMSBridgeImplTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@Test
public void testStartWithFailureThenSuccess() throws Exception {
   ActiveMQJMSConnectionFactory failingSourceCF = new ActiveMQJMSConnectionFactory(false, new TransportConfiguration(InVMConnectorFactory.class.getName())) {
      private static final long serialVersionUID = 4657153922210359725L;
      boolean firstTime = true;

      @Override
      public Connection createConnection() throws JMSException {
         if (firstTime) {
            firstTime = false;
            throw new JMSException("unable to create a conn");
         } else {
            return super.createConnection();
         }
      }
   };
   // Note! We disable automatic reconnection on the session factory. The bridge needs to do the reconnection
   failingSourceCF.setReconnectAttempts(0);
   failingSourceCF.setBlockOnNonDurableSend(true);
   failingSourceCF.setBlockOnDurableSend(true);

   ConnectionFactoryFactory sourceCFF = JMSBridgeImplTest.newConnectionFactoryFactory(failingSourceCF);
   ConnectionFactoryFactory targetCFF = JMSBridgeImplTest.newConnectionFactoryFactory(JMSBridgeImplTest.createConnectionFactory());
   DestinationFactory sourceDF = JMSBridgeImplTest.newDestinationFactory(ActiveMQJMSClient.createQueue(JMSBridgeImplTest.SOURCE));
   DestinationFactory targetDF = JMSBridgeImplTest.newDestinationFactory(ActiveMQJMSClient.createQueue(JMSBridgeImplTest.TARGET));
   TransactionManager tm = JMSBridgeImplTest.newTransactionManager();

   JMSBridgeImpl bridge = new JMSBridgeImpl();

   bridge.setSourceConnectionFactoryFactory(sourceCFF);
   bridge.setSourceDestinationFactory(sourceDF);
   bridge.setTargetConnectionFactoryFactory(targetCFF);
   bridge.setTargetDestinationFactory(targetDF);
   // retry after 10 ms
   bridge.setFailureRetryInterval(10);
   // retry only once
   bridge.setMaxRetries(1);
   bridge.setMaxBatchSize(1);
   bridge.setMaxBatchTime(-1);
   bridge.setTransactionManager(tm);
   bridge.setQualityOfServiceMode(QualityOfServiceMode.AT_MOST_ONCE);

   Assert.assertFalse(bridge.isStarted());
   bridge.start();

   Thread.sleep(500);
   Assert.assertTrue(bridge.isStarted());
   Assert.assertFalse(bridge.isFailed());

   bridge.stop();
}
 
Example 3
Source File: JMSBridgeImplTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@Test
public void testExceptionOnSourceAndRetrySucceeds() throws Exception {
   final AtomicReference<Connection> sourceConn = new AtomicReference<>();
   ActiveMQJMSConnectionFactory failingSourceCF = new ActiveMQJMSConnectionFactory(false, new TransportConfiguration(InVMConnectorFactory.class.getName())) {
      private static final long serialVersionUID = -8866390811966688830L;

      @Override
      public Connection createConnection() throws JMSException {
         sourceConn.set(super.createConnection());
         return sourceConn.get();
      }
   };
   // Note! We disable automatic reconnection on the session factory. The bridge needs to do the reconnection
   failingSourceCF.setReconnectAttempts(0);
   failingSourceCF.setBlockOnNonDurableSend(true);
   failingSourceCF.setBlockOnDurableSend(true);

   ConnectionFactoryFactory sourceCFF = JMSBridgeImplTest.newConnectionFactoryFactory(failingSourceCF);
   ConnectionFactoryFactory targetCFF = JMSBridgeImplTest.newConnectionFactoryFactory(JMSBridgeImplTest.createConnectionFactory());
   DestinationFactory sourceDF = JMSBridgeImplTest.newDestinationFactory(ActiveMQJMSClient.createQueue(JMSBridgeImplTest.SOURCE));
   DestinationFactory targetDF = JMSBridgeImplTest.newDestinationFactory(ActiveMQJMSClient.createQueue(JMSBridgeImplTest.TARGET));
   TransactionManager tm = JMSBridgeImplTest.newTransactionManager();

   JMSBridgeImpl bridge = new JMSBridgeImpl();
   Assert.assertNotNull(bridge);

   bridge.setSourceConnectionFactoryFactory(sourceCFF);
   bridge.setSourceDestinationFactory(sourceDF);
   bridge.setTargetConnectionFactoryFactory(targetCFF);
   bridge.setTargetDestinationFactory(targetDF);
   bridge.setFailureRetryInterval(10);
   bridge.setMaxRetries(2);
   bridge.setMaxBatchSize(1);
   bridge.setMaxBatchTime(-1);
   bridge.setTransactionManager(tm);
   bridge.setQualityOfServiceMode(QualityOfServiceMode.AT_MOST_ONCE);

   Assert.assertFalse(bridge.isStarted());
   bridge.start();
   Assert.assertTrue(bridge.isStarted());

   sourceConn.get().getExceptionListener().onException(new JMSException("exception on the source"));
   Thread.sleep(4 * bridge.getFailureRetryInterval());
   // reconnection must have succeeded
   Assert.assertTrue(bridge.isStarted());

   bridge.stop();
   Assert.assertFalse(bridge.isStarted());
}
 
Example 4
Source File: JMSBridgeImplTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@Test
public void testExceptionOnSourceAndRetryFails() throws Exception {
   final AtomicReference<Connection> sourceConn = new AtomicReference<>();
   ActiveMQJMSConnectionFactory failingSourceCF = new ActiveMQJMSConnectionFactory(false, new TransportConfiguration(INVM_CONNECTOR_FACTORY)) {
      private static final long serialVersionUID = 8216804886099984645L;
      boolean firstTime = true;

      @Override
      public Connection createConnection() throws JMSException {
         if (firstTime) {
            firstTime = false;
            sourceConn.set(super.createConnection());
            return sourceConn.get();
         } else {
            throw new JMSException("exception while retrying to connect");
         }
      }
   };
   // Note! We disable automatic reconnection on the session factory. The bridge needs to do the reconnection
   failingSourceCF.setReconnectAttempts(0);
   failingSourceCF.setBlockOnNonDurableSend(true);
   failingSourceCF.setBlockOnDurableSend(true);

   ConnectionFactoryFactory sourceCFF = JMSBridgeImplTest.newConnectionFactoryFactory(failingSourceCF);
   ConnectionFactoryFactory targetCFF = JMSBridgeImplTest.newConnectionFactoryFactory(JMSBridgeImplTest.createConnectionFactory());
   DestinationFactory sourceDF = JMSBridgeImplTest.newDestinationFactory(ActiveMQJMSClient.createQueue(JMSBridgeImplTest.SOURCE));
   DestinationFactory targetDF = JMSBridgeImplTest.newDestinationFactory(ActiveMQJMSClient.createQueue(JMSBridgeImplTest.TARGET));
   TransactionManager tm = JMSBridgeImplTest.newTransactionManager();

   JMSBridgeImpl bridge = new JMSBridgeImpl();
   Assert.assertNotNull(bridge);

   bridge.setSourceConnectionFactoryFactory(sourceCFF);
   bridge.setSourceDestinationFactory(sourceDF);
   bridge.setTargetConnectionFactoryFactory(targetCFF);
   bridge.setTargetDestinationFactory(targetDF);
   bridge.setFailureRetryInterval(100);
   bridge.setMaxRetries(1);
   bridge.setMaxBatchSize(1);
   bridge.setMaxBatchTime(-1);
   bridge.setTransactionManager(tm);
   bridge.setQualityOfServiceMode(QualityOfServiceMode.AT_MOST_ONCE);

   Assert.assertFalse(bridge.isStarted());
   bridge.start();
   Assert.assertTrue(bridge.isStarted());

   sourceConn.get().getExceptionListener().onException(new JMSException("exception on the source"));
   Thread.sleep(4 * bridge.getFailureRetryInterval());
   // reconnection must have failed
   Assert.assertFalse(bridge.isStarted());

}
 
Example 5
Source File: JMSBridgeImplTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@Test
public void testStartWithSpecificTCCL() throws Exception {
   MockContextClassLoader mockTccl = setMockTCCL();
   try {
      final AtomicReference<Connection> sourceConn = new AtomicReference<>();
      ActiveMQJMSConnectionFactory failingSourceCF = new ActiveMQJMSConnectionFactory(false, new TransportConfiguration(InVMConnectorFactory.class.getName())) {
         private static final long serialVersionUID = -8866390811966688830L;

         @Override
         public Connection createConnection() throws JMSException {
            sourceConn.set(super.createConnection());
            return sourceConn.get();
         }
      };
      // Note! We disable automatic reconnection on the session factory. The bridge needs to do the reconnection
      failingSourceCF.setReconnectAttempts(0);
      failingSourceCF.setBlockOnNonDurableSend(true);
      failingSourceCF.setBlockOnDurableSend(true);

      ConnectionFactoryFactory sourceCFF = JMSBridgeImplTest.newTCCLAwareConnectionFactoryFactory(failingSourceCF);
      ConnectionFactoryFactory targetCFF = JMSBridgeImplTest.newConnectionFactoryFactory(JMSBridgeImplTest.createConnectionFactory());
      DestinationFactory sourceDF = JMSBridgeImplTest.newDestinationFactory(ActiveMQJMSClient.createQueue(JMSBridgeImplTest.SOURCE));
      DestinationFactory targetDF = JMSBridgeImplTest.newDestinationFactory(ActiveMQJMSClient.createQueue(JMSBridgeImplTest.TARGET));
      TransactionManager tm = JMSBridgeImplTest.newTransactionManager();

      JMSBridgeImpl bridge = new JMSBridgeImpl();
      Assert.assertNotNull(bridge);

      bridge.setSourceConnectionFactoryFactory(sourceCFF);
      bridge.setSourceDestinationFactory(sourceDF);
      bridge.setTargetConnectionFactoryFactory(targetCFF);
      bridge.setTargetDestinationFactory(targetDF);
      bridge.setFailureRetryInterval(10);
      bridge.setMaxRetries(2);
      bridge.setMaxBatchSize(1);
      bridge.setMaxBatchTime(-1);
      bridge.setTransactionManager(tm);
      bridge.setQualityOfServiceMode(QualityOfServiceMode.AT_MOST_ONCE);

      Assert.assertFalse(bridge.isStarted());
      bridge.start();
      Assert.assertTrue(bridge.isStarted());

      unsetMockTCCL(mockTccl);
      tcclClassFound.set(false);

      sourceConn.get().getExceptionListener().onException(new JMSException("exception on the source"));
      Thread.sleep(4 * bridge.getFailureRetryInterval());
      // reconnection must have succeeded
      Assert.assertTrue(bridge.isStarted());

      bridge.stop();
      Assert.assertFalse(bridge.isStarted());
      assertTrue(tcclClassFound.get());
   } finally {
      if (mockTccl != null)
         unsetMockTCCL(mockTccl);
   }
}