天天看点

spring cloud bus

在MQ上会创建一个 springCloudBus 的 exchange

每个服务都会创建一个 springCloudBus.anonymous.xxx 的队列(queue)

--springCloudBus.anonymous.Bp0n_077SIaJXXZFzGS_hQ

每个queue都会绑定exchange,routingKey 为: #

 -- 意思是接受所有的消息

----------------------

当调用配置刷新时,调用:

POST http://localhost:8081/config/actuator/bus-refresh

会发送一条消息到MQ:

exchange: springCloudBus ,routingKey : springCloudBus

消息内容大概这样:

{"type":"RefreshRemoteApplicationEvent","timestamp":1540780323493,"originService":"config:8081:978efb4c523dc1553ec6df9f86e8574a","destinationService":"customers:9000:**","id":"5cf7d445-0fdb-4666-8017-a4cbbf55f064"}

每个服务(Queue)都会收到该信息,然后每一个都会发送一个确认消息:

{"type":"AckRemoteApplicationEvent","timestamp":1540780484680,"originService":"gateway:8084:5a04db0104b673cb01e9961467796631","destinationService":"**","id":"bbfb9bf2-7cff-4928-9c4f-1d192b04de8c","ackId":"4e320d18-2a58-41e6-aecd-98e0a66faae3","ackDestinationService":"**","event":"org.springframework.cloud.bus.event.RefreshRemoteApplicationEvent"}

这种模式依赖于客户端的消息过滤,如果某个服务的消息量较大,会拖垮其它服务

所以这种模式应该用于配置等一些通用的通道,其它业务消息事件等采用另外一套,不要混合到一起

@StreamListener 注解需要包含在 @Configuration 类中才会被扫描到

引入 bus 会导致  ClasspathLoggingApplicationListener 被触发两次

配置中心也会拉取两次,开启debug,就可以从日志看出来

官方说是正常现象,目前也没发现异常状况

https://stackoverflow.com/questions/48406527/spring-cloud-config-bus-calls-twice-to-the-config-server-when-the-binder-is-cr

https://github.com/spring-cloud/spring-cloud-stream/issues/1188

继续阅读