[英]RabbitMQ trying to connect to localhost
I have a Spring boot application running on embedded tomcat with rabbit listener which I configure like this我有一个 Spring 启动应用程序在嵌入式 tomcat 上运行,带有兔子侦听器,我像这样配置
@Configuration
public class RabbitConfiguration {
public static final String REQUEST_QUEUE = "from-beeline-req";
public static final String REPLY_QUEUE = "from-beeline-reply";
@Bean
public Queue beelineRpcReqQueue() {
return new Queue(REQUEST_QUEUE);
}
@Bean
public Queue beelineRpcReplyQueue() {
return new Queue(REPLY_QUEUE);
}
@Bean
public RabbitTemplate rabbitTemplate(RabbitTemplateConfigurer configurer, ConnectionFactory connectionFactory) {
RabbitTemplate template = new RabbitTemplate();
configurer.configure(template, connectionFactory);
template.setDefaultReceiveQueue(REQUEST_QUEUE);
template.setReplyAddress(REPLY_QUEUE);
template.setUseDirectReplyToContainer(false);
return template;
}
@Bean
public SimpleMessageListenerContainer replyListenerContainer(ConnectionFactory connectionFactory, RabbitTemplate rabbitTemplate) {
SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
container.setConnectionFactory(connectionFactory);
container.setQueues(beelineRpcReplyQueue());
container.setMessageListener(rabbitTemplate);
return container;
}
}
And my application.yml
file looks like this我的
application.yml
文件看起来像这样
spring:
main:
banner-mode: LOG
rabbitmq:
host: 172.29.14.45
port: 5672
username: guest
password: guest
template:
reply-timeout: 15000
server:
port: 8888
So the main point is I want to connect to Rabbit server located at exact address (172.29.14.45).所以重点是我想连接到位于确切地址(172.29.14.45)的 Rabbit 服务器。 Created listener container is trying to connect to localhost instead.
创建的侦听器容器正在尝试连接到 localhost。 It ignores rabbit port property as well.
它也忽略了兔子端口属性。
2021-02-23 23:04:59.715 [replyListenerContainer-1] INFO (AbstractConnectionFactory.java:636) - Attempting to connect to: [localhost:5672]
2021-02-23 23:05:01.721 [replyListenerContainer-1] ERROR (AbstractMessageListenerContainer.java:1877) - Failed to check/redeclare auto-delete queue(s).
org.springframework.amqp.AmqpConnectException: java.net.ConnectException: Connection refused: connect
and continues to restart consumer after that并在此之后继续重启消费者
2021-02-23 23:17:49.069 [replyListenerContainer-1] INFO (SimpleMessageListenerContainer.java:1428) - Restarting Consumer@2a140ce5: tags=[[]], channel=null, acknowledgeMode=AUTO local queue size=0
2021-02-23 23:17:49.069 [replyListenerContainer-1] DEBUG (BlockingQueueConsumer.java:758) - Closing Rabbit Channel: null
2021-02-23 23:17:49.071 [replyListenerContainer-2] INFO (AbstractConnectionFactory.java:636) - Attempting to connect to: [localhost:5672]
What should I do to tell spring to use my host property instead of localhost
?我应该怎么做才能告诉 spring 使用我的主机属性而不是
localhost
?
I always use the addresses property in the application.properties file我总是在 application.properties 文件中使用地址属性
spring.rabbitmq.addresses=amqp://username:password@host:port/vhost spring.rabbitmq.addresses=amqp://username:password@host:port/vhost
The name of the "virtual host" (or vhost) specifies the namespace for entities (such as exchanges and queues) referred to by the protocol. “虚拟主机”(或 vhost)的名称指定协议引用的实体(例如交换和队列)的命名空间。 Note that this is not virtual hosting in the HTTP sense.
请注意,这不是 HTTP 意义上的虚拟主机。
https://www.rabbitmq.com/uri-spec.html https://www.rabbitmq.com/uri-spec.html
example:例子:
spring.rabbitmq.addresses=amqp://ihrpsvpp:In4etuiIkgu7FVBr0tr6wYGvGcGyJ9Ja@lion.rmq.cloudamqp.com/ihrpsvpp spring.rabbitmq.addresses=amqp://ihrpsvpp:In4etuiIkgu7FVBr0tr6wYGvGcGyJ9Ja@lion.rmq.cloudamqp.com/ihrpsvpp
Ok, it turned out it was a bean refreshing context of the application, what caused autoconfiguration to fail好的,原来是应用程序的 bean 刷新上下文,导致自动配置失败
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.