activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Timothy Bish <tabish...@gmail.com>
Subject Re: failover protocol not reconnecting to single boker
Date Wed, 08 Jun 2016 15:28:49 GMT
On 06/08/2016 10:45 AM, pompanoSlayer wrote:
> >From what I read, I would only need to add failover:(tcp://localhost:61616)
> as the connection url for the broker and activeMQ does all the reconnecting
> for me. However I can't seem to get this right. The program waits for the
> broker to go online and is able to read messages out of the queue when
> there's one. When I stop the broker, the program just exits.
>
> Here's my test program.
>
>      QueueConnectionFactory queueConnectionFactory;
>      QueueConnection queueConnection;
>      QueueSession queueSession;
>      QueueReceiver queueReceiver;
>      Queue queue;
>
>          ActiveMQConnectionFactory connectionFactory = new
> ActiveMQConnectionFactory("failover:(tcp://localhost:61616)");
>
>          // Create a Connection
>          queueConnection = connectionFactory.createQueueConnection();
>          queueSession = queueConnection.createQueueSession(false,
> Session.AUTO_ACKNOWLEDGE);
>          queue = queueSession.createQueue("testUpdate");
>          queueReceiver = queueSession.createReceiver(queue);
>
>          queueReceiver.setMessageListener(
>              message ->{
>                  try {
>                      if(message != null) {
>                          String msgText = null;
>                          if (message instanceof TextMessage) {
>                              msgText = ((TextMessage) message).getText();
>                          } else {
>                              msgText = message.toString();
>                              System.out.println("message is of type " +
> message.getClass());
>                          }
>                          System.out.println("Message Received: " + msgText);
>                      }
>                  } catch (JMSException jmse) {
>                          System.err.println("An exception occurred: " +
> jmse.getMessage());
>                  }
>              }
>          );
>          queueConnection.start();
>
>
> I am not sure what I am missing or the failover protocol is not what I am
> expecting it to do.
>
>
>
> --
> View this message in context: http://activemq.2283324.n4.nabble.com/failover-protocol-not-reconnecting-to-single-boker-tp4712783.html
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>
What is keeping your program alive?  Are you simply relying on the fact 
that there is at least one non-daemon thread running (bad idea) or do 
you have some control logic to ensure it stays alive?

-- 
Tim Bish
twitter: @tabish121
blog: http://timbish.blogspot.com/


Mime
View raw message