Java Code Examples for org.apache.activemq.ActiveMQConnectionFactory#setTransportListener()

The following examples show how to use org.apache.activemq.ActiveMQConnectionFactory#setTransportListener() . 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: ConsumerConnctionFactory.java    From jim-framework with Apache License 2.0 5 votes vote down vote up
public PooledConnectionFactory create(String brokerClusterUrl){
    ActiveMQConnectionFactory mqConnectionFactory = new ActiveMQConnectionFactory();
    mqConnectionFactory.setBrokerURL(brokerClusterUrl);
    mqConnectionFactory.setTransportListener(this);
    //mqConnectionFactory.

    PooledConnectionFactory connectionFactory = new JimPooledConnectionFactory(mqConnectionFactory);
    connectionFactory.setMaxConnections(1);
    connectionFactory.setCreateConnectionOnStartup(true);

    return connectionFactory;
}
 
Example 2
Source File: ProducerConnctionFactory.java    From jim-framework with Apache License 2.0 5 votes vote down vote up
public PooledConnectionFactory create(String brokerClusterUrl){
    ActiveMQConnectionFactory mqConnectionFactory = new ActiveMQConnectionFactory();
    mqConnectionFactory.setBrokerURL(brokerClusterUrl);
    mqConnectionFactory.setTransportListener(this);
    //mqConnectionFactory.

    PooledConnectionFactory connectionFactory = new JimPooledConnectionFactory(mqConnectionFactory);
    connectionFactory.setMaxConnections(10);
    connectionFactory.setTimeBetweenExpirationCheckMillis(1000);
    //connectionFactory.setCreateConnectionOnStartup(true);

    return connectionFactory;
}
 
Example 3
Source File: InitalReconnectDelayTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
@Test
public void testNoSuspendedCallbackOnNoReconnect() throws Exception {

   String uriString = "failover://(" + newURI(1) +
      "," + newURI(2) +
      ")?randomize=false&maxReconnectAttempts=0";

   ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(uriString);
   final AtomicInteger calls = new AtomicInteger(0);
   connectionFactory.setTransportListener(new TransportListener() {
      @Override
      public void onCommand(Object command) {
      }

      @Override
      public void onException(IOException error) {
         LOG.info("on exception: " + error);
         calls.set(0x01 | calls.intValue());
      }

      @Override
      public void transportInterupted() {
         LOG.info("on transportInterupted");
         calls.set(0x02 | calls.intValue());
      }

      @Override
      public void transportResumed() {
         LOG.info("on transportResumed");
         calls.set(0x04 | calls.intValue());
      }
   });
   Connection connection = connectionFactory.createConnection();
   Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
   Queue destination = session.createQueue("foo");
   MessageProducer producer = session.createProducer(destination);

   final Message message = session.createTextMessage("TEST");
   producer.send(message);

   // clear listener state
   calls.set(0);

   LOG.info("Stopping the Broker1...");
   server1.stop();

   LOG.info("Attempting to send... failover should throw on disconnect");
   try {
      producer.send(destination, message);
      fail("Expect IOException to bubble up on send");
   } catch (javax.jms.IllegalStateException producerClosed) {
   }

   assertEquals("Only an exception is reported to the listener", 0x1, calls.get());
}