我创建了一个连接到Azure队列并使用该消息的应用程序。问题是在240000毫秒连接自动关闭后,我收到异常"org.apache.qpid.amqp_1_0.jms.MessageConsumerException: The connection was inactive for more than the allowed 240000 milliseconds and is closed by container
。
PFB我的配置代码,用于连接Azure队列。
@Bean
public ConnectionFactory jmsConnectionFactory() {
CachingConnectionFactory cachingConnectionFactory = null;
try {
cachingConnectionFactory = new CachingConnectionFactory(ConnectionFactoryImpl.createFromURL(url));
cachingConnectionFactory.setReconnectOnException(true);
cachingConnectionFactory.setClientId(applicationName);
} catch (MalformedURLException e) {
logger.error("Exception", e);
}
return cachingConnectionFactory;
}
@Bean
public MessageListenerContainer getContainer() {
DefaultMessageListenerContainer container = new DefaultMessageListenerContainer();
container.setConnectionFactory(jmsConnectionFactory());
container.setDestinationName(queueName);
container.setMessageListener(messageConsumer);
container.setConcurrency(concurrency);
return container;
}
和我的pom.xml文件
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.4.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-cassandra</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jms</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.5</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-jms_1.1_spec</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>org.apache.qpid</groupId>
<artifactId>qpid-amqp-1-0-client</artifactId>
<version>0.30</version>
</dependency>
<dependency>
<groupId>org.apache.qpid</groupId>
<artifactId>qpid-amqp-1-0-client-jms</artifactId>
<version>0.30</version>
</dependency>
<dependency>
<groupId>org.apache.qpid</groupId>
<artifactId>qpid-amqp-1-0-common</artifactId>
<version>0.30</version>
</dependency>
</dependencies>
我的网址是:
amqps://user:<password>@myqueue2.servicebus.windows.net
我的问题是如何保持连接活动或如何在异常后重新连接到队列。请帮助谢谢。
答案 0 :(得分:0)
根据有关Failover Configuration options的Qpid官方文档,请尝试使用URI进行故障转移,以启用Qpid的故障转移功能,以便在连接丢失时自动重新连接。