gpt4 book ai didi

spring-boot - 如何用spring-rabbit配置RabbitMQ连接?

转载 作者:行者123 更新时间:2023-12-03 12:26:48 26 4
gpt4 key购买 nike

我正在关注 this guide学习如何使用 spring-rabbit使用 RabbitMQ。但是,在本指南中,RabbitMQ 配置是默认配置(本地主机服务器,凭据为 guest / guest )。如果我想使用ip地址和凭据连接到远程RabbitMQ应该怎么做?我不知道在我的应用程序中在哪里设置这些信息。

最佳答案

该指南的应用程序是 Spring Boot 应用程序。

添加文件 application.propertiessrc/main/resources .

然后,您可以根据 Spring Boot Documentation 配置rabbitmq 属性。 - 向下滚动到 rabbitmq 属性...

...
spring.rabbitmq.host=localhost # RabbitMQ host.
...
spring.rabbitmq.password= # Login to authenticate against the broker.
spring.rabbitmq.port=5672 # RabbitMQ port.
...
spring.rabbitmq.username= # Login user to authenticate to the broker.
...

要连接到集群,请使用
spring.rabbitmq.addresses= # Comma-separated list of addresses to which the client should connect.

例如 server1:5672,server2:5672 .

如果您不想使用引导自动配置,请声明 CachingConnectionFactory @Bean自己并根据需要进行配置。

关于spring-boot - 如何用spring-rabbit配置RabbitMQ连接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42200317/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com