Skip to content

Commit 5ac72cc

Browse files
committed
chore: added microprofile-liberty-redis-cluster sample
Signed-off-by: Maximillian Arruda <[email protected]>
1 parent 8a8680a commit 5ac72cc

20 files changed

+1156
-0
lines changed

README.adoc

+3
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ Open Liberty is a lightweight and highly flexible open-source application server
3535
| Simple CRUD REST application
3636
| Redis - Sentinel
3737

38+
| link:microprofile-liberty-redis-cluster/[]
39+
| Simple CRUD REST application
40+
| Redis - Cluster
3841

3942
|===
4043

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
target/
2+
!target/*.war
3+
!target/liberty/wlp/usr/shared/resources/*
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
target/
2+
pom.xml.tag
3+
pom.xml.releaseBackup
4+
pom.xml.versionsBackup
5+
pom.xml.next
6+
release.properties
7+
dependency-reduced-pom.xml
8+
buildNumber.properties
9+
.mvn/timing.properties
10+
# https://github.com/takari/maven-wrapper#usage-without-binary-jar
11+
.mvn/wrapper/maven-wrapper.jar
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.9.1/apache-maven-3.9.1-bin.zip
2+
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
FROM icr.io/appcafe/open-liberty:kernel-slim-java21-openj9-ubi-minimal
3+
4+
COPY --chown=1001:0 /src/main/liberty/config /config
5+
6+
RUN features.sh
7+
8+
COPY --chown=1001:0 target/*.war /config/apps
9+
10+
RUN configure.sh
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
= MicroProfile Open Liberty with Redis sample
2+
3+
This project is intent to be a sample for MicroProfile with MongoDB integration by using Jakarta NoSQL implementation.
4+
5+
== Setup Redis
6+
7+
image::https://jnosql.github.io/img/logos/redis.png[Redis Project,align="center" width=25%,height=25%]
8+
9+
https://redis.com/[Redis] is a software project that implements data structure servers.
10+
It is open-source, networked, in-memory, and stores keys with optional durability.
11+
12+
The project is configured to reach out a Redis instance with the following configuration:
13+
14+
[source, text]
15+
----
16+
host: localhost
17+
port: 6379
18+
----
19+
20+
This Eclipse JNoSQL configuration is defined on the file `src/main/resources/META-INF/microprofile-config.properties`. More info about it, check the following link: https://github.com/eclipse/jnosql-databases?tab=readme-ov-file#configuration-14
21+
22+
[source,properties]
23+
----
24+
include::src/main/resources/META-INF/microprofile-config.properties[]
25+
----
26+
*PS:warning:* Pay attention to that when you try to set up your own Redis instance.
27+
28+
== Using Docker Compose
29+
30+
The easier way to execute this project is to use the provided docker-compose.yaml file in the root directory.
31+
You can run it by performing the following command:
32+
33+
[source, bash]
34+
----
35+
docker-compose up -d
36+
----
37+
38+
== Local installation
39+
40+
Follow the instructions in: https://redis.io/docs/latest/operate/oss_and_stack/install/install-redis/
41+
42+
== Using Docker
43+
44+
1. Install docker: https://www.docker.com/
45+
2. https://hub.docker.com/_/redis
46+
3. Run docker command
47+
48+
[source, bash]
49+
----
50+
docker run -d --name redis-instance -p 6379:6379 redis
51+
----
52+
53+
== Run the code
54+
55+
The generation of the executable jar file can be performed by issuing the following command
56+
[source, bash]
57+
----
58+
mvn clean package
59+
----
60+
61+
This will create an executable jar file **microprofile-liberty-redis.jar** within the _target_ maven folder. This can be started by executing the following command
62+
63+
[source, bash]
64+
----
65+
java -jar target/microprofile-liberty-redis.jar
66+
----
67+
68+
=== Liberty Dev Mode
69+
70+
During development, you can use Liberty's development mode (dev mode) to code while observing and testing your changes on the fly.
71+
With the dev mode, you can code along and watch the change reflected in the running server right away;
72+
unit and integration tests are run on pressing Enter in the command terminal; you can attach a debugger to the running server at any time to step through your code.
73+
74+
[source, bash]
75+
----
76+
mvn liberty:dev
77+
----
78+
79+
80+
81+
82+
To launch the test page, open your browser at the following URL
83+
84+
[source, text]
85+
----
86+
http://localhost:9080/index.html
87+
----
88+
89+
90+
=== Specification examples
91+
92+
By default, there is always the creation of a JAX-RS application class to define the path on which the JAX-RS endpoints are available.
93+
94+
Also, a simple Hello world endpoint is created, have a look at the class **HelloController**.
95+
96+
More information on MicroProfile can be found [here](https://microprofile.io/)
97+
98+
99+
=== Config
100+
101+
Configuration of your application parameters. Specification [here](https://microprofile.io/project/eclipse/microprofile-config)
102+
103+
The example class **ConfigTestController** shows you how to inject a configuration parameter and how you can retrieve it programmatically.
104+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
After you generate a starter project, these instructions will help you with what to do next.
2+
3+
The Open Liberty starter gives you a simple, quick way to get the necessary files to start building
4+
an application on Open Liberty. There is no need to search how to find out what to add to your
5+
Maven build files. A simple RestApplication.java file is generated for you to start
6+
creating a REST based application. A server.xml configuration file is provided with the necessary
7+
features for the MicroProfile and Jakarta EE versions that you previously selected.
8+
9+
If you plan on developing and/or deploying your app in a containerized environment, the included
10+
Dockerfile will make it easier to create your application image on top of the Open Liberty Docker
11+
image.
12+
13+
1) Once you download the starter project, unpackage the .zip file on your machine.
14+
2) Open a command line session, navigate to the installation directory, and run `./mvnw liberty:dev` (Linux/Mac) or `mvnw liberty:dev` (Windows).
15+
This will install all required dependencies and start the default server. When complete, you will
16+
see the necessary features installed and the message "server is ready to run a smarter planet."
17+
18+
For information on developing your application in dev mode using Maven, see the
19+
dev mode documentation (https://openliberty.io/docs/latest/development-mode.html).
20+
21+
For further help on getting started actually developing your application, see some of our
22+
MicroProfile guides (https://openliberty.io/guides/?search=microprofile&key=tag) and Jakarta EE
23+
guides (https://openliberty.io/guides/?search=jakarta%20ee&key=tag).
24+
25+
If you have problems building the starter project, make sure the Java SE version on your
26+
machine matches the Java SE version you picked from the Open Liberty starter on the downloads
27+
page (https://openliberty.io/downloads/). You can test this with the command `java -version`.
28+
29+
Open Liberty performs at its best when running using Open J9 which can be obtained via IBM Semeru
30+
(https://developer.ibm.com/languages/java/semeru-runtimes/downloads/). For a full list of supported
31+
Java SE versions and where to obtain them, reference the Java SE support page
32+
(https://openliberty.io/docs/latest/java-se.html).
33+
34+
If you find any issues with the starter project or have recommendations to improve it, open an
35+
issue in the starter GitHub repo (https://github.com/OpenLiberty/start.openliberty.io).
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
version: '3'
2+
3+
services:
4+
redis-configurer:
5+
container_name: "redis-configurer"
6+
image: redis:6.0-alpine
7+
command: >
8+
sh -c 'echo yes | redis-cli -h 172.22.0.2 -p 6379 --cluster create \
9+
172.22.0.2:6379 172.22.0.3:6379 172.22.0.4:6379 \
10+
172.22.0.5:6379 172.22.0.6:6379 172.22.0.7:6379 \
11+
--cluster-replicas 1 && tail -f /dev/null'
12+
depends_on:
13+
- redis-1
14+
- redis-2
15+
- redis-3
16+
- redis-4
17+
- redis-5
18+
- redis-6
19+
networks:
20+
redis-net:
21+
ipv4_address: 172.22.0.10
22+
23+
redis-1:
24+
container_name: "redis-1"
25+
image: redis:6.0-alpine
26+
ports:
27+
- 7001:6379
28+
command: ["redis-server", "--cluster-enabled", "yes", "--cluster-config-file", "nodes.conf", "--cluster-node-timeout", "5000", "--appendonly", "yes"]
29+
depends_on:
30+
- redis-2
31+
- redis-3
32+
- redis-4
33+
- redis-5
34+
- redis-6
35+
networks:
36+
redis-net:
37+
ipv4_address: 172.22.0.2
38+
39+
redis-2:
40+
container_name: "redis-2"
41+
image: redis:6.0-alpine
42+
ports:
43+
- 7002:6379
44+
command: ["redis-server", "--cluster-enabled", "yes", "--cluster-config-file", "nodes.conf", "--cluster-node-timeout", "5000", "--appendonly", "yes"]
45+
networks:
46+
redis-net:
47+
ipv4_address: 172.22.0.3
48+
49+
redis-3:
50+
container_name: "redis-3"
51+
image: redis:6.0-alpine
52+
ports:
53+
- 7003:6379
54+
command: ["redis-server", "--cluster-enabled", "yes", "--cluster-config-file", "nodes.conf", "--cluster-node-timeout", "5000", "--appendonly", "yes"]
55+
networks:
56+
redis-net:
57+
ipv4_address: 172.22.0.4
58+
59+
redis-4:
60+
container_name: "redis-4"
61+
image: redis:6.0-alpine
62+
ports:
63+
- 7004:6379
64+
command: ["redis-server", "--cluster-enabled", "yes", "--cluster-config-file", "nodes.conf", "--cluster-node-timeout", "5000", "--appendonly", "yes"]
65+
networks:
66+
redis-net:
67+
ipv4_address: 172.22.0.5
68+
69+
redis-5:
70+
container_name: "redis-5"
71+
image: redis:6.0-alpine
72+
ports:
73+
- 7005:6379
74+
command: ["redis-server", "--cluster-enabled", "yes", "--cluster-config-file", "nodes.conf", "--cluster-node-timeout", "5000", "--appendonly", "yes"]
75+
networks:
76+
redis-net:
77+
ipv4_address: 172.22.0.6
78+
79+
redis-6:
80+
container_name: "redis-6"
81+
image: redis:6.0-alpine
82+
ports:
83+
- 7006:6379
84+
command: ["redis-server", "--cluster-enabled", "yes", "--cluster-config-file", "nodes.conf", "--cluster-node-timeout", "5000", "--appendonly", "yes"]
85+
86+
networks:
87+
redis-net:
88+
ipv4_address: 172.22.0.7
89+
90+
networks:
91+
redis-net:
92+
driver: bridge
93+
ipam:
94+
config:
95+
- subnet: 172.22.0.0/16

0 commit comments

Comments
 (0)