spring cloud学习之十:消息总线 Spring Cloud Bus

在微服务系统中,消息总线可通过轻量级消息代理广播消息供服务订阅消费。Spring Cloud中用Spring Cloud Bus实现此功能,默认使用RabbitMQ。本文介绍了在pom.xml添加依赖、在配置文件添加Rabbit MQ配置来完成消息总线配置,还提及配置后访问地址的问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在微服务系统中,使用轻量级消息代理创建一个公共的主题通过广播的方式让所有服务进行订阅消费- - 消息总线。
消息代理(Message Broker):是一种消息验证、传输、路由的架构模式。在应用程序之间起到相互通讯、降低耦合度等作用。
spring cloud 中使用 spring cloud bus 实现消息总线的功能,默认使用RabbitMQ消息中间件。下面就进行配置消息总线。

1、pom.xml添加依赖

<!--springcloud-bus-->
		<!-- https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-bus-amqp -->
		<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-starter-bus-amqp</artifactId>
			<version>1.3.2.RELEASE</version>
		</dependency>

2、配置文件添加Rabbit MQ配置

#配置RabbitMQ
spring.rabbitmq.host=192.168.xxx.xxx
spring.rabbitmq.port=5672
spring.rabbitmq.username=admin
spring.rabbitmq.password=a123456

通过上面的配置到各应用服务及config-server就已经配置完成消息总线的功能,通过post访问http://ip:port/bus/refresh?destination=服务名:**的方式会使服务名对应的服务刷新配置–使用@RefreshScope 注解的属性。或者http://ip:port/contextPath/bus/refresh的方式访问,会发现相应工程会重新拉取配置。
问题:
访问上边的地址控制台会提示Full authentication is required to access actuator endpoints. Consider adding Spring Security or set 'management.security.enabled' to false.

设置 management.security.enabled=false  ,来暴露端点

流向图:
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值