Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 42 additions & 61 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# rsocket-kotlin

RSocket Kotlin multi-platform implementation based on [kotlinx.coroutines](https://github.com/Kotlin/kotlinx.coroutines).

RSocket is a binary protocol for use on byte stream transports such as TCP, WebSockets and Aeron.
Expand All @@ -13,92 +14,72 @@ It enables the following symmetric interaction models via async message passing
Learn more at http://rsocket.io

## Supported platforms and transports :
Transports are implemented based on [ktor](https://github.com/ktorio/ktor) to ensure Kotlin multiplatform.
So it depends on `ktor` engines for available transports and platforms (JVM, JS, Native):

Transports are implemented based on [ktor](https://github.com/ktorio/ktor) to ensure Kotlin multiplatform. So it depends on `ktor` engines
for available transports and platforms (JVM, JS, Native):

* JVM - TCP and WebSocket for both client and server
* JS - WebSocket client only
* Native - TCP client only (linux x64, macos, ios, watchos, tvos)
* Native - TCP (linux x64, macos, ios, watchos, tvos) for both client and server

## Interactions

RSocket interface contains 5 methods:
* Fire and Forget:

* Fire and Forget:

`suspend fun fireAndForget(payload: Payload)`
* Request-Response:

`suspend requestResponse(payload: Payload): Payload`
* Request-Stream:
* Request-Stream:

`fun requestStream(payload: Payload): Flow<Payload>`
* Request-Channel:

`fun requestChannel(initPayload: Payload, payloads: Flow<Payload>): Flow<Payload>`
* Metadata-Push:

`suspend fun metadataPush(metadata: ByteReadPacket)`

## Using in your projects

Make sure, that you use Kotlin 1.5.20

### Gradle:


```groovy
```kotlin
repositories {
jcenter()
mavenCentral()
}
dependencies {
implementation 'io.rsocket.kotlin:rsocket-core:0.13.1'
implementation 'io.rsocket.kotlin:rsocket-transport-ktor:0.13.1'

// client feature for ktor
// implementation 'io.rsocket.kotlin:rsocket-transport-ktor-client:0.13.1'

// server feature for ktor
// implementation 'io.rsocket.kotlin:rsocket-transport-ktor-server:0.13.1'

// one of ktor engines to work with websockets
// client engines
// implementation 'io.ktor:ktor-client-js:1.6.1' //js
// implementation 'io.ktor:ktor-client-cio:1.6.1' //jvm
// implementation 'io.ktor:ktor-client-okhttp:1.6.1' //jvm

// server engines (jvm only)
// implementation 'io.ktor:ktor-server-cio:1.6.1'
// implementation 'io.ktor:ktor-server-netty:1.6.1'
// implementation 'io.ktor:ktor-server-jetty:1.6.1'
// implementation 'io.ktor:ktor-server-tomcat:1.6.1'
implementation("io.rsocket.kotlin:rsocket-core:0.14.0")

// TCP ktor transport
implementation("io.rsocket.kotlin:rsocket-transport-ktor:0.14.0")

// WS ktor transport client plugin
implementation("io.rsocket.kotlin:rsocket-transport-ktor-client:0.14.0")

// WS ktor transport server plugin
implementation("io.rsocket.kotlin:rsocket-transport-ktor-server:0.14.0")
}
```

### Gradle Kotlin DSL:
For WS ktor transport, available client or server engine should be added:

```kotlin
repositories {
jcenter()
}
dependencies {
implementation("io.rsocket.kotlin:rsocket-core:0.13.1")
implementation("io.rsocket.kotlin:rsocket-transport-ktor:0.13.1")

// client feature for ktor
// implementation("io.rsocket.kotlin:rsocket-transport-ktor-client:0.13.1")

// server feature for ktor
// implementation("io.rsocket.kotlin:rsocket-transport-ktor-server:0.13.1")

// one of ktor engines to work with websockets
// client engines
// implementation("io.ktor:ktor-client-js:1.6.1") //js
// implementation("io.ktor:ktor-client-cio:1.6.1") //jvm
// implementation("io.ktor:ktor-client-okhttp:1.6.1") //jvm

// server engines (jvm only)
// implementation("io.ktor:ktor-server-cio:1.6.1")
// implementation("io.ktor:ktor-server-netty:1.6.1")
// implementation("io.ktor:ktor-server-jetty:1.6.1")
// implementation("io.ktor:ktor-server-tomcat:1.6.1")
// client engines for WS transport
implementation("io.ktor:ktor-client-js:1.6.2") //js
implementation("io.ktor:ktor-client-cio:1.6.2") //jvm
implementation("io.ktor:ktor-client-okhttp:1.6.2") //jvm

// server engines for WS transport (jvm only)
implementation("io.ktor:ktor-server-cio:1.6.2")
implementation("io.ktor:ktor-server-netty:1.6.2")
implementation("io.ktor:ktor-server-jetty:1.6.2")
implementation("io.ktor:ktor-server-tomcat:1.6.2")
}
```

Expand All @@ -116,7 +97,7 @@ val client = HttpClient(CIO) {
connectionConfig {
keepAlive = KeepAlive(
interval = 30.seconds,
maxLifetime = 2.minutes
maxLifetime = 2.minutes
)

//payload for setup frame
Expand All @@ -128,15 +109,15 @@ val client = HttpClient(CIO) {
metadata = "application/json"
)
}

//optional acceptor for server requests
acceptor {
RSocketRequestHandler {
requestResponse { it } //echo request payload
}
}
}
}
}
}

//connect to some url
Expand Down Expand Up @@ -196,9 +177,9 @@ embeddedServer(CIO) {
### More examples:

- [interactions](examples/interactions) - contains usages of some supported functions
- [multiplatform-chat](examples/multiplatform-chat) - chat implementation with JVM server and JS/JVM client with shared classes
and serializing data using [kotlinx.serialization](https://github.com/Kotlin/kotlinx.serialization)
- [nodejs-tcp-transport](examples/nodejs-tcp-transport) - implementation of TCP transport for nodejs
- [multiplatform-chat](examples/multiplatform-chat) - chat implementation with JVM server and JS/JVM client with shared classes and
serializing data using [kotlinx.serialization](https://github.com/Kotlin/kotlinx.serialization)
- [nodejs-tcp-transport](examples/nodejs-tcp-transport) - implementation of TCP transport for nodejs

## Reactive Streams Semantics

Expand Down
38 changes: 21 additions & 17 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -152,25 +152,29 @@ subprojects {
languageVersion = "1.5"
apiVersion = "1.5"

useExperimentalAnnotation("kotlin.RequiresOptIn")
optIn("kotlin.RequiresOptIn")

//TODO: kludge, this is needed now, as ktor isn't fully supports kotlin 1.5.3x opt-in changes
// will be not needed in future with ktor 2.0.0
optIn("io.ktor.utils.io.core.ExperimentalIoApi")

if (name.contains("test", ignoreCase = true) || isTestProject || isPlaygroundProject) {
useExperimentalAnnotation("kotlin.time.ExperimentalTime")
useExperimentalAnnotation("kotlin.ExperimentalStdlibApi")

useExperimentalAnnotation("kotlinx.coroutines.ExperimentalCoroutinesApi")
useExperimentalAnnotation("kotlinx.coroutines.InternalCoroutinesApi")
useExperimentalAnnotation("kotlinx.coroutines.ObsoleteCoroutinesApi")
useExperimentalAnnotation("kotlinx.coroutines.FlowPreview")
useExperimentalAnnotation("kotlinx.coroutines.DelicateCoroutinesApi")

useExperimentalAnnotation("io.ktor.util.InternalAPI")
useExperimentalAnnotation("io.ktor.utils.io.core.internal.DangerousInternalIoApi")

useExperimentalAnnotation("io.rsocket.kotlin.TransportApi")
useExperimentalAnnotation("io.rsocket.kotlin.ExperimentalMetadataApi")
useExperimentalAnnotation("io.rsocket.kotlin.ExperimentalStreamsApi")
useExperimentalAnnotation("io.rsocket.kotlin.RSocketLoggingApi")
optIn("kotlin.time.ExperimentalTime")
optIn("kotlin.ExperimentalStdlibApi")

optIn("kotlinx.coroutines.ExperimentalCoroutinesApi")
optIn("kotlinx.coroutines.InternalCoroutinesApi")
optIn("kotlinx.coroutines.ObsoleteCoroutinesApi")
optIn("kotlinx.coroutines.FlowPreview")
optIn("kotlinx.coroutines.DelicateCoroutinesApi")

optIn("io.ktor.util.InternalAPI")
optIn("io.ktor.utils.io.core.internal.DangerousInternalIoApi")

optIn("io.rsocket.kotlin.TransportApi")
optIn("io.rsocket.kotlin.ExperimentalMetadataApi")
optIn("io.rsocket.kotlin.ExperimentalStreamsApi")
optIn("io.rsocket.kotlin.RSocketLoggingApi")
}
}
}
Expand Down
16 changes: 8 additions & 8 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@

#Project
group=io.rsocket.kotlin
version=0.13.1
version=0.14.0

#Versions
kotlinVersion=1.5.21
ktorVersion=1.6.1
kotlinxCoroutinesVersion=1.5.1-native-mt
kotlinxAtomicfuVersion=0.16.2
kotlinxSerializationVersion=1.2.2
kotlinVersion=1.5.31
ktorVersion=1.6.4
kotlinxCoroutinesVersion=1.5.2-native-mt
kotlinxAtomicfuVersion=0.16.3
kotlinxSerializationVersion=1.3.0
kotlinxBenchmarkVersion=0.3.1
kotlinxNodejsVersion=0.0.7
rsocketJavaVersion=1.1.1
turbineVersion=0.5.2
artifactoryVersion=4.24.12
turbineVersion=0.6.1
artifactoryVersion=4.24.20
versionUpdatesVersion=0.39.0
gradleEnterpriseVersion=3.4.1

Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.1.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading