在SpringCloud使用RSocket替代Rabbit或Kafka作為訊息路由中繼的原始碼案例

banq發表於2020-10-24

帶有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


 

相關文章