Skip to content

edwin/infinispan-remote-cache-listener

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Infinispan Remote Cache Listener

A Spring Boot application that demonstrates how to set up and use Infinispan remote cache listeners to monitor cache events.

Overview

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.

Technologies Used

  • Java 21
  • Spring Boot 3.5.7
  • Infinispan 16.0.1
  • Infinispan Spring Boot Starter (Remote)
  • Infinispan HotRod Client
  • Lombok
  • Jackson

Prerequisites

  • JDK 21
  • Maven
  • Running Infinispan server (accessible at the address specified in application.properties)

Configuration

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=password

Modify these settings to match your environment:

  • infinispan.remote.server-list: Address and port of your Infinispan server
  • infinispan.remote.auth-username: Username for Infinispan authentication
  • infinispan.remote.auth-password: Password for Infinispan authentication

Project Structure

Key Components

  1. Main.java: The entry point for the Spring Boot application.

  2. InfinispanConfiguration.java: Configures the connection to the Infinispan server and sets up the remote cache.

  3. InfinispanInitializer.java: Initializes the Infinispan cache and registers the cache listener when the application starts.

  4. InfinispanRemoteListener.java: Implements the cache event listeners for entry creation and expiration events.

How It Works

  1. The application connects to a remote Infinispan server using the HotRod client protocol.
  2. It registers a client listener (InfinispanRemoteListener) with a cache named "temp-user-cache".
  3. The listener logs debug messages when cache entries are created or expired.

Running the Application

  1. Ensure you have an Infinispan server running and accessible at the address specified in application.properties.
  2. Build the application:
    mvn clean package
    
  3. Run the application:
    java -jar target/infinispan-remote-cache-listener-1.0-SNAPSHOT.jar
    
  4. The application will connect to the Infinispan server and start listening for cache events.

Cache Events

The application currently listens for two types of cache events:

  1. Entry Creation: Triggered when a new entry is added to the cache.
  2. 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.

Cache Configuration

{
  "temp-user-cache": {
    "replicated-cache": {
      "mode": "SYNC",
      "statistics": true,
      "encoding": {
        "media-type": "text/plain"
      },
      "expiration": {
        "lifespan": "-1",
        "max-idle": "5000"
      }
    }
  }
}

Adding Data

Creating new cache in Infinispan Web Console Screenshot: Creating a new cache through Infinispan Web Console

Success adding new cache in Infinispan Web Console Screenshot: Successful adding a new cache through Infinispan Web Console

Example Logs

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

Author

Muhammad Edwin (edwin@redhat.com)

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages