简体   繁体   English

ActiveMQ代理不可用时重试建立JMS连接

[英]Retry to establish a JMS connection while ActiveMQ broker is not available

Here is my scenario. 这是我的情况。 I have few ActiveMQ (JBoss-AMQ) producers and consumers installed as services. 我很少将ActiveMQ(JBoss-AMQ)生产者和消费者安装为服务。 In a server restart, what is the best practice of handling such a situation where a producer or a consumer service starts before the ActiveMQ broker service. 在服务器重新启动中,处理生产者或使用者服务在ActiveMQ代理服务之前启动的情况的最佳实践是什么。 In that case producer/client cannot establish a connection and starts to hang on as it is even after the broker service starts. 在那种情况下,即使在代理服务启动之后,生产者/客户端也无法建立连接并开始按原样挂起。

here's my code snippet of connection creation: 这是我创建连接的代码片段:

try {
            connection = connectionFactory.createConnection();
            connection.start();
            LOGGER.info(STARTED_CONNECTION_WITH_THE_DESTINATION + destinationName);
            session = createSession();
            destination = session.createQueue(destinationName);
            LOGGER.info(CREATED_QUEUE_IN_DESTINATION + destinationName);
            if (isImageProcAgent) {
                consumer = createConsumer();
                LOGGER.info(CONSUMER_HAS_BEEN_INITIALIZED);
            } else {
                producer = session.createProducer(destination);
                LOGGER.info(PRODUCER_HAS_BEEN_INITIALIZE);
            }
        } catch (MessagingException e) {
            LOGGER.error(e);
        } catch (JMSException e) {
            LOGGER.error(e);
        }

I'm new to JMS so appreciate your support. 我是JMS的新手,感谢您的支持。

This can be achieved by configuring a failover as this document explains. 本文档所述,可以通过配置failover来实现。 according to my code snippet, the change I required it: 根据我的代码段,我需要做的更改:

destination = session.createQueue("failover:"+destinationName);
producer = session.createProducer("failover:"+destination);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM