英文:
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 -> 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));
}
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论