好的,我是 RSocket 的新手。我正在尝试创建一个简单的 RSocket 客户端和简单的 RSocket 服务器。从我所做的研究来看,RSocket 支持恢复:
它特别有用,因为当发送包含有关最后接收帧的信息的 RESUME 帧时,客户端能够恢复连接并仅请求它尚未收到的数据,避免服务器上不必要的负载和浪费时间尝试检索已经检索到的数据。
它还说客户端是负责启用恢复的人。我的问题是如何启用此恢复以及如何发送该 RESUME 帧。我有功能正常的客户端和服务器,但是如果我关闭服务器并再次启动它,则什么也不会发生,稍后当客户端再次尝试与服务器通信时,它会抛出:java.nio.channels.ClosedChannelException。
这是我的客户端配置:
@Configuration
public class ClientConfiguration {
/**
* Defining the RSocket client to use tcp transport on port 7000
*/
@Bean
public RSocket rSocket() {
return RSocketFactory
.connect()
.resumeSessionDuration(Duration.ofDays(10))
.mimeType(MimeTypeUtils.APPLICATION_JSON_VALUE, MimeTypeUtils.APPLICATION_JSON_VALUE)
.frameDecoder(PayloadDecoder.ZERO_COPY)
.transport(TcpClientTransport.create(7000))
.start()
.block();
}
/**
* RSocketRequester bean which is a wrapper around RSocket
* and it is used to communicate with the RSocket server
*/
@Bean
RSocketRequester rSocketRequester(RSocketStrategies rSocketStrategies) {
return RSocketRequester.wrap(rSocket(), MimeTypeUtils.APPLICATION_JSON, MimeTypeUtils.APPLICATION_JSON, rSocketStrategies);
}
}
这是我开始与 rsocket 服务器通信的 RestController:
@RestController
public class UserDataRestController {
private final RSocketRequester rSocketRequester;
public UserDataRestController(RSocketRequester.Builder rSocketRequester) {
this.rSocketRequester = rSocketRequester.connectTcp("localhost", 7000).block();
}
@GetMapping(value = "/feed/{firstName}", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
public Publisher<Person> feed(@PathVariable("firstName") String firstName) {
return rSocketRequester
.route("feedPersonData")
.data(new PersonDataRequest(firstName))
.retrieveFlux(Person.class);
}
}