Giter VIP home page Giter VIP logo

ignite-micronaut-demo's Introduction

Demo: Getting Started With Apache Ignite and Micronaut

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.

Start Ignite Cluster and Load Sample Database

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:

  1. Connect to the first Ignite server node container:

    docker exec -it cluster_ignite_server_node_1 bash
  2. Go to the bin folder of the Ignite installation directory:

    cd apache-ignite/bin/
  3. Connect to the cluster with the SQLLine tool:

    ./sqlline.sh --verbose=true -u jdbc:ignite:thin://127.0.0.1/
  4. Load the World database using SQLLine:

    !run ../examples/sql/world.sql
  5. Disconnect from the container by closing the SQLLine connection (!q) and the bash session (exit)

Start Micronaut Application

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:

  1. Build the application with Maven:

    mvn clean package
  2. 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:

  1. Get the IP address of the first server node:

    docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' cluster_ignite_server_node_1
  2. 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.

Request Most Populated Cities

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.

Terminate Demo

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.