Introducing RSocket Swift

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.

What is RSocket?

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.
Key Features:

  • 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

More Information about RSocket can be found at rsocket.io and a greate presentation from @OlegDokuka is available on YouTube.

Swift implementation

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.

Modules

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 RSocketTSChannel which uses swift-nio-transport-services (i.e. Network.framework) or RSocketNIOChannel which uses swift-nio-ssl for 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. RSocketWSTransport contains channel handlers which allow RSocket to run over WebSocket. RSocketTCPTransport is 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.

Current State

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.

What is planned

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.

13 Likes

This is super cool and very exciting! Thank you for writing this up.

I very much think that RSocket is relevant to the Swift on Server community so big +1 from me to an SSWG proposal :slight_smile: .

4 Likes

Thanks a lot David! I'm very excited your great work on this! :slight_smile:

It's always shocking to me what a small world it is hehe... not too long ago we were discussing and kicking off initial rsocket designs along with reactive-streams and now it's grown into a real thing and also a swift implementation, so amazing! :star_struck:

I'm tracking the repo and can't wait to see it mature; looking forward to welcoming it in the sswg sandbox when you feel ready to pitch :slight_smile:

4 Likes