springboot集成rabbitmq——采坑

欢迎大家关注我的公众号,添加我为好友!

1.我是在CentOS7下面安装的rabbitmq,通过浏览器访问的时候记得关闭防火墙

2.配置application.properties 的时候记得写对配置(测试通过配置如下)

   注意:不要把ip地址加上前缀,如“http://192.168.52.133” 端口号是“5672” 不是管控台的“15672”

spring.rabbitmq.host=192.168.52.133
spring.rabbitmq.port=5672
spring.rabbitmq.username=guest
spring.rabbitmq.password=guest
spring.rabbitmq.virtual-host=/
spring.rabbitmq.connection-timeout=15000ms
server.servlet.context-path=/
spring.http.encoding.charset=utf-8
spring.jackson.date-format=yyyy-MM-dd HH:mm:ss
spring.jackson.time-zone=GMT+8
spring.jackson.default-property-inclusion=non_null

3.采坑中。。。。。。

欢迎大家关注我的公众号,添加我为好友!

### Spring Boot 集成 RabbitMQ 教程 #### 项目结构设置 为了使Spring Boot应用程序能够与RabbitMQ交互,需创建测试类`SpringbootOrderRabbitmqProducerApplicationTests`用于验证生产者发送消息的功能。该类位于路径`src/test/java/com/xxx/rabbitmq/SpringbootOrderRabbitmqProducerApplicationTests.java`并引入必要的包以便于操作订单服务[^1]。 ```java package com.xxx.rabbitmq; import com.xxx.rabbitmq.service.OrderService; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; @SpringBootTest class SpringbootOrderRabbitmqProducerApplicationTests { @Autowired private OrderService orderService; /** * 测试ttl过期时间方法 */ @Test void contextLoadsTtl() { orderService.makeOrderTTL("2","1",2); } } ``` #### 启用定时任务支持 要在应用中加入定时任务的支持,在主程序上添加`@EnableScheduling`注解来激活基于注解的调度功能[^2]: ```java @EnableAsync // 开启异步执行能力 @EnableScheduling // 开启定时任务处理 @SpringBootApplication public class SpringbootTaskApplication { public static void main(String[] args) { SpringApplication.run(SpringbootTaskApplication.class, args); } } ``` #### 修改默认配置项 利用application.properties或application.yml文件调整Spring Boot内建组件的行为模式,比如更改服务器监听端口或是数据库连接字符串等参数[^3]。对于RabbitMQ而言,则可能涉及如下属性设定: - `spring.rabbitmq.host`: 设置主机地址,默认localhost。 - `spring.rabbitmq.port`: 设定客户端访问的服务端口,默认5672。 - `spring.rabbitmq.username/password`: 登录凭证信息。 #### 实现复杂的消息路由逻辑 借助Exchange完成更加精细的消息分发策略定义。除了标准类型的exchange外,还可以自定义组合形式满足特定业务场景下的需求[^4]。 #### 处理接收到的信息 当hotel-demo模块接收到来自MQ的通知后,会依据具体指令取相应行动——如新增记录至Elasticsearch索引或者移除已存在的文档实例[^5]。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值