Skip to content

Commit e767b72

Browse files
committed
Initial commit
0 parents  commit e767b72

File tree

27 files changed

+1347
-0
lines changed

27 files changed

+1347
-0
lines changed

.gitignore

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
### IntelliJ IDEA ###
2+
.idea
3+
!.idea/
4+
.idea/*
5+
!.idea/runConfigurations/
6+
*.iws
7+
*.iml
8+
*.ipr
9+
*.log*
10+
11+
target/
12+
13+
### STS ###
14+
.apt_generated
15+
.classpath
16+
.factorypath
17+
.project
18+
.settings
19+
.springBeans
20+
.sts4-cache
21+
22+
### NetBeans ###
23+
/nbproject/private/
24+
/nbbuild/
25+
/dist/
26+
/nbdist/
27+
/.nb-gradle/
28+
build/
29+
30+
### VS Code ###
31+
.vscode/

.idea/runConfigurations/GatewayApplication1.xml

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

.idea/runConfigurations/GatewayApplication2.xml

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

.idea/runConfigurations/PingApplication1.xml

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

.idea/runConfigurations/PingApplication2.xml

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

.idea/runConfigurations/PongApplication.xml

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

.java-version

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
11.0
+117
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
/*
2+
* Copyright 2007-present the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
import java.net.*;
17+
import java.io.*;
18+
import java.nio.channels.*;
19+
import java.util.Properties;
20+
21+
public class MavenWrapperDownloader {
22+
23+
private static final String WRAPPER_VERSION = "0.5.5";
24+
/**
25+
* Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided.
26+
*/
27+
private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/"
28+
+ WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar";
29+
30+
/**
31+
* Path to the maven-wrapper.properties file, which might contain a downloadUrl property to
32+
* use instead of the default one.
33+
*/
34+
private static final String MAVEN_WRAPPER_PROPERTIES_PATH =
35+
".mvn/wrapper/maven-wrapper.properties";
36+
37+
/**
38+
* Path where the maven-wrapper.jar will be saved to.
39+
*/
40+
private static final String MAVEN_WRAPPER_JAR_PATH =
41+
".mvn/wrapper/maven-wrapper.jar";
42+
43+
/**
44+
* Name of the property which should be used to override the default download url for the wrapper.
45+
*/
46+
private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl";
47+
48+
public static void main(String args[]) {
49+
System.out.println("- Downloader started");
50+
File baseDirectory = new File(args[0]);
51+
System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath());
52+
53+
// If the maven-wrapper.properties exists, read it and check if it contains a custom
54+
// wrapperUrl parameter.
55+
File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH);
56+
String url = DEFAULT_DOWNLOAD_URL;
57+
if(mavenWrapperPropertyFile.exists()) {
58+
FileInputStream mavenWrapperPropertyFileInputStream = null;
59+
try {
60+
mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile);
61+
Properties mavenWrapperProperties = new Properties();
62+
mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream);
63+
url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url);
64+
} catch (IOException e) {
65+
System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'");
66+
} finally {
67+
try {
68+
if(mavenWrapperPropertyFileInputStream != null) {
69+
mavenWrapperPropertyFileInputStream.close();
70+
}
71+
} catch (IOException e) {
72+
// Ignore ...
73+
}
74+
}
75+
}
76+
System.out.println("- Downloading from: " + url);
77+
78+
File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH);
79+
if(!outputFile.getParentFile().exists()) {
80+
if(!outputFile.getParentFile().mkdirs()) {
81+
System.out.println(
82+
"- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'");
83+
}
84+
}
85+
System.out.println("- Downloading to: " + outputFile.getAbsolutePath());
86+
try {
87+
downloadFileFromURL(url, outputFile);
88+
System.out.println("Done");
89+
System.exit(0);
90+
} catch (Throwable e) {
91+
System.out.println("- Error downloading");
92+
e.printStackTrace();
93+
System.exit(1);
94+
}
95+
}
96+
97+
private static void downloadFileFromURL(String urlString, File destination) throws Exception {
98+
if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) {
99+
String username = System.getenv("MVNW_USERNAME");
100+
char[] password = System.getenv("MVNW_PASSWORD").toCharArray();
101+
Authenticator.setDefault(new Authenticator() {
102+
@Override
103+
protected PasswordAuthentication getPasswordAuthentication() {
104+
return new PasswordAuthentication(username, password);
105+
}
106+
});
107+
}
108+
URL website = new URL(urlString);
109+
ReadableByteChannel rbc;
110+
rbc = Channels.newChannel(website.openStream());
111+
FileOutputStream fos = new FileOutputStream(destination);
112+
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
113+
fos.close();
114+
rbc.close();
115+
}
116+
117+
}

.mvn/wrapper/maven-wrapper.jar

49.5 KB
Binary file not shown.

.mvn/wrapper/maven-wrapper.properties

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip
2+
wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.5/maven-wrapper-0.5.5.jar

README.md

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# spring-cloud-gateway-rsocket example
2+
Polyglot RSocket clients communication via RSocket gateway cluster...
3+
4+
```
5+
+------+ +------+
6+
+~-*-~--~> | gw 2 | <~-~> | pong |
7+
| +------+ +------+
8+
Client V | Server
9+
+------+ +------+ +------+
10+
| ping | <~-~> | gw 1 | <~-~> | gw 3 |
11+
+------+ +------+ +------+
12+
```
13+
14+
* no service mesh
15+
* no sidecar
16+
* no circuit breaker
17+
18+
```bash
19+
./mvnw
20+
21+
SPRING_PROFILES_ACTIVE=gateway1 java -jar ./gateway/target/*.jar
22+
SPRING_PROFILES_ACTIVE=gateway2 java -jar ./gateway/target/*.jar
23+
24+
java -jar ./ping-pong/pong/target/*.jar
25+
java -jar ./ping-pong/ping/target/*.jar
26+
```
27+
28+
## Versions
29+
30+
* `spring-cloud` -> `Hoxton.RELEASE`
31+
* `spring-cloud-gateway-rsocket` -> `2.2.0.M2`
32+
* `spring-cloud-rsocket-broker` -> `0.2.0.BUILD-SNAPSHOT`
33+
* `spring-cloud-rsocket-client` -> `0.2.0.BUILD-SNAPSHOT`
34+
35+
## Resources
36+
37+
* https://www.infoq.com/presentations/rsocket-spring-cloud-gateway
38+
* https://github.com/spencergibb/rsocket-routing-sample

gateway/pom.xml

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<parent>
5+
<groupId>daggerok</groupId>
6+
<artifactId>spring-cloud-gateway-rsocket-example</artifactId>
7+
<version>1.0.0-SNAPSHOT</version>
8+
<relativePath>..</relativePath>
9+
</parent>
10+
11+
<modelVersion>4.0.0</modelVersion>
12+
<artifactId>gateway</artifactId>
13+
<packaging>jar</packaging>
14+
15+
<dependencies>
16+
<dependency>
17+
<groupId>org.springframework.cloud</groupId>
18+
<artifactId>spring-cloud-rsocket-broker</artifactId>
19+
</dependency>
20+
</dependencies>
21+
22+
<build>
23+
<plugins>
24+
<plugin>
25+
<groupId>org.springframework.boot</groupId>
26+
<artifactId>spring-boot-maven-plugin</artifactId>
27+
</plugin>
28+
</plugins>
29+
</build>
30+
31+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package daggerok.gateway;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
import reactor.core.publisher.Hooks;
6+
7+
@SpringBootApplication
8+
public class GatewayApplication {
9+
10+
public static void main(String[] args) {
11+
Hooks.onOperatorDebug();
12+
SpringApplication.run(GatewayApplication.class, args);
13+
}
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
spring:
2+
output:
3+
ansi:
4+
enabled: always
5+
application:
6+
name: gateway
7+
logging:
8+
level:
9+
org.springframework.cloud.gateway.rsocket: DEBUG
10+
---
11+
spring:
12+
profiles: gateway1
13+
rsocket:
14+
server:
15+
port: 7001
16+
cloud:
17+
gateway:
18+
rsocket:
19+
id: ${spring.profiles}
20+
route-id: 111
21+
service-name: ${spring.application.name}
22+
brokers:
23+
- host: gateway2-127-0-0-1.nip.io
24+
port: 7002
25+
- host: gateway3-127-0-0-1.nip.io
26+
port: 7003
27+
---
28+
spring:
29+
profiles: >
30+
gateway2
31+
rsocket:
32+
server:
33+
port: 7002
34+
cloud:
35+
gateway:
36+
rsocket:
37+
id: ${spring.profiles}
38+
route-id: 222
39+
service-name: ${spring.application.name}
40+
brokers:
41+
- host: gateway1-127-0-0-1.nip.io
42+
port: 7001
43+
- host: gateway3-127-0-0-1.nip.io
44+
#host: 127.0.0.1
45+
port: 7003
46+
#---
47+
#spring:
48+
# profiles:
49+
# - gateway3
50+
# rsocket:
51+
# server:
52+
# port: 7003
53+
# cloud:
54+
# gateway:
55+
# rsocket:
56+
# id: ${spring.profiles}
57+
# route-id: 333
58+
# service-name: ${spring.application.name}
59+
# brokers:
60+
# - host: gateway1-127-0-0-1.nip.io
61+
# port: 7001
62+
# - host: gateway2-127-0-0-1.nip.io
63+
# port: 7002
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package daggerok.gateway;
2+
3+
import org.junit.jupiter.api.Test;
4+
import org.springframework.boot.test.context.SpringBootTest;
5+
6+
@SpringBootTest
7+
class GatewayApplicationTests {
8+
9+
@Test
10+
void contextLoads() { }
11+
}

0 commit comments

Comments
 (0)