使用RSocketFactory的替代方法

huangapple go评论76阅读模式
英文:

Using the replacement of RSocketFactory

问题

我一直在查阅一些 RSocket 的演示和示例,以了解它们的工作原理,但其中大多数往往包含过时的代码片段。

例如,我有这个示例,它使用了被弃用的 RSocketFactory。

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

我通过进一步搜索发现,它被 RSocketConnectorConfigurer 替代了,但是我找不到新用法的示例代码。有没有之前尝试过 RSocket 的人可以帮助解释如何使用新的配置方法?

谢谢!

英文:

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!

答案1

得分: 5

我也遇到了类似的问题,因为 API 更改导致的。你可以使用以下示例。

更多信息请查看这里 - 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));
    }

}
英文:

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 -&gt; encoders.add(new Jackson2CborEncoder()))
                .decoders(decoders -&gt; decoders.add(new Jackson2CborDecoder()))
                .build();
    }

    @Bean
    public Mono&lt;RSocketRequester&gt; getRSocketRequester(RSocketRequester.Builder builder){
        return builder
                .rsocketConnector(rSocketConnector -&gt; rSocketConnector.reconnect(Retry.fixedDelay(2, Duration.ofSeconds(2))))
                .dataMimeType(MediaType.APPLICATION_CBOR)
                .connect(TcpClientTransport.create(6565));
    }

}

huangapple
  • 本文由 发表于 2020年8月19日 22:59:47
  • 转载请务必保留本文链接:https://go.coder-hub.com/63489822.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定