org.apache.activemq.artemis.jms.client.ActiveMQJMSConnectionFactory Java Examples

The following examples show how to use org.apache.activemq.artemis.jms.client.ActiveMQJMSConnectionFactory. 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: ArtemisJMSClientFeatureIT.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Test
public void testArtemisJMSClient() throws Exception {
   // setup connection
   ConnectionFactory cf = new ActiveMQJMSConnectionFactory("tcp://localhost:61616");
   try (Connection connection = cf.createConnection()) {
      Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
      connection.start();
      Queue queue = ActiveMQJMSClient.createQueue("artemisJMSClientFeatureITQueue");
      MessageProducer producer = session.createProducer(queue);
      // send message
      String textMessage = "This is a text message";
      TextMessage message = session.createTextMessage(textMessage);
      producer.send(message);

      // receive message and assert
      MessageConsumer messageConsumer = session.createConsumer(queue);
      TextMessage messageReceived = (TextMessage) messageConsumer.receive(100);
      assertEquals(textMessage, messageReceived.getText());
   }
}
 
Example #2
Source File: JMSClientTestSupport.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
private Connection createCoreConnection(String connectionString, String username, String password, String clientId, boolean start) throws JMSException {
   ActiveMQJMSConnectionFactory factory = new ActiveMQJMSConnectionFactory(connectionString);

   Connection connection = trackJMSConnection(factory.createConnection(username, password));

   connection.setExceptionListener(new ExceptionListener() {
      @Override
      public void onException(JMSException exception) {
         exception.printStackTrace();
      }
   });

   if (clientId != null && !clientId.isEmpty()) {
      connection.setClientID(clientId);
   }

   if (start) {
      connection.start();
   }

   return connection;
}
 
Example #3
Source File: RestDeserializationTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
private void jmsSendMessage(Serializable value, String destName, boolean isQueue) throws JMSException {
   ConnectionFactory factory = new ActiveMQJMSConnectionFactory("tcp://localhost:61616");
   String jmsDest;
   if (isQueue) {
      jmsDest = QUEUE_QUALIFIED_PREFIX + destName;
   } else {
      jmsDest = TOPIC_QUALIFIED_PREFIX + destName;
   }
   Destination destination = ActiveMQDestination.fromPrefixedName(jmsDest);

   Connection conn = factory.createConnection();
   try {
      Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
      MessageProducer producer = session.createProducer(destination);
      ObjectMessage message = session.createObjectMessage();
      message.setStringProperty(HttpHeaderProperty.CONTENT_TYPE, "application/xml");
      message.setObject(value);
      producer.send(message);
   } finally {
      conn.close();
   }
}
 
Example #4
Source File: JmsReceive.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
   System.out.println("Receive Setup...");
   ConnectionFactory factory = new ActiveMQJMSConnectionFactory("tcp://localhost:61616");
   Destination destination = ActiveMQDestination.fromPrefixedName("queue://orders");

   try (Connection conn = factory.createConnection()) {
      Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
      MessageConsumer consumer = session.createConsumer(destination);
      consumer.setMessageListener(new MessageListener() {
         @Override
         public void onMessage(Message message) {
            System.out.println("Received Message: ");
            Order order = Jms.getEntity(message, Order.class);
            System.out.println(order);
         }
      });
      conn.start();
      Thread.sleep(1000000);
   }
}
 
Example #5
Source File: ReceiveShipping.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
   ConnectionFactory factory = new ActiveMQJMSConnectionFactory("tcp://localhost:61616");
   Destination destination = ActiveMQDestination.fromPrefixedName("queue://shipping");

   try (Connection conn = factory.createConnection()) {
      Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
      MessageConsumer consumer = session.createConsumer(destination);
      consumer.setMessageListener(new MessageListener() {
         @Override
         public void onMessage(Message message) {
            System.out.println("Received Message: ");
            Order order = Jms.getEntity(message, Order.class);
            System.out.println(order);
         }
      });
      conn.start();
      Thread.sleep(1000000);
   }
}
 
Example #6
Source File: HeaderPropagationTest.java    From smallrye-reactive-messaging with Apache License 2.0 5 votes vote down vote up
@Before
public void init() {
    factory = new ActiveMQJMSConnectionFactory(
            "tcp://localhost:61616",
            null, null);
    jms = factory.createContext();
}
 
Example #7
Source File: ConnectionFactoryURITest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Test
public void testJGroupsKeyValue() throws Exception {
   ActiveMQConnectionFactory factory = parser.newObject(new URI("jgroups://channel-name?properties=param=value;param2=value2&test=33"), null);

   Assert.assertTrue(ActiveMQJMSConnectionFactory.class.getName().equals(factory.getClass().getName()));
   JGroupsPropertiesBroadcastEndpointFactory broadcastEndpointFactory = (JGroupsPropertiesBroadcastEndpointFactory) factory.getDiscoveryGroupConfiguration().getBroadcastEndpointFactory();
   Assert.assertEquals(broadcastEndpointFactory.getProperties(), "param=value;param2=value2");
   Assert.assertEquals(broadcastEndpointFactory.getChannelName(), "channel-name");
}
 
Example #8
Source File: ConnectionFactoryURITest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Test
public void testJGroupsFile() throws Exception {
   ActiveMQConnectionFactory factory = parser.newObject(new URI("jgroups://channel-name?file=/path/to/some/file/channel-file.xml&test=33"), null);

   Assert.assertTrue(ActiveMQJMSConnectionFactory.class.getName().equals(factory.getClass().getName()));
   JGroupsFileBroadcastEndpointFactory broadcastEndpointFactory = (JGroupsFileBroadcastEndpointFactory) factory.getDiscoveryGroupConfiguration().getBroadcastEndpointFactory();
   Assert.assertEquals(broadcastEndpointFactory.getFile(), "/path/to/some/file/channel-file.xml");
   Assert.assertEquals(broadcastEndpointFactory.getChannelName(), "channel-name");
}
 
Example #9
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 #10
Source File: JMSTestCase.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
@Before
public void setUp() throws Exception {
   super.setUp();

   ic = getInitialContext();

   // All jms tests should use a specific cg which has blockOnAcknowledge = true and
   // both np and p messages are sent synchronously
   cf = new ActiveMQJMSConnectionFactory("tcp://127.0.0.1:61616?blockOnAcknowledge=true&blockOnDurableSend=true&blockOnNonDurableSend=true");
   queueCf = new ActiveMQQueueConnectionFactory("tcp://127.0.0.1:61616?blockOnAcknowledge=true&blockOnDurableSend=true&blockOnNonDurableSend=true");
   topicCf = new ActiveMQTopicConnectionFactory("tcp://127.0.0.1:61616?blockOnAcknowledge=true&blockOnDurableSend=true&blockOnNonDurableSend=true");

   assertRemainingMessages(0);
}
 
Example #11
Source File: JMSUtil.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
public static ConnectionFactory createFactory(final String connectorFactory,
                                              final long connectionTTL,
                                              final long clientFailureCheckPeriod) throws JMSException {
   ActiveMQJMSConnectionFactory cf = (ActiveMQJMSConnectionFactory) ActiveMQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF, new TransportConfiguration(connectorFactory));

   cf.setBlockOnNonDurableSend(true);
   cf.setBlockOnDurableSend(true);
   cf.setBlockOnAcknowledge(true);
   cf.setConnectionTTL(connectionTTL);
   cf.setClientFailureCheckPeriod(clientFailureCheckPeriod);

   return cf;
}
 
Example #12
Source File: JMSUtil.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
public static Connection createConnection(final String connectorFactory) throws JMSException {
   ActiveMQJMSConnectionFactory cf = (ActiveMQJMSConnectionFactory) ActiveMQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF, new TransportConfiguration(connectorFactory));

   cf.setBlockOnNonDurableSend(true);
   cf.setBlockOnDurableSend(true);
   cf.setBlockOnAcknowledge(true);

   return cf.createConnection();
}
 
Example #13
Source File: AutoGroupingTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
protected ConnectionFactory getCF() throws Exception {
   ActiveMQJMSConnectionFactory cf1 = (ActiveMQJMSConnectionFactory) ActiveMQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF, new TransportConfiguration(INVM_CONNECTOR_FACTORY));

   cf1.setAutoGroup(true);

   return cf1;
}
 
Example #14
Source File: GroupIDTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
protected ConnectionFactory getCF() throws Exception {
   ActiveMQJMSConnectionFactory cf = (ActiveMQJMSConnectionFactory) ActiveMQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF, new TransportConfiguration(INVM_CONNECTOR_FACTORY));

   cf.setGroupID("wibble");

   return cf;
}
 
Example #15
Source File: JmsSend.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
   ConnectionFactory factory = new ActiveMQJMSConnectionFactory("tcp://localhost:61616");
   Destination destination = ActiveMQDestination.fromPrefixedName("queue://orders");

   try (Connection conn = factory.createConnection()) {
      Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
      MessageProducer producer = session.createProducer(destination);
      ObjectMessage message = session.createObjectMessage();

      Order order = new Order("Bill", "$199.99", "iPhone4");
      message.setObject(order);
      producer.send(message);
   }
}
 
Example #16
Source File: SelectorTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void setup() throws Exception {
   connectionFactory = new ActiveMQJMSConnectionFactory(manager.getQueueManager().getServerLocator());
   log.debug("Queue name: " + prefixedTopicName);
   TopicDeployment deployment = new TopicDeployment();
   deployment.setDuplicatesAllowed(true);
   deployment.setDurableSend(false);
   deployment.setName(topicName);
   manager.getTopicManager().deploy(deployment);
}
 
Example #17
Source File: PostOrder.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
   ConnectionFactory factory = new ActiveMQJMSConnectionFactory("tcp://localhost:61616");
   Destination destination = ActiveMQDestination.fromPrefixedName("queue://orders");

   try (Connection conn = factory.createConnection()) {
      Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
      MessageProducer producer = session.createProducer(destination);
      ObjectMessage message = session.createObjectMessage();

      Order order = new Order("Bill", "$199.99", "iPhone4");
      message.setObject(order);
      producer.send(message);
   }
}
 
Example #18
Source File: JmsSinkTest.java    From smallrye-reactive-messaging with Apache License 2.0 5 votes vote down vote up
@Before
public void init() {
    factory = new ActiveMQJMSConnectionFactory(
            "tcp://localhost:61616",
            null, null);
    jms = factory.createContext();
    json = JsonbBuilder.create();
    executor = Executors.newFixedThreadPool(3);
}
 
Example #19
Source File: NamedFactoryTest.java    From smallrye-reactive-messaging with Apache License 2.0 5 votes vote down vote up
@Produces
@Named("bar")
ConnectionFactory factory() {
    return new ActiveMQJMSConnectionFactory(
            "tcp://localhost:61618", // Wrong on purpose
            null, null);
}
 
Example #20
Source File: ArtemisJmsProducer.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@Produces
@ApplicationScoped
@DefaultBean
public ConnectionFactory connectionFactory() {
    return new ActiveMQJMSConnectionFactory(config.url,
            config.username.orElse(null), config.password.orElse(null));
}
 
Example #21
Source File: NamedFactoryTest.java    From smallrye-reactive-messaging with Apache License 2.0 5 votes vote down vote up
@Produces
@Named("foo")
ConnectionFactory factory() {
    return new ActiveMQJMSConnectionFactory(
            "tcp://localhost:61616",
            null, null);
}
 
Example #22
Source File: JmsSourceTest.java    From smallrye-reactive-messaging with Apache License 2.0 5 votes vote down vote up
@Before
public void init() {
    factory = new ActiveMQJMSConnectionFactory(
            "tcp://localhost:61616",
            null, null);
    jms = factory.createContext();
}
 
Example #23
Source File: ArtemisJmsTestRule.java    From brave with Apache License 2.0 4 votes vote down vote up
ArtemisJmsTestRule(TestName testName) {
  super(testName);
  factory = new ActiveMQJMSConnectionFactory("vm://0");
  factory.setProducerMaxRate(1); // to allow tests to use production order
}
 
Example #24
Source File: ConnectionFactoryURITest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@Test
public void testInvalidCFType() throws Exception {
   ActiveMQConnectionFactory factory = parser.newObject(new URI("udp://localhost:3030?ha=true&type=QUEUE_XA_CFInvalid"), null);

   Assert.assertTrue(ActiveMQJMSConnectionFactory.class.getName().equals(factory.getClass().getName()));
}
 
Example #25
Source File: ConnectionFactoryURITest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@Test
public void testNoCF() throws Exception {
   ActiveMQConnectionFactory factory = parser.newObject(new URI("tcp://localhost:3030?ha=true"), null);

   Assert.assertTrue(ActiveMQJMSConnectionFactory.class.getName().equals(factory.getClass().getName()));
}
 
Example #26
Source File: ConnectionFactoryURITest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@Test
public void testCF() throws Exception {
   ActiveMQConnectionFactory factory = parser.newObject(new URI("tcp://localhost:3030?ha=true&type=CF"), null);

   Assert.assertTrue(ActiveMQJMSConnectionFactory.class.getName().equals(factory.getClass().getName()));
}
 
Example #27
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);
   }
}
 
Example #28
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 #29
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 #30
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();
}