Skip to content
项目

Nasruddin/spring-boot-based-microservices

在 GitHub 查看

关于

这是一个模块化、可扩展的 Spring Boot 微服务框架,用于管理课程和评论。它通过 Keycloak 提供 OAuth 2.0 身份验证,使用 Spring Cloud Gateway 管理 API,并借助 OTel、Grafana、Loki、Tempo 和 Prometheus 实现可观测性。数据存储使用 MongoDB 和 PostgreSQL,支持通过 Docker Compose 和 Kubernetes 部署。

系统与基础设施

这些数字如何统计

实测星标增长

24小时
0
7天
0
15天
0
1个月
正在收集历史

各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。

README.md

原文

Spring Boot Based Microservices

A modular, production-style microservices reference project for managing courses and reviews with strong focus on:

  • API gateway routing
  • OAuth2/OIDC security with Keycloak
  • Observability (metrics, logs, traces)
  • Docker Compose and Kubernetes/Tilt local deployment workflows

Table of Contents


Overview

The system is split into domain services and platform components:

  • Gateway Service: entry point and request routing
  • Course Service: manages course data in PostgreSQL
  • Review Service: manages review data in MongoDB
  • Course Composite Service: aggregates course + review responses
  • Keycloak: identity provider for authn/authz
  • Observability stack: Prometheus, Grafana, Loki, Tempo, Fluent Bit, OpenTelemetry Collector

Architecture

Context Diagram

System context

Container Diagram

Container

Component Diagram

Component

Deployment View

Deployment


Tech Stack

  • Java 17, Spring Boot, Spring Cloud Gateway
  • PostgreSQL (Course Service)
  • MongoDB (Review Service)
  • Keycloak (OAuth2/OIDC)
  • OpenTelemetry, Prometheus, Grafana, Loki, Tempo, Fluent Bit
  • Docker Compose and Kubernetes (Minikube + Tilt)

Prerequisites

Install the following before running:

  • Java 17+
  • Maven 3.8+
  • Docker + Docker Compose
  • (Optional) Minikube + Tilt for Kubernetes mode
  • curl or HTTPie for API validation

Quick Start (Docker Compose)

Make sure Docker Engine is running.

1) Start databases

cd docker
docker compose -f docker-compose-infra.yml up --build

2) Start observability stack

cd docker
docker compose -f docker-compose-observability.yml up --build

3) Start microservices

From repository root:

sh run.sh docker

or

sh run.sh

Run with Kubernetes + Tilt

1) Start Minikube

minikube start \
  --profile=microservice-deployment \
  --memory=4g \
  --cpus=4 \
  --disk-size=30g \
  --kubernetes-version=v1.31.0 \
  --driver=docker

2) Enable ingress

minikube addons enable ingress --profile microservice-deployment

3) Use Minikube Docker daemon

eval $(minikube -p microservice-deployment docker-env)

4) Build images

sh build-images.sh

5) Start platform with Tilt

tilt up

Optional check:

tilt get uiresources

Each service exposes actuator metrics and Prometheus output.

Core Endpoints

Ports and hostnames depend on your local setup (Docker vs Kubernetes ingress).

Typical routes exposed through the gateway:

  • GET /course
  • POST /course
  • GET /review
  • POST /review
  • GET /course-composite/{courseId}

Actuator/metrics examples:

  • GET /actuator/health
  • GET /actuator/prometheus

Keycloak

Keycloak is used as the identity provider for user authentication and token issuance.

Typical local flow:

  1. Open Keycloak admin/UI.
  2. Ensure realm, clients, and users are configured.
  3. Get a bearer token from Keycloak.
  4. Call gateway APIs with Authorization: Bearer <token>.

The token must contain both:

Observability

Prometheus

  • Check service targets are UP.
  • Scrape metrics from /actuator/prometheus.

Grafana

  • Use dashboards for metrics/logs/traces correlation.

Fluent Bit + Loki

  • Fluent Bit forwards service logs to Loki.

Tempo + OpenTelemetry

  • Services export traces through OTel collector to Tempo.

Troubleshooting

  • Services fail to start: verify dependent containers (PostgreSQL, MongoDB, Keycloak) are healthy.
  • Auth issues (401/403): check token expiration, client config, and realm roles in Keycloak.
  • No logs/traces/metrics: ensure Fluent Bit, OTel collector, Prometheus, Loki, and Tempo are running.
  • Kubernetes image pull issues: confirm you built images in Minikube Docker context (docker-env).

Notes

  • This README focuses on readable setup and operational flow.
  • Architecture diagrams remain in notes/images.

探索相关项目

加载中…