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
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);
}
}
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 is up and running on 127.0.0.1 on port 15672, but the app is never able to connect.
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
RabbitMQ networking configuration reference
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With