RSocket 面向连接的、消息驱动的协议 项目简介
RSocket 就是为服务而设计的。它是面向连接的、消息驱动的协议,内置了应用程序级的流控制。它在浏览器中和在服务器上一样工作。事实上,Web 浏览器可以服务于后端微服务的流量。它也是二进制的。它可以同样好地处理文本和二进制数据,并且可以分解有效工作负载。它将应用程序中的所有交互建模为网络原语。这意味着,你可以流化数据或执行发布 / 订阅,而无需设置应用程序队列。目前提供 Java、JavaScript、C++ 和 Kotlin 版本实现。服务端示例代码:RSocketFactory.receive()
.frameDecoder(Frame::retain)
.acceptor(new PingHandler())
.transport(TcpServerTransport.create(7878))
.start()
.block()
.onClose();客户端示例代码:Mono<RSocket> client =
RSocketFactory.connect()
.frameDecoder(Frame::retain)
.transport(TcpClientTransport.create(7878))
.start();PingClient pingClient = new PingClient(client);Recorder recorder = pingClient.startTracker(Duration.ofSeconds(1));int count = 1_000;pingClient .startPingPong(count, recorder)
.doOnTerminate(() -> System.out.println("Sent " + count + " messages."))
.blockLast();
.frameDecoder(Frame::retain)
.acceptor(new PingHandler())
.transport(TcpServerTransport.create(7878))
.start()
.block()
.onClose();客户端示例代码:Mono<RSocket> client =
RSocketFactory.connect()
.frameDecoder(Frame::retain)
.transport(TcpClientTransport.create(7878))
.start();PingClient pingClient = new PingClient(client);Recorder recorder = pingClient.startTracker(Duration.ofSeconds(1));int count = 1_000;pingClient .startPingPong(count, recorder)
.doOnTerminate(() -> System.out.println("Sent " + count + " messages."))
.blockLast();