SpringBoot 兔子连接超时问题 [英] SpringBoot rabbit connection timeout issue
问题描述
我的 Spring Boot 应用程序抛出连接超时错误,并且永远无法连接.我看到的另一个有趣的问题是,它永远不会选择 spring 应用程序属性中定义的连接超时属性.
My spring boot application throws connection timeout error, and it is never able to connect. The other interesting problem I see is, it is never picking up the connection timeout property defined in spring app properties.
org.springframework.amqp.AmqpTimeoutException: java.util.concurrent.TimeoutException
at org.springframework.amqp.rabbit.support.RabbitExceptionTranslator.convertRabbitAccessException(RabbitExceptionTranslator.java:74) ~[spring-rabbit-1.6.7.RELEASE.jar:na]
at org.springframework.amqp.rabbit.connection.AbstractConnectionFactory.createBareConnection(AbstractConnectionFactory.java:309) ~[spring-rabbit-1.6.7.RELEASE.jar:na]
at org.springframework.amqp.rabbit.connection.CachingConnectionFactory.createConnection(CachingConnectionFactory.java:577) ~[spring-rabbit-1.6.7.RELEASE.jar:na]
at org.springframework.amqp.rabbit.core.RabbitTemplate.doExecute(RabbitTemplate.java:1431) ~[spring-rabbit-1.6.7.RELEASE.jar:na]
at org.springframework.amqp.rabbit.core.RabbitTemplate.execute(RabbitTemplate.java:1412) ~[spring-rabbit-1.6.7.RELEASE.jar:na]
at org.springframework.amqp.rabbit.core.RabbitTemplate.execute(RabbitTemplate.java:1388) ~[spring-rabbit-1.6.7.RELEASE.jar:na]
at org.springframework.amqp.rabbit.core.RabbitAdmin.getQueueProperties(RabbitAdmin.java:336) ~[spring-rabbit-1.6.7.RELEASE.jar:na]
at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.redeclareElementsIfNecessary(SimpleMessageListenerContainer.java:1123) [spring-rabbit-1.6.7.RELEASE.jar:na]
at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.access$800(SimpleMessageListenerContainer.java:98) [spring-rabbit-1.6.7.RELEASE.jar:na]
at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$AsyncMessageProcessingConsumer.run(SimpleMessageListenerContainer.java:1329) [spring-rabbit-1.6.7.RELEASE.jar:na]
at java.lang.Thread.run(Thread.java:745) [na:1.8.0_91]
Caused by: java.util.concurrent.TimeoutException: null
at com.rabbitmq.utility.BlockingCell.get(BlockingCell.java:76) ~[amqp-client-3.6.5.jar:na]
at com.rabbitmq.utility.BlockingCell.uninterruptibleGet(BlockingCell.java:110) ~[amqp-client-3.6.5.jar:na]
at com.rabbitmq.utility.BlockingValueOrException.uninterruptibleGetValue(BlockingValueOrException.java:36) ~[amqp-client-3.6.5.jar:na]
at com.rabbitmq.client.impl.AMQChannel$BlockingRpcContinuation.getReply(AMQChannel.java:366) ~[amqp-client-3.6.5.jar:na]
at com.rabbitmq.client.impl.AMQConnection.start(AMQConnection.java:292) ~[amqp-client-3.6.5.jar:na]
at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:824) ~[amqp-client-3.6.5.jar:na]
at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:736) ~[amqp-client-3.6.5.jar:na]
at org.springframework.amqp.rabbit.connection.AbstractConnectionFactory.createBareConnection(AbstractConnectionFactory.java:293) ~[spring-rabbit-1.6.7.RELEASE.jar:na]
... 9 common frames omitted
这是我的java配置,
Here is my java config,
@Configuration
@EnableRabbit
public class RabbitConfig {
private final String exchange;
private final String queueName;
public RabbitConfig(
@Value("${exchange.name}") String exchange,
@Value("${queue.name}") String queue) {
this.exchange= exchange;
this.queueName=queue;
}
@Bean
Queue queue() {
return new Queue(queueName, true);
}
@Bean
DirectExchange exchange() {
return new DirectExchange(queueName);
}
@Bean
Binding binding(Queue queue, DirectExchange exchange) {
return BindingBuilder.bind(queue).to(exchange).with(queueName);
}
@Bean
SimpleMessageListenerContainer container(RabbitAdmin admin,CachingConnectionFactory connectionFactory) {
SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
connectionFactory.setCloseTimeout(10000);
container.setQueueNames(queueName);
container.setConnectionFactory(connectionFactory);
//container.setMessageListener(listenerAdapter);
return container;
}
// @Bean
// MessageListenerAdapter listenerAdapter(Receiver receiver) {
// return new MessageListenerAdapter(receiver, "receiveMessage");
// }
@Bean
public RabbitAdmin admin(ConnectionFactory connectionFactory) {
return new RabbitAdmin(connectionFactory);
}
}
我的 spring 应用程序属性看起来像,
And my spring application properties look like,
spring.rabbitmq.host = 127.0.0.1
spring.rabbitmq.port = 15672
spring.rabbitmq.username = guest
spring.rabbitmq.password = guest
exchange.name=myExchange
queue.name=myQueue
spring.rabbitmq.cache.connection.mode=CONNECTION
spring.rabbitmq.cache.channel.size=50
spring.rabbitmq.cache.channel.checkout-timeout= 10000
Rabbit 已在 127.0.0.1 端口 15672 上启动并运行,但该应用程序永远无法连接.
Rabbit is up and running on 127.0.0.1 on port 15672, but the app is never able to connect.
推荐答案
默认情况下,AMQP 端口为 5672.端口 15672 显示 Web UI(管理控制台).如果您使用的是默认设置,请调整
By default, the AMQP port is 5672. Port 15672 shows the web UI (admin console). If you're using the default setup, adjust
spring.rabbitmq.port = 5672
这篇关于SpringBoot 兔子连接超时问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!