Skip to content

Commit f5c1b64

Browse files
committed
Implement all the things...
1 parent b3f6b8a commit f5c1b64

File tree

12 files changed

+386
-85
lines changed

12 files changed

+386
-85
lines changed

.github/workflows/ci.yml

+55-53
Original file line numberDiff line numberDiff line change
@@ -39,63 +39,65 @@ jobs:
3939
shell: bash
4040
run: |
4141
java -Dfile.encoding="UTF-8" -jar $GITHUB_WORKSPACE/server/build/libs/*.jar &
42-
java -Dfile.encoding="UTF-8" -jar $GITHUB_WORKSPACE/client/build/libs/*.jar &
43-
echo wait-port 7070 8080
42+
echo wait-port 7070...
43+
sleep 5s
44+
java -Dfile.encoding="UTF-8" -jar $GITHUB_WORKSPACE/client/build/libs/*.jar
4445
- name: Cache gradle
4546
uses: actions/cache@v1
4647
with:
4748
path: ~/.gradle
4849
key: ${{ matrix.gradle-version }}-${{ matrix.os }}-gradle-cache
4950
restore-keys: |
5051
${{ matrix.gradle-version }}-${{ matrix.os }}-gradle-cache-
51-
windows:
52-
strategy:
53-
matrix:
54-
java: [11]
55-
nodejs-version: [12]
56-
python-version: [3.8]
57-
gradle-version: [6.2]
58-
maven-version: [3.6.3]
59-
os: [windows-latest]
60-
runs-on: ${{ matrix.os }}
61-
name: Java ${{ matrix.java }} on ${{ matrix.os }}
62-
steps:
63-
- name: Set up NodeJS ${{ matrix.nodejs-version }}
64-
uses: actions/setup-node@v1
65-
with:
66-
node-version: ${{ matrix.nodejs-version }}
67-
- name: Install required npm packages globally
68-
run: npm install -g wait-port
69-
- name: Cache npm
70-
uses: actions/cache@v1
71-
with:
72-
path: ~/.npm
73-
key: java-${{ matrix.java }}-${{ runner.os }}-${{ matrix.os }}-npm-
74-
restore-keys: |
75-
java-${{ matrix.java }}-${{ runner.os }}-${{ matrix.os }}-npm-
76-
- name: Git clone
77-
uses: actions/checkout@v1
78-
- name: Setup java
79-
uses: actions/setup-java@v1
80-
with:
81-
java-version: ${{ matrix.java }}
82-
- name: Build windows gradle apps
83-
shell: cmd
84-
run: |
85-
@chcp 65001>nul
86-
gradlew -p server
87-
gradlew -p client
88-
- name: Test windows gradle apps
89-
shell: cmd
90-
run: |
91-
@chcp 65001>nul
92-
start /b "" java -Dfile.encoding="UTF-8" -jar %GITHUB_WORKSPACE%\server\build\libs\server-1.0.0-SNAPSHOT.jar
93-
start /b "" java -Dfile.encoding="UTF-8" -jar %GITHUB_WORKSPACE%\client\build\libs\client-1.0.0-SNAPSHOT.jar
94-
echo wait-port 7070 8080
95-
- name: Cache gradle
96-
uses: actions/cache@v1
97-
with:
98-
path: ~/.gradle
99-
key: java-${{ matrix.java }}-${{ runner.os }}-${{ matrix.os }}-gradle-${{ hashFiles('**/.gradle/**') }}
100-
restore-keys: |
101-
java-${{ matrix.java }}-${{ runner.os }}-${{ matrix.os }}-gradle-
52+
## FIXME after: https://github.com/rsocket/rsocket-rpc-java/issues/58
53+
# windows:
54+
# strategy:
55+
# matrix:
56+
# java: [11]
57+
# nodejs-version: [12]
58+
# python-version: [3.8]
59+
# gradle-version: [6.2]
60+
# maven-version: [3.6.3]
61+
# os: [windows-latest]
62+
# runs-on: ${{ matrix.os }}
63+
# name: Java ${{ matrix.java }} on ${{ matrix.os }}
64+
# steps:
65+
# - name: Set up NodeJS ${{ matrix.nodejs-version }}
66+
# uses: actions/setup-node@v1
67+
# with:
68+
# node-version: ${{ matrix.nodejs-version }}
69+
# - name: Install required npm packages globally
70+
# run: npm install -g wait-port
71+
# - name: Cache npm
72+
# uses: actions/cache@v1
73+
# with:
74+
# path: ~/.npm
75+
# key: java-${{ matrix.java }}-${{ runner.os }}-${{ matrix.os }}-npm-
76+
# restore-keys: |
77+
# java-${{ matrix.java }}-${{ runner.os }}-${{ matrix.os }}-npm-
78+
# - name: Git clone
79+
# uses: actions/checkout@v1
80+
# - name: Setup java
81+
# uses: actions/setup-java@v1
82+
# with:
83+
# java-version: ${{ matrix.java }}
84+
# - name: Build windows gradle apps
85+
# shell: cmd
86+
# run: |
87+
# @chcp 65001>nul
88+
# gradlew -p server
89+
# gradlew -p client
90+
# - name: Test windows gradle apps
91+
# shell: cmd
92+
# run: |
93+
# @chcp 65001>nul
94+
# start /b "" java -Dfile.encoding="UTF-8" -jar %GITHUB_WORKSPACE%\server\build\libs\server-1.0.0-SNAPSHOT.jar
95+
# wait-port 7070
96+
# java -Dfile.encoding="UTF-8" -jar %GITHUB_WORKSPACE%\client\build\libs\client-1.0.0-SNAPSHOT.jar
97+
# - name: Cache gradle
98+
# uses: actions/cache@v1
99+
# with:
100+
# path: ~/.gradle
101+
# key: java-${{ matrix.java }}-${{ runner.os }}-${{ matrix.os }}-gradle-${{ hashFiles('**/.gradle/**') }}
102+
# restore-keys: |
103+
# java-${{ matrix.java }}-${{ runner.os }}-${{ matrix.os }}-gradle-

.idea/runConfigurations/ClientApplication.xml

+1-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/runConfigurations/ServerApplication.xml

+1-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

+10
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,22 @@
22
TODO: implement me...
33

44
```bash
5+
./gradlew -p server genProto
6+
./gradlew -p client generateProto
7+
58
./gradlew -p server
69
./gradlew -p client
10+
11+
java -jar server/build/libs/*.jar &
12+
npx wait-port 7070
13+
java -jar client/build/libs/*.jar
714
```
815

916
## resources
1017

18+
* https://github.com/netifi/rsocket-rpc-example/tree/master/service
19+
* https://github.com/netifi/rsocket-rpc-example/tree/master/client/src/main/java/io/netifi/rsocket/example/client
20+
* https://github.com/b3rnoulli/rsocket-examples/tree/d1d6e4c4c0d280cf931cce4adcf0b56ffa2e88ed
1121
* https://dzone.com/articles/reactive-service-to-service-communication-with-rso-3
1222
* [Official Gradle documentation](https://docs.gradle.org)
1323
* [Spring Boot Gradle Plugin Reference Guide](https://docs.spring.io/spring-boot/docs/2.2.4.RELEASE/gradle-plugin/reference/html/)

client/build.gradle

+50-7
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
plugins {
2-
id 'org.springframework.boot' version '2.2.4.RELEASE'
32
id 'io.spring.dependency-management' version '1.0.9.RELEASE'
3+
id 'org.springframework.boot' version '2.2.4.RELEASE'
4+
id 'com.google.protobuf' version '0.8.10'
45
id 'java'
56
id 'idea'
67
}
78

8-
group = 'com.example'
9-
version = '0.0.1-SNAPSHOT'
10-
// sourceCompatibility = '1.8'
11-
sourceCompatibility = (org.gradle.internal.jvm.Jvm.current().javaVersion ?: JavaVersion.VERSION_1_8).ordinal() > JavaVersion.VERSION_1_8.ordinal()
12-
? JavaVersion.VERSION_11.toString() : JavaVersion.VERSION_1_8.toString()
9+
// sourceCompatibility = (org.gradle.internal.jvm.Jvm.current().javaVersion ?: JavaVersion.VERSION_1_8).ordinal() > JavaVersion.VERSION_1_8.ordinal()
10+
// ? JavaVersion.VERSION_11.toString() : JavaVersion.VERSION_1_8.toString()
11+
sourceCompatibility = '1.8'
1312

1413
configurations {
1514
compileOnly {
@@ -22,6 +21,16 @@ repositories {
2221
}
2322

2423
dependencies {
24+
// implementation 'io.netty:netty-tcnative:2.0.6.Final' // not necessary
25+
// org.apache.tools.ant.taskdefs.condition.Os.with {
26+
// if (it.isFamily(it.FAMILY_MAC)) {
27+
// implementation 'io.rsocket:rsocket-transport-netty:0.11.16'
28+
// }
29+
// }
30+
protobuf "com.google.protobuf:protobuf-java:${project.protobufVersion}"
31+
implementation "com.google.protobuf:protobuf-java:${project.protobufVersion}"
32+
// protobuf 'com.google.protobuf:protobuf-java:3.10.0'
33+
implementation "io.rsocket.rpc:rsocket-rpc-core:${project.rSocketProtobufVersion}"
2534
implementation 'org.springframework.boot:spring-boot-starter-rsocket'
2635
compileOnly 'org.projectlombok:lombok'
2736
annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor'
@@ -56,5 +65,39 @@ bootJar {
5665
defaultTasks("clean", "build")
5766

5867
wrapper {
59-
gradleVersion = '6.2'
68+
gradleVersion = project.gradleWrapperVersion
69+
}
70+
71+
protobuf {
72+
protoc {
73+
artifact = "com.google.protobuf:protoc:${project.protobufVersion}"
74+
}
75+
plugins {
76+
rsocketRpc {
77+
artifact = "io.rsocket.rpc:rsocket-rpc-protobuf:${project.rSocketProtobufVersion}"
78+
}
79+
}
80+
generateProtoTasks {
81+
all()*.plugins {
82+
rsocketRpc {}
83+
}
84+
}
85+
}
86+
87+
// If you use Intellij add this so it can find the generated classes
88+
idea {
89+
module {
90+
sourceDirs += file("src/main/proto")
91+
sourceDirs += file("src/generated/main/java")
92+
sourceDirs += file("src/generated/main/rsocketRpc")
93+
94+
generatedSourceDirs += file('src/generated/main/java')
95+
generatedSourceDirs += file('src/generated/main/rsocketRpc')
96+
}
97+
}
98+
99+
clean {
100+
delete 'src/generated/main'
101+
delete 'build'
102+
delete 'out'
60103
}

client/gradle.properties

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
name = client
2+
group = com.example
3+
version = 0.0.1-SNAPSHOT
4+
protobufVersion = 3.6.1
5+
gradleWrapperVersion = 6.2
6+
rSocketProtobufVersion = 0.2.10
7+
#rSocketProtobufVersion = 0.2.19
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,55 @@
11
package com.example.client;
22

3+
import io.rsocket.RSocket;
4+
import io.rsocket.RSocketFactory;
5+
import io.rsocket.rpc.testing.protobuf.SimpleRequest;
6+
import io.rsocket.rpc.testing.protobuf.SimpleResponse;
7+
import io.rsocket.rpc.testing.protobuf.SimpleServiceClient;
8+
import io.rsocket.transport.netty.client.TcpClientTransport;
9+
import lombok.extern.log4j.Log4j2;
310
import org.springframework.boot.SpringApplication;
411
import org.springframework.boot.autoconfigure.SpringBootApplication;
12+
import reactor.core.publisher.Flux;
13+
import reactor.core.publisher.Mono;
514

15+
import java.util.concurrent.TimeUnit;
16+
17+
@Log4j2
618
@SpringBootApplication
719
public class ClientApplication {
820

921
public static void main(String[] args) {
10-
SpringApplication.run(ClientApplication.class, args);
11-
}
1222

23+
RSocket rSocket = RSocketFactory.connect()
24+
.transport(TcpClientTransport.create(7070))
25+
.start()
26+
.block();
27+
28+
SimpleServiceClient client = new SimpleServiceClient(rSocket);
29+
30+
Flux<SimpleRequest> requests =
31+
Flux.range(1, 11)
32+
.map(i -> "sending -> " + i)
33+
.map(s -> SimpleRequest.newBuilder()
34+
.setRequestMessage(s)
35+
.build());
36+
37+
Mono<SimpleResponse> response = client.streamingRequestSingleResponse(requests);
38+
Mono<String> message = response.map(SimpleResponse::getResponseMessage);
39+
message.doOnSubscribe(subscription -> log.info("subscribing..."))
40+
.doOnEach(each -> log.info("on each: {}", each))
41+
.doOnNext(next -> log.info("next: {}", next))
42+
.doOnCancel(() -> log.info("cancel..."))
43+
.subscribe(log::info);
44+
45+
try {
46+
TimeUnit.SECONDS.sleep(1);
47+
} catch (InterruptedException e) {
48+
log.error("oops... {}", e.getLocalizedMessage(), e);
49+
}
50+
51+
log.info("Done.");
52+
53+
// SpringApplication.run(ClientApplication.class, args);
54+
}
1355
}

client/src/main/proto/api.proto

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
syntax = "proto3";
2+
3+
package io.rsocket.rpc.testing;
4+
5+
import "google/protobuf/empty.proto";
6+
7+
option java_package = "io.rsocket.rpc.testing.protobuf";
8+
option java_outer_classname = "SimpleServiceProto";
9+
option java_multiple_files = true;
10+
11+
service SimpleService {
12+
// Request / Response
13+
rpc RequestReply (SimpleRequest) returns (SimpleResponse) {}
14+
15+
// Fire-and-Forget
16+
rpc FireAndForget (SimpleRequest) returns (google.protobuf.Empty) {}
17+
18+
// Single Request / Streaming Response
19+
rpc RequestStream (SimpleRequest) returns (stream SimpleResponse) {}
20+
21+
// Streaming Request / Single Response
22+
rpc StreamingRequestSingleResponse (stream SimpleRequest) returns (SimpleResponse) {}
23+
24+
// Streaming Request / Streaming Response
25+
rpc StreamingRequestAndResponse (stream SimpleRequest) returns (stream SimpleResponse) {}
26+
}
27+
28+
message SimpleRequest {
29+
string requestMessage = 1;
30+
}
31+
32+
message SimpleResponse {
33+
string responseMessage = 1;
34+
}

0 commit comments

Comments
 (0)