Skip to content

Maybe the first demo in Groovy with spring boot: a demo in Groovy running a Spring Boot web app with OpenApi and using Kafka and Elasticsearch

License

Notifications You must be signed in to change notification settings

besessener/GroovySpringBootKafkaElasticsearchDemo

Repository files navigation

Spring Boot demo in Groovy

featuring:

  • easy Http GET and POST routes

  • OpenApi (annotation usage, doc generation, groovy client generation)

  • Swagger UI

  • Kafka stream

  • Elasticsearch store and read

The service will accept new User objects as JSON via Http POST. This new user will then be put onto the Kafka stream ('topic-user' topic) to allow asynchronuous processing of it. POST will almost immediately respond to the client. The Kafka Listener on the other side will then trigger on every new incoming user and write it into Elasticsearch ('user' index). All GET methods will then directly fetch from Elasticsearch to return the requested results.

Setup

  1. Get Gradle 6.8.x or newer (Gradle wrapper is configured for 7.0.2)

  2. Zookeeper

    1. download (https://zookeeper.apache.org/releases.html#download)

    2. execute ()

      cd ~/kafka_2.12-2.2.2/bin
      ./zookeeper-server-start.sh ../config/zookeeper.properties
  3. Kafka

    1. Download Kafka (https://kafka.apache.org/downloads)

    2. execute

      cd ~/kafka_2.12-2.2.2/bin
      ./kafka-server-start.sh ../config/server.properties
    3. add topic

      export KAFKA_HOME=/home/vagrant/kafka_2.12-2.2.2/
      cd ~/convenienceScripts  # special scripts, just create a topic
      . ./localKafka.sh
      ./createTopic.sh topic-user 0   # this topic is configured in AppConstants.groovy as well
      ./showTopics.sh  # optional to see that it worked
  4. Elasticsearch

    1. download (https://www.elastic.co/downloads/elasticsearch, be aware that latest version might not work with spring-data-elasticsearch: I use 7.12.1)

    2. execute

      cd ~/elasticsearch/elasticsearch-7.12.1/bin
      ./elasticsearch

Execution

Either run the GroovyDemoApplication from within IntelliJ or run ./gradlew bootRun in your shell to start the application. The gradle option has the nice benefit of also generating API docs and client side API classes.

Access

localhost:8080 will open Swagger UI. There you will see all access possibilities. The rest of the routes are, as you might see, under: localhost:8080/users/*

With localhost:9200/user you can access the Elasticsearch index that is used to store and read data (directly, defined in AppConstants.groovy).

About

Maybe the first demo in Groovy with spring boot: a demo in Groovy running a Spring Boot web app with OpenApi and using Kafka and Elasticsearch

Topics

Resources

License

Stars

Watchers

Forks

Languages