|
| 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 | + |
0 commit comments