- Introduction
- Exercise 1: Challenge first steps
- Exercise 2: Spring Cache
- Exercise 2.1: Spring Cache without null values
- Exercise 3: Spring Session
- Exercise 4: Running your application of Openshift
- [Optional] Setting up your local development environment
- Documentation and Resources for this challenge
- Need help?
In this challenge, you will learn how to take advantage of Spring Cache and Spring Session to easily boost the performance of a Spring Boot application. As this exercise is focused on the Spring Boot client, you will be provided with the configuration of the caches as well as the configuration of the server on Openshift.
❗
|
The application developed in this challenge requires an instance of RH Data Grid 8.2 or Infinispan running to connect to. The final result has to run on Openshift, but for development purposes, you may want to use a local environment. Guidelines to deploy your Data Grid locally can be found in section Setting up your local development environment. Otherwise, we recommend you to use the CodeReady Workspaces instance deployed in your Openshift cluster. |
At the end of this exercise, you will have your application ready to code all the features required in this challenge. Please, before continuing to the next exercise, make sure that:
-
The application compiles, connects to Data Grid locally and runs.
-
The Infinispan Spring Boot Starter dependency is in place.
-
The necessary properties in the
application.properties
are configured. -
[Only local] Data Grid 8.2 or Infinispan 12.1.x.Final is running locally (through a container or by using the binaries).
As this is a Spring Boot application, running it is as simple as executing the following command:
mvn clean spring-boot:run
Once your application is running, run time weatherFetcher.sh
. It should take a few seconds to complete.
Use Spring Cache to decrease the execution time as much as you can.
💡
|
By default, Java Serialization is not enabled for any Java package. Set the property called Find more info in this section of the documentation. |
In order to make sure that Spring Cache is correctly configured and that entries are being cached, you can access the Data Grid web console to check the number of entries stored.
💡
|
In this challenge, the Data Grid server is configured to use authentication. Therefore, you will need a username and password to connect your client application as well as access the web console. As any other other product, credentials are stored as secrets. Check the documentation for more information |
Spring Cache provides many functionalities. One of them is to avoid the caching of null values. Use this feature to avoid caching and requesting null temperatures every time that the test is run.
Keep in mind that values might be stored from the previous execution! You have to clean the cache before executing the new code again. There are multiple methods, you may explore clearing the cache from the Java client or using the Web Console
💡
|
When you have finished this section, go to the Data Grid console. The statistics tab should display 10 entries instead of 11. If this is your value, congrats! You are not storing null values. |
Data Grid also provides an implementation for Spring Session. Use this feature to store clients' sessions, so that you do not lose the data if the application restarts.
You should store the latest city requested by each user in the user session. Users will be able to check the latest city using a REST endpoint.
💡
|
The Spring Session implementation does not check if the cache for sessions is configured on the server side. Make sure that the cache exists on Data Grid before launching your application!! |
Whether you decided to start coding locally or on CodeReady Workspaces, you will need to run your application in its own pod at some point. In this section, we will help you to do so!
🔥
|
Executing your application from CodeReady Workspaces is not enough to consider that your application is running on Openshift. |
First, you need to create an image based on a Java image. I suggest using an image like ubi8-openjdk-11
. You can find more information here. You can create this image using the s2i utility that provides Openshift. Follow this link for more information.
Second, you need to deploy your image on your Openshift project. I recommend you to use a Deployment or DeploymentConfig.
Third, you have to configure your client to connect to the Data Grid server. All the configuration that can change should be in the application.properties
.
💡
|
If you are a little bit lost, maybe you can check https://github.com/alvarolop/rhdg8-client#52-running-the-client-on-openshift [this] example of configuration. Ask questions if you are stuck in this section!! |
To run this application locally, you will need all the following requirements met:
-
To run your client application:
-
JDK 11+ installed with JAVA_HOME configured appropriately.
-
Apache Maven 3.8.1+
-
-
To run your server:
-
Check section below.
-
-
To execute scripts:
-
Bash console.
-
curl
command installed.
-
-
To deliver the exercise and work as a group:
-
A
git
account.
-
Run your server locally using one of these two options:
Running the server using a container image is as simple as executing the following command:
podman run -p 11222:11222 -e USER="admin" -e PASS="password" quay.io/infinispan/server:12.1.7.Final-1
If the server is up and running, you should see the following logs:
17:29:38,655 INFO (main) [org.infinispan.SERVER] ISPN080018: Started connector REST (internal)
17:29:38,865 INFO (main) [org.infinispan.SERVER] ISPN080004: Connector SINGLE_PORT (default) listening on 10.0.2.100:11222
17:29:38,903 INFO (main) [org.infinispan.SERVER] ISPN080001: Infinispan Server 12.1.7.Final started in 6149ms
There is a known compatibility issue in the Docker For Mac and the Infinispan Client. Explanations can be found in
this blog post.
You won’t need to do this in your production environment, but Docker for Mac users have to configure the following
property in the file src/main/resources/META-INF/resources/hotrod-client.properties
:
quarkus.infinispan-client.client-intelligence=BASIC
Follow the steps below:
-
Download server binaries from the Infinispan Downloads website. Choose version
12.1.7.Final
. -
Unzip the file and
cd
into the folder. -
Run the server using the script:
./bin/server.sh
.
If the server is up and running, you should see the following logs:
17:29:38,655 INFO (main) [org.infinispan.SERVER] ISPN080018: Started connector REST (internal)
17:29:38,865 INFO (main) [org.infinispan.SERVER] ISPN080004: Connector SINGLE_PORT (default) listening on 10.0.2.100:11222
17:29:38,903 INFO (main) [org.infinispan.SERVER] ISPN080001: Infinispan Server 12.1.7.Final started in 4399ms
In order to be successful in this challenge, you will need to check extra documentation. Here you can find some useful links:
Remember that we are all here to answer any questions and support you during all the Developer Games:
-
Katia Aresti - karestig@redhat.com
-
Álvaro López - alopezme@redhat.com