在SpringCloud使用RSocket替代Rabbit或Kafka作为消息路由中继的源码案例


带有RSocket路由的spring-cloud-bus作为传输的示例应用程序。点击标题进入源码:

  • 克隆https://github.com/spencergibb/rsocket-routing-sample 运行 BrokerApplication
  • 运行 DemobusApplication
  • 运行 DemobusApplication --spring.profiles.active=bus2
  • 运行 http POST :8080/actuator/busrefresh 或 http POST :8080/actuator/busrefresh/service_name=busclient.

您应该在DemobusApplication输出中看到类似以下内容的内容:
2020-10-23 15:23:51.548 DEBUG 206569 --- [tor-tcp-epoll-2] o.springframework.cloud.bus.BusConsumer  : Received remote event from bus: [RefreshRemoteApplicationEvent@12fd361c id = '14d10461-a197-4773-95ac-9030a59cd96d', originService = 'busclient:busclient-1', destinationService = 'bus=true']
2020-10-23 15:23:51.548  INFO 206569 --- [tor-tcp-epoll-2] o.s.cloud.bus.event.RefreshListener      : Received remote refresh request.
2020-10-23 15:23:51.659  INFO 206569 --- [tor-tcp-epoll-2] o.s.cloud.bus.event.RefreshListener      : Keys refreshed []

注意到上面/busrefresh后面XXX=XXX如service_name=busclient.现在/actuator/busrefresh/service_name=busclient/instance_name=busclient-2将匹配两个客户端。
两个客户端都会看到类似:

2020-10-23 16:06:50.810  INFO 214362 --- [nio-8080-exec-1] o.s.cloud.bus.event.RefreshListener      : Refresh not performed, the event was targeting bus=true;service_name=busclient;instance_name=busclient-2