|
1 |
| -####RSOCKET-ANDROID |
| 1 | +#### RSOCKET-ANDROID |
2 | 2 |
|
3 |
| -Ongoing effort to make [rsocket-java](https://github.com/rsocket/rsocket-java) available pre java8. This project focus is client-server communication use case, and it complements original one - intended |
4 |
| -mainly for server-server. The goal is to make rsocket practically useful for native mobile (support android 4.4+) while interacting with jvm based backends (primary platform is `Spring Boot`). Backend is assumed to run original `rsocket-java`. Interop with `rsocket` implementations on other tech stacks is not a goal of this project. |
| 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+) |
| 7 | + |
| 8 | +Supports 4 interaction models: fire-and-forget, request-response, request-stream, request-channel. |
5 | 9 |
|
| 10 | + ##### USAGE |
| 11 | + Sample mobile application for verifying interactions is available [here](https://github.com/mostroverkhov/rsocket-backport-demo) |
| 12 | + |
| 13 | + ######Client |
| 14 | + Client initiates new `Connections`. Because protocol is duplex, each side of connection has |
| 15 | + `Requester` RSocket for making requests to peer, and `Responder` RSocket to handle |
| 16 | + requests from peer. `Responder` RSocket is optional for Client. |
| 17 | + |
| 18 | + ``` |
| 19 | + val rSocket: Single<RSocket> = RSocketFactory // Requester RSocket |
| 20 | + .connect() |
| 21 | + .acceptor { -> handler() } // Optional responder RSocket |
| 22 | + .transport(OkhttpWebsocketClientTransport // WebSockets transport |
| 23 | + .create(protocol, host, port)) |
| 24 | + .start() |
| 25 | + |
| 26 | + private fun handler(): RSocket { |
| 27 | + return object : AbstractRSocket() { |
| 28 | + override fun fireAndForget(payload: Payload): Completable { |
| 29 | + return Completable.fromAction {Log.d("tag", "fire-n-forget from server")} |
| 30 | + } |
| 31 | + } |
| 32 | + } |
| 33 | + ``` |
| 34 | + Messages for all 4 interactions are represented as `Payload` of binary (nio `ByteBuffer`) data |
| 35 | + and metadata (to/from UTF8-string utility methods are available) |
| 36 | + |
| 37 | + Request-stream |
| 38 | + ``` |
| 39 | + rSocket.flatMapPublisher { |
| 40 | + it.requestStream(PayloadImpl("req-stream ping")) |
| 41 | + }.subscribe { responsePayload -> Log.d("request-stream", responsePayload.getDataUtf8)} |
| 42 | + ``` |
6 | 43 |
|
7 |
| - Done so far (to make runnable POC) |
| 44 | + Request-channel |
| 45 | + ``` |
| 46 | + rSocket.flatMapPublisher { |
| 47 | + it.requestChannel(Flowable.just( |
| 48 | + PayloadImpl("req-channel1"), |
| 49 | + PayloadImpl("req-channel2"))) |
| 50 | + }.subscribe { responsePayload -> Log.d("request-stream", responsePayload.getDataUtf8)} |
| 51 | + ``` |
| 52 | + ######Server |
| 53 | + Server accepts new `Connections` from peers. Same as `Client` it has `Requester` and `Responder` RSockets. |
| 54 | + As this project does not provide server implementation, use [RSocket-java](https://github.com/rsocket/rsocket-java) with `Netty` based `WebSockets` |
| 55 | + 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 |
8 | 56 |
|
9 |
| - * Get rid of all modules except rsocket-core |
10 |
| - * Convert sources to kotlin (intellij semi auto converter helped a lot) |
11 |
| - * Replace jre8 specific types with kotlin or custom counterparts |
12 |
| - * Replace reactor types with rxjava2 ones |
13 |
| - * Added throw-away OkHttp based Websockets transport |
14 |
| - * Sample server running rsocket-java, and [mobile app](https://github.com/mostroverkhov/rsocket-backport-demo) running rsocket-backport to verify supported interactions: |
15 |
| - req-reply, req-stream, fire-and-forget. req-channel is not ported for now as there is no obvious way to convert it |
16 |
| - to rxjava2 with minimal efforts |
17 |
| - |
18 |
| - TODO |
| 57 | + ##### Build and binaries |
19 | 58 |
|
20 |
| - * Implement req-channel |
21 |
| - * Resurrect tests |
22 |
| - * Come up with Websockets transport with capabilities similar to Netty one, and minimal dependencies |
23 |
| - * Introduce rpc system assuming jvm only environment - it should be approachable for regular developer to use/extend |
24 |
| - * at least minimal integration with Spring Boot |
| 59 | + The project is not released yet, so snapshots have to be installed locally with `./gradlew install` |
| 60 | + This will produce 2 artifacts: |
| 61 | + |
| 62 | +```groovy |
| 63 | + dependencies { |
| 64 | + compile 'io.rsocket:rsocket-android-core:0.9-SNAPSHOT' |
| 65 | + compile 'io.rsocket:rsocket-transport-okhttp:0.9-SNAPSHOT' |
| 66 | + } |
| 67 | +``` |
0 commit comments