我的Spring启动应用程序抛出连接超时错误,它永远无法连接。我看到的另一个有趣的问题是,它永远不会获取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配置,
@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
Rabbit已启动并在端口15672上运行127.0.0.1,但应用程序永远无法连接。
答案 0 :(得分:6)
默认情况下,AMQP端口为5672.端口15672显示Web UI(管理控制台)。如果您使用的是默认设置,请调整
spring.rabbitmq.port = 5672