This is a tutorial which explains how to use Infinispan embedded in your own application. The application will retrieve the current weather conditions for some cities and store them in a cache, for quicker retrieval. It will also show how to configure the cache for expiration, so that entries get removed as they age. It will then demonstrate how to cluster multiple nodes together and reacting to events in the cluster. Finally, a computation of average temperatures per country will show the power of the map/reduce functionality.
Each tagged commit is a separate lesson teaching a single aspect of Infinispan.
The tutorial instructions are at http:https://infinispan.org/tutorials/embedded/
N.B. The tutorial connects to OpenWeatherMap (http:https://openweathermap.org) to retrieve current weather data. The service requires obtaining a free API key. Before launching the application, ensure you've set the OWMAPIKEY environment variable to your API key. If you don't want to register for the service, if you don't have an Internet connection or you are having trouble connecting to the service, just don't set the environment variable, and it will use the RandomWeatherService.
- Get a JDK. You will need version 1.8 or higher
- Get Maven. You will need version 3.2 or higher
You can check out any point of the tutorial using git checkout step-?
To see the changes between any two lessons use the git diff command. git diff step-?..step-?
- The initial implementation of the Weather application
- Adding Infinispan to the project and initializing a cache manager
- Add caching to the weather service
- Store the entries in the cache with an expiration time
- Configure the features of the default cache
- Add a transport to the CacheManager so that it supports clustering
- Use CacheManager events to detect changes in the cluster
- Detect changes to the cache with a clustered listener
- Group related entries on the same nodes for efficiency
- Implement a custom externalizer for our value class
- Use Distributed Streams to compute temperature averages per country
- Use the XML configuration instead of the programmatic API
- Run
mvn clean package
to rebuild the application - Run
mvn exec:exec
to execute the application. In case you're running a clustered step, run this from multiple terminals, where each instance will represent a node - Run
mvn clean package docker:build
to build docker image, and then rundocker run infinispan-embedded-tutorial/infinispan-embedded-tutorial
in 2 different terminals to simulate multiple nodes of distributed cache
docker/ -->
src/ -->
main/ -->
java/ -->
resources/ -->
For more information on Infinispan please check out http:https://infinispan.org/