Skip to content

Commit cdcba75

Browse files
mostroverkhovrobertroeser
authored andcommitted
improve readme (#30)
1 parent c025893 commit cdcba75

File tree

2 files changed

+102
-60
lines changed

2 files changed

+102
-60
lines changed

CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ When submitting code, please make every effort to follow existing conventions an
66

77
## License
88

9-
By contributing your code, you agree to license your contribution under the terms of the APLv2: https://github.com/RSocket/reactivesocket-java/blob/master/LICENSE
9+
By contributing your code, you agree to license your contribution under the terms of the APLv2: https://github.com/rsocket/rsocket-kotlin/blob/master/LICENSE
1010

1111
All files are released with the Apache 2.0 license.
1212

1313
If you are adding a new file it should have a header like this:
1414

1515
```
1616
/**
17-
* Copyright 2015 Netflix, Inc.
17+
* Copyright 2018 Netflix, Inc.
1818
*
1919
* Licensed under the Apache License, Version 2.0 (the "License");
2020
* you may not use this file except in compliance with the License.

README.md

Lines changed: 100 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,118 @@
1-
# RSOCKET-ANDROID
1+
# RSOCKET-KOTLIN
2+
<a href='https://travis-ci.org/rsocket/rsocket-kotlin/builds'><img src='https://travis-ci.org/rsocket/rsocket-kotlin.svg?branch=master'></a> [![Join the chat at https://gitter.im/RSocket/reactivesocket-java](https://badges.gitter.im/RSocket/reactivesocket-java.svg)](https://gitter.im/ReactiveSocket/reactivesocket-java)
23

3-
This is an implementation of [RSocket](http://rsocket.io/) - binary application protocol bringing [Reactive-Streams](http://www.reactive-streams.org/) semantics
4-
for network communications.
5-
`Kotlin` & `RxJava2` backport of [RSocket-java](https://github.com/rsocket/rsocket-java) intended for pre java8 runtimes.
6-
Relies on `OkHttp` as WebSockets transport. Target platform is Android (tested on API level 4.4+)
4+
R(eactive)Socket: [Reactive Streams](http://www.reactive-streams.org/) over network boundary (tcp, websockets, etc) using Kotlin/Rxjava
5+
6+
RSocket is binary application protocol which models all communication as multiplexed streams of messages over a single network connection, and never synchronously blocks while waiting for a response.
7+
8+
It enables following symmetric interaction models:
9+
10+
* fire-and-forget (no response)
11+
* request/response (stream of 1)
12+
* request/stream (finite/infinite stream of many)
13+
* channel (bi-directional streams)
14+
15+
Also, metadata can be associated with stream or RSocket itself
716

8-
Supports 4 interaction models: fire-and-forget, request-response, request-stream, request-channel.
9-
1017
## Build and Binaries
1118

12-
<a href='https://travis-ci.org/rsocket/rsocket-android/builds'><img src='https://travis-ci.org/rsocket/rsocket-android.svg?branch=master'></a>
13-
14-
15-
The project is not released yet, snapshots are available on Bintray
19+
Snapshots are available on Bintray
1620
```groovy
1721
repositories {
1822
maven { url 'https://oss.jfrog.org/libs-snapshot' }
1923
}
20-
```
21-
24+
```
2225

2326
```groovy
24-
dependencies {
25-
compile 'io.rsocket:rsocket-android-core:0.9-SNAPSHOT'
26-
compile 'io.rsocket:rsocket-transport-okhttp:0.9-SNAPSHOT'
27-
}
27+
dependencies {
28+
compile 'io.rsocket.android:rsocket-core:0.9-SNAPSHOT'
29+
}
30+
```
31+
### Transports
32+
`Netty` based Websockets and TCP transport (`Client` and `Server`)
33+
`OkHttp` based Websockets transport (`Client` only)
34+
```groovy
35+
dependencies {
36+
compile 'io.rsocket.android:rsocket-transport-netty:0.9-SNAPSHOT'
37+
compile 'io.rsocket.android:rsocket-transport-okhttp:0.9-SNAPSHOT'
38+
}
39+
```
40+
### Usage
41+
Each side of connection (Client and Server) has `Requester RSocket` for making requests to peer, and `Responder RSocket` to handle requests from peer.
42+
43+
Messages for all interactions are represented as `Payload` of binary (`NIO ByteBuffer`) data and metadata.
44+
45+
UTF-8 `text` payloads can be constructed as follows
46+
```kotlin
47+
val request = PayloadImpl.textPayload("data", "metadata")
48+
```
49+
Stream Metadata is optional
50+
```kotlin
51+
val request = PayloadImpl.textPayload("data")
2852
```
29-
30-
## USAGE
31-
Sample mobile application for verifying interactions is available [here](https://github.com/mostroverkhov/rsocket-backport-demo)
32-
33-
### Client
34-
Client initiates new `Connections`. Because protocol is duplex, each side of connection has
35-
`Requester` RSocket for making requests to peer, and `Responder` RSocket to handle
36-
requests from peer. `Responder` RSocket is optional for Client.
37-
38-
```
39-
val rSocket: Single<RSocket> = RSocketFactory // Requester RSocket
53+
#### Interactions
54+
Fire and Forget
55+
`RSocket.fireAndForget(payload: Payload): Completable`
56+
Request-Response
57+
`RSocket.requestResponse(payload: Payload): Single<Payload>`
58+
Request-Stream
59+
`RSocket.requestStream(payload: Payload): Flowable<Payload>`
60+
Request-Channel
61+
`RSocket.requestChannel(payload: Publisher<Payload>): Flowable<Payload>`
62+
Metadata-Push
63+
`fun metadataPush(payload: Payload): Completable`
64+
65+
#### Client
66+
Client is initiator of `Connections`
67+
```kotlin
68+
val rSocket: Single<RSocket> = RSocketFactory // Requester RSocket
4069
.connect()
41-
.acceptor { -> handler() } // Optional responder RSocket
70+
.acceptor { { requesterRSocket -> handler(requesterRSocket) } } // Optional handler RSocket
4271
.transport(OkhttpWebsocketClientTransport // WebSockets transport
43-
.create(protocol, host, port))
72+
.create(protocol, host, port))
4473
.start()
45-
46-
private fun handler(): RSocket {
74+
75+
private fun handler(requester:RSocket): RSocket {
4776
return object : AbstractRSocket() {
48-
override fun fireAndForget(payload: Payload): Completable {
49-
return Completable.fromAction {Log.d("tag", "fire-n-forget from server")}
77+
override fun requestStream(payload: Payload): Flowable<Payload> {
78+
return Flowable.just(PayloadImpl.textPayload("client handler response"))
5079
}
5180
}
5281
}
53-
```
54-
Messages for all 4 interactions are represented as `Payload` of binary (nio `ByteBuffer`) data
55-
and metadata (to/from UTF8-string utility methods are available)
56-
57-
Request-stream
58-
```
59-
rSocket.flatMapPublisher {
60-
it.requestStream(PayloadImpl("req-stream ping"))
61-
}.subscribe { responsePayload -> Log.d("request-stream", responsePayload.getDataUtf8)}
62-
```
63-
64-
Request-channel
65-
```
66-
rSocket.flatMapPublisher {
67-
it.requestChannel(Flowable.just(
68-
PayloadImpl("req-channel1"),
69-
PayloadImpl("req-channel2")))
70-
}.subscribe { responsePayload -> Log.d("request-stream", responsePayload.getDataUtf8)}
71-
```
72-
### Server
73-
Server accepts new `Connections` from peers. Same as `Client` it has `Requester` and `Responder` RSockets.
74-
As this project does not provide server implementation, use [RSocket-java](https://github.com/rsocket/rsocket-java) with `Netty` based `WebSockets`
75-
transport. Check its [examples](https://github.com/rsocket/rsocket-java/tree/1.0.x/rsocket-examples) folder or sample [app](https://github.com/mostroverkhov/rsocket-backport-demo/tree/master/rsocket-server-netty) minimalistic server
76-
82+
```
83+
#### Server
84+
Accepts `Connections` from `Clients`
85+
```kotlin
86+
val closeable: Single<Closeable> = RSocketFactory
87+
.receive()
88+
.acceptor { { setup, rSocket -> handler(setup, rSocket) } } // server handler RSocket
89+
.transport(WebsocketServerTransport.create(port)) // Netty websocket transport
90+
.start()
91+
92+
93+
private fun handler(setup: Setup, rSocket: RSocket): Single<RSocket> {
94+
return Single.just(object : AbstractRSocket() {
95+
override fun requestStream(payload: Payload): Flowable<Payload> {
96+
return Flowable.just(PayloadImpl.textPayload("server handler response"))
97+
}
98+
})
99+
}
100+
101+
```
102+
103+
### LICENSE
104+
105+
Copyright 2015-2018 Netflix, Inc.
106+
Maksym Ostroverkhov
107+
108+
Licensed under the Apache License, Version 2.0 (the "License");
109+
you may not use this file except in compliance with the License.
110+
You may obtain a copy of the License at
111+
112+
http://www.apache.org/licenses/LICENSE-2.0
113+
114+
Unless required by applicable law or agreed to in writing, software
115+
distributed under the License is distributed on an "AS IS" BASIS,
116+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
117+
See the License for the specific language governing permissions and
118+
limitations under the License.

0 commit comments

Comments
 (0)