Build Microservices With Micronaut and Ignite
Build a Micronaut microservice backed by a GridGain in-memory database, then deploy the service and a two-node cluster in Docker.
Introduction
This tutorial walks you through the process of creating a simple Micronaut microservice that uses GridGain 8 as an in-memory database. The service provides information about the world's most populated cities by processing user HTTP requests and querying data from a distributed GridGain cluster. At the end of the tutorial, you deploy the microservice in Docker in your local environment. You can then easily launch the solution, with minimal changes, in a cloud environment.
Prerequisites
Java Development Kit, version 17 or later
Micronaut CLI, version 4.10. This tutorial uses Micronaut 4.10, which builds on Java 17. Micronaut 5 build plugins require a newer Java (25).
Apache Maven 3.9 or later
Docker with Docker Compose V2 (the
docker composecommand)GridGain 8.10 trial license file (
gridgain-license.xml) and the SQL scriptexamples/sql/world.sql, both from the GridGain 8.10 binary distributionYour favorite IDE, such as IntelliJ IDEA, or Eclipse
What You Will Learn
How to create a GridGain thin client singleton with Micronaut dependency injection
How to expose a Micronaut controller that queries GridGain with SQL
How to start a two-node GridGain cluster and load the World sample database
How to deploy the microservice and cluster together in Docker
Generate the Application Project
Start by creating a Maven project for the microservice implementation and accompanying Docker files.
To expedite this step, open a terminal window and use Micronaut CLI to generate a project structure:
Open the project with your favorite IDE and edit the {project}/pom.xml file:
Add the GridGain repository next to the existing
centralrepository:Add the
gridgain-corelibrary, which includes the thin client, to the list of the project dependencies:
Create the GridGain Thin Client Singleton
Micronaut implements the JSR-330: Dependency Injection for Java specification, which supports the @Singleton annotation. With that annotation, you can easily create a single instance of a GridGain thin client connection and share it across all your Micronaut controllers.
Add the following singleton implementation to the {project}/src/main/java/org/gridgain/demo folder:
The first inquiry to the singleton automatically calls the
init()method. The method creates an instance of the GridGain thin client.The
cfg.setAddresses(Application.IGNITE_SERVER_ADDRESS)parameter passes the address of a GridGain server node that the client needs to connect to.Application.IGNITE_SERVER_ADDRESSrepresents the environment variable that you are about to add to the application logic.The
cfg.setAffinityAwarenessEnabled(true)setting enables the partition-awareness feature of GridGain that allows the thin client to send query requests directly to the node that owns the requested record. If your network is configured so that the client can communicate only to the server with theApplication.IGNITE_SERVER_ADDRESSaddress, disable this property.
Open {project}/src/main/java/org/gridgain/demo/Application.java class that Micronaut CLI generated and change its default implementation by adding the logic that is related to the Application.IGNITE_SERVER_ADDRESS variable:
Introduce the Micronaut Controller
The controller needs to respond to user requests that are in the http://localhost:8080/cities?population=800000 format by returning all cities with a population that is equal to or greater than the population parameter.
Add org.gridgain.demo.City POJO class into the {project}/src/main/java/org/gridgain/demo folder that will be used by the controller's logic:
The @Serdeable annotation lets Micronaut Serialization convert City objects to JSON.
Complete the microservice implementation by adding the controller class into the {project}/src/main/java/org/gridgain/demo location:
The
@Inject IgniteClientConnectionclient directive injects an instance of your GridGain thin client singleton during the controller-creation process.The
List<City> listCities(int population)method intercepts user requests, queries data from GridGain and sends backs a sorted result.
Start the GridGain Cluster and Load the Sample Database
In the last few sections of the tutorial, you deploy the whole solution, including a GridGain cluster and the just-completed Micronaut microservice in Docker. Start by preparing three files in a cluster folder next to your project:
Copy your
gridgain-license.xmlfile and theexamples/sql/world.sqlscript from the GridGain 8.10 distribution to theclusterfolder. The Docker image does not include the examples.Add the
ignite-config.xmlfile. The default multicast discovery does not connect nodes in a Docker bridge network, so the configuration lists the service name of the server nodes, which Docker resolves to every node container:Add the
ignite-cluster.yamlDocker Compose configuration file:
Bootstrap a two-node GridGain cluster and load the World database records:
Open a terminal window, navigate to the
clusterfolder, and use the following Docker Compose command to launch the cluster:Wait about half a minute, then check that the two nodes formed one cluster. Look for
servers=2in the log of the second node:Connect to the first server node's container:
Once inside of the container, go to the
binfolder of the GridGain installation directory:Connect to the cluster with the SQLLine tool that is shipped with GridGain:
Create the World database schema and load the sample data by using the script that you mounted into the container:
Exit the container by closing the SQLLine connection (
!q) and the bash session (exit).
Build and Deploy the Micronaut Microservice
As with the cluster, you deploy the microservice in the Docker environment.
First, create a Docker image:
Go to the project's root folder and build the microservice with Maven:
Add a file named
Dockerfileto the project's root folder. The GridGain thin client needs access to a JDK internal package (java.nio) on Java 17 and later, so thejavacommand opens it:Create a Docker image named
ignite-micronaut-app:
Second, start the microservice from the image in the same Docker network as the cluster. Use the ignite_server_node service name as the server address, so that you do not need to look up a container IP address:
Query Most Populated Cities
Now your cluster and microservice are up-and-running and ready to process user requests.
Go ahead and request a list of the cities with a population equal to or greater than eight million by opening the following URL in a browser or with curl:
The response should be as follow:
Play with the population parameter to get cities with different populations.
Terminate the Microservice and the Cluster
Use the following commands to shut down the demo and free up resources:
Stop the Micronaut microservice:
If you're not planning to bring the service back later, remove the application container:
Shutdown the GridGain cluster:
Bonus Task
Create a similar application but deploy it as a serverless function in your favorite cloud environment. When the solution is workable, upload it to GitHub and claim an award by sending a direct message to the tutorial author.
This page is: Copyright © 2026 MariaDB. All rights reserved.
Last updated
Was this helpful?

