Skip to content

Spring boot microservice example with Eureka Server + Eureka Client + Spring Cloud API Gateway + OAuth2.0 + Circuit Breaker + Resilience4J + FeignClient + RestTemplate

Notifications You must be signed in to change notification settings

subhashlamba/spring-boot-microservice-example

Repository files navigation

Spring boot microservice example Build Status

Spring boot microservice example with Eureka Server + Eureka Client + Spring Cloud API Gateway + OAuth2.0 + Circuit Breaker + Resilience4J + FeignClient + RestTemplate

  • Eureka Server : Eureka service registry
  • Spring Cloud API Gateway: API Gateway which is responsible to route the request to specific microservice
  • Spring OAuth2.0: Authentication service and responsible to secure the end points.
    • Eureka Client
    • Generate OAuth token
    • Validate the OAuth token
  • User Service: User microservice with a basic feature
  • Order Service: Order microservice with a basic feature
  • Notification Service: Notification microservice with basic feature

Checkout repository

> git clone https://github.com/subhashlamba/spring-microservices.git
> cd spring-boot-microservices-example

Step 1: Start all services

1.1 For windows:

mvn clean install -f .\spring-boot-cloud-eureka-server\pom.xml
mvn clean install -f .\spring-boot-cloud-zuul-routing\pom.xml
mvn clean install -f .\spring-boot-cloud-eureka-user-service\pom.xml
mvn clean install -f .\spring-boot-cloud-eureka-order-service\pom.xml
mvn clean install -f .\spring-boot-cloud-eureka-notification-service\pom.xml
mvn clean install -f .\spring-boot-cloud-authentication-service\pom.xml

START "Server" java -jar spring-boot-cloud-eureka-server/target/eureka-server.jar 
START "API Gateway" java -jar spring-boot-cloud-zuul-routing/target/zuul-api-gateway.jar --server.port=8080 
START "User Service" java -jar spring-boot-cloud-eureka-user-service/target/user-service.jar --server.port=8181
START "Order Service" java -jar spring-boot-cloud-eureka-order-service/target/order-service.jar --server.port=8282
START "Notification Service" java -jar spring-boot-cloud-eureka-notification-service/target/notification-service.jar --server.port=8383
START "Authentication Service" java -jar spring-boot-cloud-authentication-service/target/authentication-service.jar --server.port=8484

Step 2: Check Eureka Server

Eureka server is running 8761 port, Now let's open it. Where we can check following instances are running:

  • 1 instance of API Gateway service
  • 1 instance of User service
  • 1 instance of Order service
  • 1 instance of Authentication service
  • 1 instance of Notification service

Eureka server : https://localhost:8761/

eureka server

Step 3: Configure Zipkin Server (Optional)

1. Download the [https://zipkin.io/pages/quickstart] Download zipkin
2. Start zipkin using following command:
java -jar zipkin-server-2.23.2-exec.jar
3. Open zipkin server : [https://localhost:9411/](https://localhost:9411/)

Zipkin-Server

Step 4: Generate OAuth2.0 token

4.1 Using curl

curl -X POST \
  https://localhost:8080/oauth/token \
  -H 'authorization: Basi