Skip to content

Commit 3873734

Browse files
committed
chore: added a sample project using redis
Signed-off-by: Maximillian Arruda <[email protected]>
1 parent 5c09dea commit 3873734

File tree

20 files changed

+1064
-1
lines changed

20 files changed

+1064
-1
lines changed

README.adoc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ Open Liberty is a lightweight and highly flexible open-source application server
2727
|Simple CRUD REST application with *Jakarta Bean Validation* support
2828
| MongoDB
2929

30+
| link:microprofile-liberty-redis/[]
31+
| Simple CRUD REST application
32+
| Redis
33+
34+
3035
|===
3136

3237
== Wildfly
@@ -85,4 +90,5 @@ Apache TomEE is a lightweight, open-source Jakarta EE application server that is
8590
| Simple CRUD REST application
8691
| MongoDB
8792

88-
|===
93+
|===
94+
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
target/
2+
!target/*.war
3+
!target/liberty/wlp/usr/shared/resources/*
Lines changed: 11 additions & 0 deletions
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
Lines changed: 2 additions & 0 deletions
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
Lines changed: 10 additions & 0 deletions
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
Lines changed: 104 additions & 0 deletions
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+
Lines changed: 35 additions & 0 deletions
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).
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
version: "3"
2+
3+
services:
4+
redis:
5+
container_name: "redis-master"
6+
image: redis
7+
command: redis-server
8+
ports:
9+
- "6379:6379"

0 commit comments

Comments
 (0)