Skip to content

About

Spring gRPC, GraphQL, Docker OpenTelemetry LGTM, Kafka, Redis, Elasticsearch and Logstash Integrations with Spring Boot 4, Java 25 and Docker. Integration Tests with Testcontainers for Controller. Unit Tests for Controller, Service, and Mapper with Junit, and Mockito

Topics

Resources

Stars

9 stars

Watchers

1 watching

Forks

Repository files navigation

Table of Contents

  1. Summary
  2. Prerequisites and Installation
  3. How To Run And Test Application
  4. Tech Stack
  5. Redis Commands
  6. Google Play Integrity API
  7. References

Summary

live-data-service is providing CRUD operations to process live events


Prerequisites

  • Docker needs to be installed
  • Clone or checkout the project from version control system (git) and follow below steps
  • For local development only (not needed for Docker-based workflows):
    • Java 26+ needs to be installed export JAVA_HOME=$(/usr/libexec/java_home -v 26)
    • Maven needs to be installed (or use the included Maven wrapper ./mvnw)
    • Install any Java IDE (Eclipse, STS, Intellij etc..)

How_To_Run_And_Test_Application

  • The Dockerfile uses a multi-stage build with Maven cache mounts and a jlink custom runtime, so you do not need to build the JAR locally first. Docker handles the full build (compile + package) inside the container.
  • Tests are skipped during the Docker build because Testcontainers requires a Docker daemon which is not available inside docker build. Run tests on the host before building.
  • The start_application profile builds the app image and starts it together with all infrastructure services (Redis, Kafka, Elasticsearch, ActiveMQ, Mailpit, Zipkin, Jaeger, etc.). Services with healthchecks (Elasticsearch, Kafka) must be healthy before the app starts.
  • Docker -> Preferences -> Resources -> File sharing -> click add button and select prometheus folder under the /src/main/resources or just add /etc/prometheus path -> Apply & Restart
    • img.png
cd live-data-service

# Run tests on the host (requires Docker for Testcontainers)
mvn clean verify

# Build and start the application together with all infrastructure services
docker compose --profile start_application up -d --build

# Start only infrastructure services (Redis, Kafka, Elasticsearch, etc.)
docker compose up -d

# For local development without Docker (requires infrastructure services running via docker compose up -d)
./mvnw spring-boot:run   # or: mvn spring-boot:run

Tech_Stack

  • Java 26

  • Spring Boot 4

  • H2 Database (Default values are provided below)

  • Swagger: http://localhost:8080/swagger-ui/index.html

  • Flyway for database migration

  • Centralize exception handling by ControllerAdvice

  • Mapstruct to map different type of objects to each other

  • Micrometer dependencies were added to track the logs easily

  • OpenTelemetry with Grafana LGTM stack for distributed tracing, metrics, and log correlation

    • TraceId and SpanId are propagated to all log statements (including Hibernate SQL queries) via MDC
    • AOT-compatible tracing configuration ensures context propagation works with Spring Boot AOT and virtual threads
  • Testcontainers dependencies were added for integration tests

  • docker-compose.yml contains Grafana LGTM (Loki, Grafana, Tempo, Mimir) for unified observability, Prometheus for metrics scraping, Kafka for event-driven architecture, Redis for caching, Elasticsearch, Kibana, and Logstash for search, analytics engine and logs, PostgreSQL and MongoDB for data storage.

    • Kafka and its UI are included for message streaming, while the Elastic Stack (Elasticsearch, Logstash, Kibana) is set up for log management and visualization.
    • All services are connected through bridge networks, ensuring communication between containers.
    • Actuator: http://localhost:8080/actuator
    • Kafka UI: http://localhost:9999/
    • RedisInsight: http://localhost:5540/
      • Redis Host: redis
      • Redis Port: 6379
    • activemq-artemis Web Console: http://localhost:8161
    • Grafana LGTM (OpenTelemetry collector + Grafana UI)
      • Login Credentials
      • Preconfigured datasources: Loki (logs), Tempo (traces), Mimir (metrics)
      • OTLP endpoints: http://localhost:4318 (HTTP), http://localhost:4317 (gRPC)
    • Prometheus
    • Elasticsearch: http://localhost:9200/
    • Kibana: http://localhost:5601/app/home#/
      • Connect Spring Boot to Elasticsearch (TESTED FOR SPRING BOOT 4)
      • Run Spring Boot project
      • Open http://localhost:5601/app/home#/ --> Discover --> Create data view -> Name should be Index name --> Save date view to Kibana
        • img.png
    • Database credentials
      • PostgreSQL
        • url: jdbc:postgresql://localhost:5432/localdb
        • username: test
        • password: test
      • MongoDB
        • url: mongodb://localhost:27017/testdb?authSource=admin
        • username: root
        • password: example
    • GraphQL endpoint: http://localhost:8080/graphiql?path=/graphql
      • GraphQL API Documentation in Swagger UI:
        • Swagger UI: http://localhost:8080/swagger-ui/index.html - Select graphql-api from the dropdown
        • GET /api/graphql/schema - Returns the GraphQL schema (SDL)
        • GET /api/graphql/info - Provides API documentation with available queries and mutations
        • GET /api/graphql/examples/queries - Example query payloads
        • GET /api/graphql/examples/mutations - Example mutation payloads
    • gRPC API Documentation in Swagger UI:
    • Mailpit UI: http://localhost:8025/
      • username: admin
      • password: admin
      • Mailpit is a local SMTP server for testing email sending functionality without actually sending emails to real addresses. It captures and displays emails sent by the application, allowing developers to verify email content and functionality during development.
  • Test via Postman (OPTIONAL):

    1. Import Postman Collection
    2. Right-click the imported Postman Collection and click Run Collection section.
    3. On the right panel choose Functional or Performance section, edit Run configuration and click _ run_ to test the application.

Docker Compose image versions

  • Check pinned image tags in docker-compose.yml:
    • Linux / macOS / Git Bash: ./docs/scripts/check-compose-image-updates.sh
    • Windows: .\docs\scripts\check-compose-image-updates.cmd
    • Preview upgrades: ./docs/scripts/check-compose-image-updates.sh --dry-run
    • Apply OUTDATED bumps: ./docs/scripts/check-compose-image-updates.sh --apply
  • CI runs the read-only check on every pipeline; automated Maven + Compose upgrades run via .github/workflows/dependency-update.yml.

Redis

  • The following command returns all matched data by 'keyPattern:*' pattern

    • redis-cli --scan --pattern 'keyPattern:*'
  • The following command deletes all matched data by 'keyPattern:*' pattern

    • redis-cli KEYS 'keyPattern:*' | xargs redis-cli DEL
  • The following command finds TYPE in redis with KEY

    • TYPE key -> TYPE xxx:hashedIdOrSomethingElse
  • The following commands search by TYPE

    • for "string" TYPE: get key
    • for "hash" TYPE: hgetall key
    • for "list" TYPE: lrange key 0 -1
    • for "set" TYPE: smembers key
    • for "zset" TYPE: zrange key 0 -1 withScores

Google_Play_Integrity_API


References

About

Spring gRPC, GraphQL, Docker OpenTelemetry LGTM, Kafka, Redis, Elasticsearch and Logstash Integrations with Spring Boot 4, Java 25 and Docker. Integration Tests with Testcontainers for Controller. Unit Tests for Controller, Service, and Mapper with Junit, and Mockito

Topics

Resources

Stars

9 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages