Tim,

Thx, good to know that the failover works! Obviously I've been doing something wrong. Well, as you requested here is my JMS/AMQP client source (I have removed the SSL initialization part used for amqps conncetion ):


Connection URI:
connectionfactory.nm = failover:(amqps://somedomain.com:5671)?failover.reconnectDelay=2000&failover.warnAfterReconnectAttempts=1


Source code:

public class TestClient implements Runnable {

private static final Logger logger = Logger.getLogger(TestClient.class.getName());
    private static Connection connection;

    public static void main(String[] args) {

org.apache.log4j.PropertyConfigurator.configure("./log4j.properties");

        initSSL();

        new Thread(new TestClient()).start();

        Runtime.getRuntime().addShutdownHook(new Thread(() -> {

            logger.info("Shutting down...");

            try {
                if (connection != null) {
                    connection.close();
                }
            } catch (JMSException e) {
                logger.warning(e.getMessage());
            }
        }));
    }

    @Override
    public void run() {

        try {
            Properties properties = new Properties();

            if (System.getProperty("nmclient.configuration") == null) {
File jarPath = new File(TestClient.class.getProtectionDomain().getCodeSource().getLocation().getPath());
                String propertiesPath = jarPath.getParent();
properties.load(new FileInputStream(propertiesPath + "/config.properties"));
            } else {
properties.load(new FileInputStream(System.getProperty("nmclient.configuration")));
            }

            Context context = new InitialContext(properties);
ConnectionFactory connectionFactory = (ConnectionFactory) context.lookup("nm");

            connection = connectionFactory.createConnection();

            connection.setExceptionListener((final JMSException e) -> {
                logger.log(Level.SEVERE, null, e);
            });

Session consumerSession = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
            Queue queueEaup = (Queue) context.lookup("eaup");
MessageConsumer messageConsumer = consumerSession.createConsumer(queueEaup);

            messageConsumer.setMessageListener((final Message message) -> {
                try {
                    if (message instanceof TextMessage) {

                        TextMessage payload = (TextMessage) message;
logger.info(payload.getText());
                    }
                    message.acknowledge();
                } catch (Exception e) {
                    logger.log(Level.SEVERE, null, e);
                }
            });

            connection.start();

        } catch (IOException | NamingException | JMSException e) {
            logger.log(Level.SEVERE, null, e);
        }
    }

    private static void initSSL() {
          // ....
    }
}

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@qpid.apache.org
For additional commands, e-mail: users-h...@qpid.apache.org

Reply via email to