SpringBoot兔子连接超时问题

SpringBoot兔子连接超时问题

问题描述:

我的spring引导应用程序抛出连接超时错误,并且它永远不能连接。我看到的另一个有趣的问题是,它从来没有拿起Spring应用程序属性中定义的连接超时属性。SpringBoot兔子连接超时问题

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配置,

@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应用程序性能的样子,

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 

兔子并在端口15672 127.0.0.1上运行,但应用程序永远不能连接。

+2

你** **肯定RabbitMQ的有** ** AMQP端口15672开放?默认情况下,15672显示Web UI(管理控制台)和AMQP端口5672.您可能只需将'spring.rabbitmq.port'更改为'5672'。 –

+0

哦,我正在杀死自己。 – Imran

默认情况下,AMQP端口为5672.端口15672显示Web UI(管理控制台)。如果您使用的是默认设置,调整

spring.rabbitmq.port = 5672 

RabbitMQ networking configuration reference