Reactive API with Mutiny
What You Will Learn
How to use the Infinispan Mutiny API to perform non-blocking, reactive cache operations. Instead of the traditional RemoteCacheManager, this tutorial uses the Infinispan API entry point to obtain a MutinyCache.
Prerequisites
-
Java 17+
-
An Infinispan Server running on
localhost:11222(or Docker/Podman available for Testcontainers)
Step 1: Connect with the Infinispan API
Use the Infinispan.create() factory to establish a connection:
ConfigurationBuilder configurationBuilder = TutorialsConnectorHelper.connectionConfig();
try {
infinispan = Infinispan.create(configurationBuilder.create());
Step 2: Obtain a Mutiny Cache
Get a MutinyCache from the Mutiny API:
cache = infinispan.mutiny()
.caches().<String, String>get(TUTORIAL_CACHE_NAME)
.await().atMost(Duration.ofMillis(100));
Step 3: Chain Reactive Operations
Use Mutiny operators to chain cache operations in a non-blocking pipeline:
cache.set("hello", "reactive")
.chain(ignore -> cache.get("hello"))
.onItem().invoke(v -> System.out.printf("%s -- %s\n", LocalDateTime.now(), v))
.map(v -> v + " is nice!!")
.onItem().delayIt().onExecutor(executor).by(Duration.ofSeconds(1))
.invoke(v -> System.out.printf("%s -- %s\n", LocalDateTime.now(), v))
.await().atMost(Duration.ofSeconds(2));
This pipeline sets a value, reads it back, transforms it, adds a delay, and prints the result — all as a reactive chain.
Step 4: Run the Tutorial
mvn package exec:java
You should see two timestamped lines showing the reactive operations executing with a one-second delay between them.
What’s Next
-
Getting started with basic cache operations
-
Transactional operations with commit and rollback


