It's my pleasure to introduce you to RSocket Swift, a Client and Server implementation of the RSocket (Reactive Socket) network protocol on top of SwiftNIO.
RSocket provides a protocol for Reactive Streams semantics between client-server, and server-server communication. It is a binary protocol for use on byte stream transports such as TCP, WebSockets, and Aeron.
- support for interaction models beyond request/response such as streaming responses and push
- application-level flow control semantics (async pull/push of bounded batch sizes) across network boundaries
- binary, multiplexed use of a single connection
- support resumption of long-lived subscriptions across transport connections
We are still actively working on it and the API will change for sure. Nevertheless, I will give you an overview of the general architecture and a client code example.
We have split the implementation into multiple modules. This allows a user of this package to only include what is really needed.
RSocketCore, as the name implies, contains the core logic which every other module depends on.
The other modules are grouped in one of three categories:
Channel - convenience client bootstrap implementation which configures a SwiftNIO Channel Pipeline and takes care of TLS/SSL, EventLoopGroup creation and shutdown. Either
RSocketTSChannelwhich uses swift-nio-transport-services (i.e. Network.framework) or
swift-nio-sslfor TLS/SSL and the default channel implementation for a TCP connection.
Transport Protocol - RSocket can run on top of any message-stream oriented transport protocol.
RSocketWSTransportcontains channel handlers which allow RSocket to run over WebSocket.
RSocketTCPTransportis the equivalent for a plain TCP connection.
Reactive Streams - RSocket Swift lets you choose which implementation of Reactive Streams you want to use. ReactiveSwift is implemented, Combine and async/await/AsyncSequence are work in progress. You can also mix two reactive stream libraries and do some requests with Combine and some with async/await over the same connection.
A User will usually only chose one from each category.
All Mandatory Core Protocol Features have been implemented and tested against the Java and Kotlin implementation.
Working examples can be found under Sources/Examples. TimerClient and TwitterClient connect to demo.rsocket.io/rsocket where a Kotlin Server is running and work without running a server locally.
The Client API has currently a lot more convenience API's and is a lot simpler than the Server API. If you want to create a RSocket Server you need to create you own SwiftNIO pipeline and setup SSL/TLS yourself. This will be improved in the future as we implement some RSocket extensions like Routing.
- Automatic reconnect for Clients
- RSocket extensions including Composite Metadata, Routing and per Stream Data MIME Types
- Autogenerated Documentation
- Server Examples
We, @OlegDokuka, @nkristek and myself, now want to gather feedback from the Swift Community. After that, we want to pitch this project to the SSWG and go through the Incubation Process to become one of the recommended projects.