Search code examples
javaspringlombokrsocket

Using the replacement of RSocketFactory


I have been looking through a few RSocket demos and examples to see how they work but most of them tend to have outdated pieces of code.

For example, I have got this demo, with uses RSocketFactory when happens to be deprecated.

@Bean
RSocket rSocket () {
    return RSocketFactory
            .connect()
            .dataMimeType(MimeTypeUtils.APPLICATION_JSON_VALUE)
            .frameDecoder(PayloadDecoder.ZERO_COPY)
            .transport(TcpClientTransport.create(7000))
            .start()
            .block();
}

I found out through searching more that it was replaced by RSocketConnectorConfigurer but I wasn't able to find example code of the new usage. Any chance someone that has played around with RSocket before could help with using the new method for configuration?

Thanks!


Solution

  • I was also facing similar issue due to the api changes. You can use this example.

    Check here for more info - http://www.vinsguru.com/rsocket-integrating-with-spring-boot/

    @Configuration
    public class RSocketConfig {
    
        @Bean
        public RSocketStrategies rSocketStrategies() {
            return RSocketStrategies.builder()
                    .encoders(encoders -> encoders.add(new Jackson2CborEncoder()))
                    .decoders(decoders -> decoders.add(new Jackson2CborDecoder()))
                    .build();
        }
    
        @Bean
        public Mono<RSocketRequester> getRSocketRequester(RSocketRequester.Builder builder){
            return builder
                    .rsocketConnector(rSocketConnector -> rSocketConnector.reconnect(Retry.fixedDelay(2, Duration.ofSeconds(2))))
                    .dataMimeType(MediaType.APPLICATION_CBOR)
                    .connect(TcpClientTransport.create(6565));
        }
    
    }