RSocket

📅 2019-10-17

rsocket

Developers can customize the RSocketStrategies component by creating beans that implement the RSocketStrategiesCustomizer interface. Note that their @Order is important, as it determines the order of codecs.

Interaction Models

  • request/response (stream of 1)
  • request/stream (finite stream of many)
  • fire-and-forget (no response)
  • channel (bi-directional streams)

Links

Spring Related

  • 将 RSocket 暴露为 websocket

    spring.rsocket.server.mapping-path=/rsocket # a mapping path is defined
    spring.rsocket.server.transport=websocket # websocket is chosen as a transport
    #spring.rsocket.server.port= # no port is defined
    
  • 将 RSocket 暴露为 tcp

    spring.rsocket.server.port=9898 # the only required configuration
    spring.rsocket.server.transport=tcp # you're free to configure other properties
    
  • 如果不同的Service需要注入不同的 RSocketRequester, 可以这样写

    @Service
    public class MyService {
    
        private final RSocketRequester rsocketRequester;
    
        public MyService(RSocketRequester.Builder rsocketRequesterBuilder) {
            // 注意,RSocketRequester.Builder是spring自动注入的,是个prototype bean(即,stateful)
            this.rsocketRequester = rsocketRequesterBuilder
                    .connectTcp("example.org", 9898).block();
        }
    
        public Mono<User> someRSocketCall(String name) {
            return this.requester.route("user").data(name)
                    .retrieveMono(User.class);
        }
    
    }
    

Readings

Edit