Skip to content

Commit 31393bb

Browse files
committed
Add README files with the instructions
1 parent 56be328 commit 31393bb

File tree

15 files changed

+425
-2
lines changed

15 files changed

+425
-2
lines changed

Diff for: .gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ javadoc/
4040
build/
4141
lib/
4242

43+
*.idea/
44+
*.iml
4345

4446
*.pbxuser
4547
!default.pbxuser

Diff for: README.md

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Reactive Microservices in Java
2+
3+
This repository contains the source code from the _Reactive Microsevices in Java - Asynchronous, Elastic, Resilience Applications_ book. It contains the source code shown in the book as well as other examples.
4+
5+
6+
The repository is structured as follows:
7+
8+
9+
* [Hello Vert.x - the Vert.x Hello World](hello-vertx)
10+
* [Packaging Examples - build Vert.x application using any tool](packaging-examples)
11+
* [Reactive Programming (RX Java 1) examples](reactive-programming)
12+
* [Microservices - the different microservices built in the book](microservices)
13+
* [OpenShift - the microservices built in the book running on top of OpenShift](openshift)
14+
15+
16+
Each directory contains the instructions to build and run the _module_.

Diff for: microservices/README.md

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Microservices
2+
3+
This directory contains the different microservices developed in the book. In order of appearance:
4+
5+
* [Hello Microservice - HTTP](hello-microservice-http)
6+
* [Hello Consumer Microservice - HTTP](hello-consumer-microservice-http)
7+
* [Hello Microservice - Event Bus](hello-microservice-message)
8+
* [Hello Consumer Microservice - Event Bus](hello-consumer-microservice-message)
9+
* [Hello Microservice with faults](hello-microservice-faulty)
10+
* [Hello Consumer Microservice with timeout and reply](hello-consumer-microservice-timeout)
11+
12+
The _-consumer_ projects invoke the corresponding services:
13+
14+
* The [Hello Consumer Microservice - HTTP](hello-consumer-microservice-http) invokes the [Hello Microservice - HTTP](hello-microservice-http).
15+
* The [Hello Consumer Microservice - Event Bus](hello-consumer-microservice-message) invokes the [Hello Microservice - Event Bus](hello-microservice-message).
16+
* The [Hello Consumer Microservice with timeout and reply](hello-consumer-microservice-timeout) invokes the [Hello Microservice with faults](hello-microservice-faulty).
17+
18+
Be aware to run both at the same time.
19+
20+
Each project is built with Apache Maven:
21+
22+
```
23+
cd $DIRECTORY
24+
mvn clean package
25+
```
26+
27+
Each project contains a `README` with running instructions.
+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Hello Consumer Microservice - HTTP
2+
3+
This directory contains the source code of the _Hello_ microservice consumer using HTTP interactions. It invokes the [Hello microservice - HTTP](../hello-microservice-http).
4+
5+
## Running in development mode
6+
7+
8+
```
9+
mvn compile vertx:run
10+
```
11+
12+
Hit `CTRL+C` to stop the execution and reloading.
13+
14+
15+
## Packaging
16+
17+
```
18+
mvn clean package
19+
```
20+
21+
## Execution using the application package
22+
23+
```
24+
java -jar target/hello-consumer-microservice-http-1.0-SNAPSHOT.jar
25+
```
26+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Hello Consumer Microservice - Event Bus
2+
3+
This directory contains the source code of the _Hello_ microservice consumer using event bus (message) interactions. It invokes the [Hello microservice - Event Bus](../hello-microservice-message).
4+
5+
## Running in development mode
6+
7+
```
8+
mvn compile vertx:run -Dvertx.runArgs="-cluster -Djava.net.preferIPv4Stack=true"
9+
```
10+
11+
Hit `CTRL+C` to stop the execution and reloading.
12+
13+
14+
## Packaging
15+
16+
```
17+
mvn clean package
18+
```
19+
20+
## Execution using the application package
21+
22+
```
23+
java -jar target/hello-consumer-microservice-message-1.0-SNAPSHOT.jar -cluster -Djava.net.preferIPv4Stack=true
24+
```
25+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Hello Consumer Microservice - Event Bus with timeout and reply
2+
3+
This directory contains the source code of the _Hello_ microservice consumer using event bus (message) interactions. It implements a simple fault-tolerance strategy using timeouts and retries. It invokes the [Hello microservice - Event Bus - Faulty](../hello-microservice-faulty).
4+
5+
## Running in development mode
6+
7+
```
8+
mvn compile vertx:run -Dvertx.runArgs="-cluster -Djava.net.preferIPv4Stack=true"
9+
```
10+
11+
Hit `CTRL+C` to stop the execution and reloading.
12+
13+
14+
## Packaging
15+
16+
```
17+
mvn clean package
18+
```
19+
20+
## Execution using the application package
21+
22+
```
23+
java -jar target/hello-consumer-microservice-message-1.0-SNAPSHOT.jar -cluster -Djava.net.preferIPv4Stack=true
24+
```
25+

Diff for: microservices/hello-consumer-microservice-timeout/src/main/java/io/vertx/book/message/HelloConsumerMicroservice.java

+8-2
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,19 @@ public void start() {
1919
<JsonObject>rxSend("hello", "Luke")
2020
.subscribeOn(RxHelper.scheduler(vertx))
2121
.timeout(3, TimeUnit.SECONDS)
22-
.retry()
22+
.retry((i, t) -> {
23+
System.out.println("Retrying... because of " + t.getMessage());
24+
return true;
25+
})
2326
.map(Message::body);
2427
Single<JsonObject> obs2 = vertx.eventBus().
2528
<JsonObject>rxSend("hello", "Leia")
2629
.subscribeOn(RxHelper.scheduler(vertx))
2730
.timeout(3, TimeUnit.SECONDS)
28-
.retry()
31+
.retry((i, t) -> {
32+
System.out.println("Retrying... because of " + t.getMessage());
33+
return true;
34+
})
2935
.map(Message::body);
3036

3137
Single

Diff for: microservices/hello-microservice-faulty/README.md

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Hello Microservice - Event Bus with faults
2+
3+
This directory contains the source code of the _Hello_ microservice using event bus (message) interactions with with injected fault (on purpose).
4+
5+
## Running in development mode
6+
7+
```
8+
mvn compile vertx:run -Dvertx.runArgs="-cluster -Djava.net.preferIPv4Stack=true"
9+
```
10+
11+
Hit `CTRL+C` to stop the execution and reloading.
12+
13+
14+
## Packaging
15+
16+
```
17+
mvn clean package
18+
```
19+
20+
## Execution using the application package
21+
22+
```
23+
java -jar target/hello-microservice-message-1.0-SNAPSHOT.jar -cluster -Djava.net.preferIPv4Stack=true
24+
```
25+

Diff for: microservices/hello-microservice-http/README.md

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Hello Microservice - HTTP
2+
3+
This directory contains the source code of the _Hello_ microservice using HTTP interactions.
4+
5+
## Running in development mode
6+
7+
8+
```
9+
mvn compile vertx:run
10+
```
11+
12+
Hit `CTRL+C` to stop the execution and reloading.
13+
14+
15+
## Packaging
16+
17+
```
18+
mvn clean package
19+
```
20+
21+
## Execution using the application package
22+
23+
```
24+
java -jar target/hello-microservice-http-1.0-SNAPSHOT.jar
25+
```
26+

Diff for: microservices/hello-microservice-message/README.md

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Hello Microservice - Event Bus
2+
3+
This directory contains the source code of the _Hello_ microservice using event bus (message) interactions.
4+
5+
## Running in development mode
6+
7+
```
8+
mvn compile vertx:run -Dvertx.runArgs="-cluster -Djava.net.preferIPv4Stack=true"
9+
```
10+
11+
Hit `CTRL+C` to stop the execution and reloading.
12+
13+
14+
## Packaging
15+
16+
```
17+
mvn clean package
18+
```
19+
20+
## Execution using the application package
21+
22+
```
23+
java -jar target/hello-microservice-message-1.0-SNAPSHOT.jar -cluster -Djava.net.preferIPv4Stack=true
24+
```
25+

Diff for: openshift/README.md

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Microservices on OpenShift
2+
3+
This directory contains the different microservices running on top of OpenShift developed in the book. In order of appearance:
4+
5+
* [Hello Microservice](hello-microservice-openshift)
6+
* [Hello Consumer Microservice](hello-microservice-consumer-openshift)
7+
* [Hello Microservice with Health Check](hello-microservice-openshift-health-checks)
8+
* [Hello Consumer Microservice with Circuit Breaker](hello-microservice-consumer-openshift-circuit-breaker)
9+
10+
Each project is built with Apache Maven:
11+
12+
```
13+
cd $DIRECTORY
14+
mvn clean package
15+
```
16+
17+
Each project contains a `README` with running instructions.
18+
19+
20+
You need access to an OpenShift v3.x instance to run them. Either use [OpenShift Online](https://www.openshift.com/devpreview/) of []MiniShift](https://github.com/minishift/minishift).
21+
22+
Once running, login using the `oc` command line. For MiniShift, use:
23+
24+
```
25+
oc login https://192.168.64.12:8443 -u developer -p developer
26+
```
27+
28+
Also, create a new project:
29+
30+
```
31+
oc new-project reactive-microservices
32+
oc policy add-role-to-user admin developer -n reactive-microservices
33+
oc policy add-role-to-user view -n reactive-microservices -z default
34+
```
35+
36+
NOTE: on OpenShift Online you may not be able to create a new project (as you have a limited number of projects). In this context, run:
37+
38+
```
39+
oc project -q # Print the name of the current project
40+
oc policy add-role-to-user admin developer -n $PROJECT_NAME
41+
oc policy add-role-to-user view -n $PROJECT_NAME -z default
42+
```
43+
44+
Replace `$PROJECT_NAME` by the name printed by the first command.
45+
46+
Then, open the OpenShift console:
47+
48+
* OpenShift Online - https://console.preview.openshift.com/console/
49+
* MiniShift - https://192.168.64.12:8443/console/ (`developer/developer`)
50+
51+
52+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Hello Microservice Consumer with circuit breaker - OpenShift
2+
3+
This directory contains the source code of the _Hello_ consumer microservice with a cricuit breaker protecting the calls to the _Hello_ microservice. It updates the [Hello consumer microservice](../hello-microservice-consumer-openshift). It requires the deployment of the [Hello microservice](../hello-microservice-openshift) (or the version [with health checks](../hello-microservice-openshift-health-checks)).
4+
5+
## Deployment
6+
7+
```
8+
mvn fabric8:deploy -Popenshift
9+
```
10+
11+
## Accessing the service
12+
13+
Open the route url from the OpenShift dashboard. Alternatively, you can retrieve the route url as follows:
14+
15+
```
16+
$ oc describe routes hello-consumer
17+
Name: hello-consumer
18+
Namespace: reactive-microservices
19+
Created: About a minute ago
20+
Labels: group=io.vertx.book
21+
project=hello-consumer
22+
provider=fabric8
23+
version=1.0-SNAPSHOT
24+
Annotations: openshift.io/host.generated=true
25+
Requested Host: hello-consumer-reactive-microservices.192.168.64.12.xip.io
26+
exposed on router router about a minute ago
27+
Path: <none>
28+
TLS Termination: <none>
29+
Insecure Policy: <none>
30+
Endpoint Port: http
31+
32+
Service: hello-consumer
33+
Weight: 100 (100%)
34+
Endpoints: 172.17.0.10:8080
35+
$ curl hello-consumer-reactive-microservices.192.168.64.12.xip.io
36+
```
37+
38+
Or:
39+
40+
```
41+
oc describe routes hello-consumer | grep "Requested" | awk '{$1=""; print $3}'
42+
```
+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Hello Microservice Consumer - OpenShift
2+
3+
This directory contains the source code of the _Hello_ consumer microservice running on top of OpenShift. It requires the deployment of the [Hello Microservice](../hello-microservice-openshift).
4+
5+
## Deployment
6+
7+
```
8+
mvn fabric8:deploy -Popenshift
9+
```
10+
11+
## Accessing the service
12+
13+
Open the route url from the OpenShift dashboard. Alternatively, you can retrieve the route url as follows:
14+
15+
```
16+
$ oc describe routes hello-consumer
17+
Name: hello-consumer
18+
Namespace: reactive-microservices
19+
Created: About a minute ago
20+
Labels: group=io.vertx.book
21+
project=hello-consumer
22+
provider=fabric8
23+
version=1.0-SNAPSHOT
24+
Annotations: openshift.io/host.generated=true
25+
Requested Host: hello-consumer-reactive-microservices.192.168.64.12.xip.io
26+
exposed on router router about a minute ago
27+
Path: <none>
28+
TLS Termination: <none>
29+
Insecure Policy: <none>
30+
Endpoint Port: http
31+
32+
Service: hello-consumer
33+
Weight: 100 (100%)
34+
Endpoints: 172.17.0.10:8080
35+
$ curl hello-consumer-reactive-microservices.192.168.64.12.xip.io
36+
```
37+
38+
Or:
39+
40+
```
41+
oc describe routes hello-consumer | grep "Requested" | awk '{$1=""; print $3}'
42+
```

0 commit comments

Comments
 (0)