The demo shows how to create a simple Micronaut microservice that processes HTTP requests and queries data from an Ignite cluster using SQL APIs. The app is deployed in Docker and uses a lightweight Ignite thin client connection to communicate with the cluster.
If you'd like to build the microservice from the ground up, learning about all the nuances, then complete the Building Microservices With Micronaut and Apache Ignite tutorial.
Before deploying the application, let's boot up an Ignite cluster and load it with sample data.
Start a two-node Ignite cluster in Docker using configuration settings of the ignite-cluster.yaml
file:
docker-compose -p cluster -f ignite-cluster.yaml up --scale ignite_server_node=2 -d
Create the World database schema that is shipped with every Ignite release and load sample data into the cluster:
-
Connect to the first Ignite server node container:
docker exec -it cluster_ignite_server_node_1 bash
-
Go to the
bin
folder of the Ignite installation directory:cd apache-ignite/bin/
-
Connect to the cluster with the SQLLine tool:
./sqlline.sh --verbose=true -u jdbc:ignite:thin://127.0.0.1/
-
Load the World database using SQLLine:
!run ../examples/sql/world.sql
-
Disconnect from the container by closing the SQLLine connection (
!q
) and the bash session (exit
)
Similarly to the cluster, you deploy the application in Docker with a single port open for HTTP requests processing.
Create the application's Docker image:
-
Build the application with Maven:
mvn clean package
-
Produce a Docker image named
ignite-micronaut-app
:docker build -t ignite-micronaut-app .
Start the application passing an IP address of one of the Ignite server nodes:
-
Get the IP address of the first server node:
docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' cluster_ignite_server_node_1
-
Replace the
<YOUR_IP_ADDRESS>
with the IP address returned by the previous command and launch the application in Docker:docker run -p 8080:8080 --env igniteServerAddress=<YOUR_IP_ADDRESS>:10800 --name ignite-micronaut-app --network cluster_ignite_net ignite-micronaut-app
The application will connect to the cluster using the <YOUR_IP_ADDRESS>:10800
endpoint and will be ready to process your
HTTP requests on port 8080
.
With the application running, you can request a list of the most populated cities by opening the URL below in a browser or
with curl
:
curl http://localhost:8080/cities?population=8000000
The previous request returns all the cities with the population equal to or bigger than 8 million. Micronaut intercepts this
request and queries the Ignite cluster to prepare the response. Note, you can change
the value of the population
parameter to get cities with a different population.
Use the commands below to shutdown the demo and free up resources:
-
Stop the application:
docker container stop ignite-micronaut-app
-
Remove the application container:
docker container rm ignite-micronaut-app
-
Shutdown the Ignite cluster:
docker-compose -p cluster -f ignite-cluster.yaml down