A Spring Boot application that demonstrates how to set up and use Infinispan remote cache listeners to monitor cache events.
This project showcases the integration of Spring Boot with Infinispan's remote cache functionality, specifically focusing on implementing cache event listeners. The application connects to a remote Infinispan server and registers listeners that respond to cache events such as entry creation and expiration.
- Java 21
- Spring Boot 3.5.7
- Infinispan 16.0.1
- Infinispan Spring Boot Starter (Remote)
- Infinispan HotRod Client
- Lombok
- Jackson
- JDK 21
- Maven
- Running Infinispan server (accessible at the address specified in application.properties)
The application is configured via the application.properties file:
# Server configuration
server.port=8080
spring.application.name=infinispan-remote-cache-listener
# Logging configuration
logging.level.root=INFO
logging.level.com.edw=DEBUG
logging.pattern.console=%d{dd-MM-yyyy HH:mm:ss} %magenta([%thread]) %highlight(%-5level) %logger.%M - %msg%n
# Infinispan configuration
infinispan.remote.server-list=192.168.8.140:11222
infinispan.remote.auth-username=admin
infinispan.remote.auth-password=passwordModify these settings to match your environment:
infinispan.remote.server-list: Address and port of your Infinispan serverinfinispan.remote.auth-username: Username for Infinispan authenticationinfinispan.remote.auth-password: Password for Infinispan authentication
-
Main.java: The entry point for the Spring Boot application.
-
InfinispanConfiguration.java: Configures the connection to the Infinispan server and sets up the remote cache.
-
InfinispanInitializer.java: Initializes the Infinispan cache and registers the cache listener when the application starts.
-
InfinispanRemoteListener.java: Implements the cache event listeners for entry creation and expiration events.
- The application connects to a remote Infinispan server using the HotRod client protocol.
- It registers a client listener (
InfinispanRemoteListener) with a cache named "temp-user-cache". - The listener logs debug messages when cache entries are created or expired.
- Ensure you have an Infinispan server running and accessible at the address specified in
application.properties. - Build the application:
mvn clean package - Run the application:
java -jar target/infinispan-remote-cache-listener-1.0-SNAPSHOT.jar - The application will connect to the Infinispan server and start listening for cache events.
The application currently listens for two types of cache events:
- Entry Creation: Triggered when a new entry is added to the cache.
- Entry Expiration: Triggered when an entry expires in the cache.
When these events occur, the application logs the key of the affected cache entry at the DEBUG level.
{
"temp-user-cache": {
"replicated-cache": {
"mode": "SYNC",
"statistics": true,
"encoding": {
"media-type": "text/plain"
},
"expiration": {
"lifespan": "-1",
"max-idle": "5000"
}
}
}
}
Screenshot: Creating a new cache through Infinispan Web Console
Screenshot: Successful adding a new cache through Infinispan Web Console
20-11-2025 11:15:32 [HotRod-client-async-pool-1-1] DEBUG com.edw.listener.InfinispanRemoteListener.entryCreated - data hello is created
20-11-2025 11:16:11 [HotRod-client-async-pool-1-1] DEBUG com.edw.listener.InfinispanRemoteListener.entryExpired - data hello is expired
Muhammad Edwin (edwin@redhat.com)