Skip to content

Commit

Permalink
Merge branch 'main' of github.com:JNOSQL/demo-ee
Browse files Browse the repository at this point in the history
  • Loading branch information
otaviojava committed Dec 1, 2024
2 parents 43435cd + 5793ef0 commit be3dfdf
Show file tree
Hide file tree
Showing 57 changed files with 3,337 additions and 2 deletions.
15 changes: 14 additions & 1 deletion README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,18 @@ Open Liberty is a lightweight and highly flexible open-source application server
|Simple CRUD REST application with *Jakarta Bean Validation* support
| MongoDB

| link:microprofile-liberty-redis-single-node/[]
| Simple CRUD REST application
| Redis - Single node

| link:microprofile-liberty-redis-sentinel/[]
| Simple CRUD REST application
| Redis - Sentinel

| link:microprofile-liberty-redis-cluster/[]
| Simple CRUD REST application
| Redis - Cluster

|===

== Wildfly
Expand Down Expand Up @@ -85,4 +97,5 @@ Apache TomEE is a lightweight, open-source Jakarta EE application server that is
| Simple CRUD REST application
| MongoDB

|===
|===

3 changes: 3 additions & 0 deletions microprofile-liberty-redis-cluster/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
target/
!target/*.war
!target/liberty/wlp/usr/shared/resources/*
11 changes: 11 additions & 0 deletions microprofile-liberty-redis-cluster/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
target/
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next
release.properties
dependency-reduced-pom.xml
buildNumber.properties
.mvn/timing.properties
# https://github.com/takari/maven-wrapper#usage-without-binary-jar
.mvn/wrapper/maven-wrapper.jar
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.1/apache-maven-3.9.1-bin.zip
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar
10 changes: 10 additions & 0 deletions microprofile-liberty-redis-cluster/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

FROM icr.io/appcafe/open-liberty:kernel-slim-java21-openj9-ubi-minimal

COPY --chown=1001:0 /src/main/liberty/config /config

RUN features.sh

COPY --chown=1001:0 target/*.war /config/apps

RUN configure.sh
81 changes: 81 additions & 0 deletions microprofile-liberty-redis-cluster/README.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
= MicroProfile Open Liberty with Redis Cluster sample

This project is intent to be a sample for MicroProfile with Redis Cluster integration by using Jakarta NoSQL implementation.

== Setup Redis

image::https://jnosql.github.io/img/logos/redis.png[Redis Project,align="center" width=25%,height=25%]

https://redis.com/[Redis] is a software project that implements data structure servers.
It is open-source, networked, in-memory, and stores keys with optional durability.

The project is configured to reach out the Redis Cluster with the following configuration 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

[source,properties]
----
include::src/main/resources/META-INF/microprofile-config.properties[]
----
*PS:warning:* Pay attention to that when you try to set up your own Redis instance.

== Using Docker Compose

The easier way to execute this project is to use the provided docker-compose.yaml file in the root directory.
You can run it by performing the following command:

[source, bash]
----
docker-compose up -d
----

== Run the code

The generation of the executable jar file can be performed by issuing the following command
[source, bash]
----
mvn clean package
----

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

[source, bash]
----
java -jar target/microprofile-liberty-redis.jar
----

=== Liberty Dev Mode

During development, you can use Liberty's development mode (dev mode) to code while observing and testing your changes on the fly.
With the dev mode, you can code along and watch the change reflected in the running server right away;
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.

[source, bash]
----
mvn liberty:dev
----




To launch the test page, open your browser at the following URL

[source, text]
----
http://localhost:9080/index.html
----


=== Specification examples

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.

Also, a simple Hello world endpoint is created, have a look at the class **HelloController**.

More information on MicroProfile can be found [here](https://microprofile.io/)


=== Config

Configuration of your application parameters. Specification [here](https://microprofile.io/project/eclipse/microprofile-config)

The example class **ConfigTestController** shows you how to inject a configuration parameter and how you can retrieve it programmatically.

35 changes: 35 additions & 0 deletions microprofile-liberty-redis-cluster/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
After you generate a starter project, these instructions will help you with what to do next.

The Open Liberty starter gives you a simple, quick way to get the necessary files to start building
an application on Open Liberty. There is no need to search how to find out what to add to your
Maven build files. A simple RestApplication.java file is generated for you to start
creating a REST based application. A server.xml configuration file is provided with the necessary
features for the MicroProfile and Jakarta EE versions that you previously selected.

If you plan on developing and/or deploying your app in a containerized environment, the included
Dockerfile will make it easier to create your application image on top of the Open Liberty Docker
image.

1) Once you download the starter project, unpackage the .zip file on your machine.
2) Open a command line session, navigate to the installation directory, and run `./mvnw liberty:dev` (Linux/Mac) or `mvnw liberty:dev` (Windows).
This will install all required dependencies and start the default server. When complete, you will
see the necessary features installed and the message "server is ready to run a smarter planet."

For information on developing your application in dev mode using Maven, see the
dev mode documentation (https://openliberty.io/docs/latest/development-mode.html).

For further help on getting started actually developing your application, see some of our
MicroProfile guides (https://openliberty.io/guides/?search=microprofile&key=tag) and Jakarta EE
guides (https://openliberty.io/guides/?search=jakarta%20ee&key=tag).

If you have problems building the starter project, make sure the Java SE version on your
machine matches the Java SE version you picked from the Open Liberty starter on the downloads
page (https://openliberty.io/downloads/). You can test this with the command `java -version`.

Open Liberty performs at its best when running using Open J9 which can be obtained via IBM Semeru
(https://developer.ibm.com/languages/java/semeru-runtimes/downloads/). For a full list of supported
Java SE versions and where to obtain them, reference the Java SE support page
(https://openliberty.io/docs/latest/java-se.html).

If you find any issues with the starter project or have recommendations to improve it, open an
issue in the starter GitHub repo (https://github.com/OpenLiberty/start.openliberty.io).
95 changes: 95 additions & 0 deletions microprofile-liberty-redis-cluster/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
version: '3'

services:
redis-configurer:
container_name: "redis-configurer"
image: redis:6.0-alpine
command: >
sh -c 'echo yes | redis-cli -h 172.22.0.2 -p 6379 --cluster create \
172.22.0.2:6379 172.22.0.3:6379 172.22.0.4:6379 \
172.22.0.5:6379 172.22.0.6:6379 172.22.0.7:6379 \
--cluster-replicas 1 && tail -f /dev/null'
depends_on:
- redis-1
- redis-2
- redis-3
- redis-4
- redis-5
- redis-6
networks:
redis-net:
ipv4_address: 172.22.0.10

redis-1:
container_name: "redis-1"
image: redis:6.0-alpine
ports:
- 7001:6379
command: ["redis-server", "--cluster-enabled", "yes", "--cluster-config-file", "nodes.conf", "--cluster-node-timeout", "5000", "--appendonly", "yes"]
depends_on:
- redis-2
- redis-3
- redis-4
- redis-5
- redis-6
networks:
redis-net:
ipv4_address: 172.22.0.2

redis-2:
container_name: "redis-2"
image: redis:6.0-alpine
ports:
- 7002:6379
command: ["redis-server", "--cluster-enabled", "yes", "--cluster-config-file", "nodes.conf", "--cluster-node-timeout", "5000", "--appendonly", "yes"]
networks:
redis-net:
ipv4_address: 172.22.0.3

redis-3:
container_name: "redis-3"
image: redis:6.0-alpine
ports:
- 7003:6379
command: ["redis-server", "--cluster-enabled", "yes", "--cluster-config-file", "nodes.conf", "--cluster-node-timeout", "5000", "--appendonly", "yes"]
networks:
redis-net:
ipv4_address: 172.22.0.4

redis-4:
container_name: "redis-4"
image: redis:6.0-alpine
ports:
- 7004:6379
command: ["redis-server", "--cluster-enabled", "yes", "--cluster-config-file", "nodes.conf", "--cluster-node-timeout", "5000", "--appendonly", "yes"]
networks:
redis-net:
ipv4_address: 172.22.0.5

redis-5:
container_name: "redis-5"
image: redis:6.0-alpine
ports:
- 7005:6379
command: ["redis-server", "--cluster-enabled", "yes", "--cluster-config-file", "nodes.conf", "--cluster-node-timeout", "5000", "--appendonly", "yes"]
networks:
redis-net:
ipv4_address: 172.22.0.6

redis-6:
container_name: "redis-6"
image: redis:6.0-alpine
ports:
- 7006:6379
command: ["redis-server", "--cluster-enabled", "yes", "--cluster-config-file", "nodes.conf", "--cluster-node-timeout", "5000", "--appendonly", "yes"]

networks:
redis-net:
ipv4_address: 172.22.0.7

networks:
redis-net:
driver: bridge
ipam:
config:
- subnet: 172.22.0.0/16
Loading

0 comments on commit be3dfdf

Please sign in to comment.