activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pompanoSlayer <moi...@gmail.com>
Subject failover protocol not reconnecting to single boker
Date Wed, 08 Jun 2016 14:45:59 GMT
>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.

Mime
View raw message