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

Overview

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
    • Eureka Client
    • OAuth2.0 Client
    • Supports RestTemplate Client
    • Supports Resilience4J circuit breaker
    • Use of Resilience4J circuit breaker with RestTemplate
    • Swagger Document - http://localhost:8181/swagger-ui/index.html
  • 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 : http://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 : [http://localhost:9411/](http://localhost:9411/)

Zipkin-Server

Step 4: Generate OAuth2.0 token

4.1 Using curl

curl -X POST \
  http://localhost:8080/oauth/token \
  -H 'authorization: Basic amF2YWRldmVsb3BlcnpvbmU6c2VjcmV0' \
  -H 'cache-control: no-cache' \
  -H 'content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW' \
  -H 'postman-token: d2629b30-a7cf-fa72-df64-d71118afb549' \
  -F grant_type=password \
  -F username=zone1 \
  -F password=mypassword

4.2 Using swagger

In the swagger UI, There is a "Autorize" button on the top, click on it it will open the following popup:

eureka server

Use the following information

Username: zone1
Password: mypassword
ClientId: javadeveloperzone
Secret: secret

Output

{
    "access_token": "imdUX2_t_WQLSTUlaLBTjVyHUTg",
    "token_type": "bearer",
    "refresh_token": "zLufOQtLQO1u-8JP7KN64Dsc3wc",
    "expires_in": 522,
    "scope": "read write"
}

Step 5: Create user using user microservice

5.1 Using curl

curl -X POST \
  http://localhost:8080/user/ \
  -H 'authorization: Bearer imdUX2_t_WQLSTUlaLBTjVyHUTg' \
  -H 'cache-control: no-cache' \
  -H 'content-type: application/json' \
  -H 'postman-token: d73bb63f-969c-4081-1dee-77fa2b0f1f5a' \
  -d '{"firstName":"subhash", "lastName": "Lamba"}'
 

5.2 Using Swagger UI

eureka server

Step 6: Create order using order microservice

6.1 Using curl

curl -X POST \
  http://localhost:8080/order/ \
  -H 'authorization: Bearer DF977lxKiBzdWKTkZsE7XevqK40' \
  -H 'cache-control: no-cache' \
  -H 'content-type: application/json' \
  -H 'postman-token: 2256b83e-30dc-3b8e-26f0-8d13c0dcfd44' \
  -d '{"userId":1, "orderDate": "2021-01-01"}'

6.2 Using Swagger UI

eureka server

Step 7: Get user and order using user microservice

7.1 Using curl

curl -X GET \
  http://localhost:8080/user/1 \
  -H 'authorization: Bearer DF977lxKiBzdWKTkZsE7XevqK40' \
  -H 'cache-control: no-cache' \
  -H 'content-type: application/json' \
  -H 'postman-token: 5163fb23-f54f-c793-9faa-e9df54eab9d5' \
  -d '{"userId":1, "orderDate": "2021-01-01"}'
{
    "user": {
        "id": 1,
        "firstName": "subhash",
        "lastName": "Lamba"
    },
    "orders": [
        {
            "id": 5,
            "orderDate": "2021-01-01T00:00:00.000+00:00",
            "userId": 1
        }
    ]
}

7.1 Using Swagger UI

eureka server

You might also like...

Docker Compose Spring,Resilience4j,Prometheus,Grafana

Docker Compose Spring,Resilience4j,Prometheus,Grafana

Docker Compose Spring,Resilience4j,Prometheus,Grafana ( Circuit Breaker pattern - Retry pattern - Ratelimiter pattern - Timelimiter pattern - Bulkhead pattern )

Mar 27, 2022

Spring Boot Security Login example with JWT and H2 example

 Spring Boot Security Login example with JWT and H2 example

Spring Boot Security Login example with JWT and H2 example Appropriate Flow for User Login and Registration with JWT and HttpOnly Cookie Spring Boot R

Dec 21, 2022

How To Implement Fault Tolerance In Microservices Using Resilience4j

springboot-resilience4j-demo How To Implement Fault Tolerance In Microservices Using Resilience4j? Things todo list: Clone this repository: git clone

Mar 30, 2022

Clivia is a scalable, high-performance, elastic and responsive API gateway based on spring weblux

Clivia is a scalable, high-performance, elastic and responsive API gateway based on spring weblux

clivia是一款基于spring webflux的可扩展、高性能、高弹性、响应式的 API 网关 clivia_V0.0.1 架构概览 模块介绍 clivia-admin-core : 网关配置管理后台核心模块 clivia-client-core : 网关核心模块 clivia-example

Jan 9, 2023

Spring MSA api gateway & service discovery with consul & Jaeger & Cassandra

Spring-Cloud-MSA 준비 Cassandra 서버를 준비한다 table.sql 파일로 keyspace와 테이블을 만들어 둔다 Consul 1.11.1버전 기준 https://www.consul.io/downloads 에서 1.11.1 버전 운영체제 맞게 다운

Nov 22, 2022

DCL-350: Implementing MicroService Architecture using Spring Cloud

DCL-350: Implementing MicroService Architecture using Spring Cloud

DCL-350: Implementing MicroService Architecture using Spring Cloud

Sep 20, 2022

Spring JPA Many To Many example with Hibernate and Spring Boot CRUD Rest API - ManyToMany annotation

Spring JPA Many To Many example with Hibernate and Spring Boot CRUD Rest API - ManyToMany annotation

Dec 28, 2022

:herb: 基于springboot的快速学习示例,整合自己遇到的开源框架,如:rabbitmq(延迟队列)、Kafka、jpa、redies、oauth2、swagger、jsp、docker、spring-batch、异常处理、日志输出、多模块开发、多环境打包、缓存cache、爬虫、jwt、GraphQL、dubbo、zookeeper和Async等等:pushpin:

:herb: 基于springboot的快速学习示例,整合自己遇到的开源框架,如:rabbitmq(延迟队列)、Kafka、jpa、redies、oauth2、swagger、jsp、docker、spring-batch、异常处理、日志输出、多模块开发、多环境打包、缓存cache、爬虫、jwt、GraphQL、dubbo、zookeeper和Async等等:pushpin:

欢迎大家留言和PR~ Tip: 技术更新换代太快,本仓库仅做参考,自己的项目具体使用哪个版本还需谨慎思考~(不推荐使用最新的版本,推荐使用(最新-1|2)的版本,会比较稳定) spring-boot-quick 前言   自己很早就想搞一个总的仓库就是将自己平时遇到的和学习到的东西整合在一起,方便后

Jan 2, 2023

ShenYu is High-Performance Java API Gateway.

ShenYu is High-Performance Java API Gateway.

Scalable, High Performance, Responsive API Gateway Solution for all MicroServices https://shenyu.apache.org/ English | 简体中文 Architecture Features Shen

Jan 4, 2023
Owner
Subhash Lamba
Software Developer with 8+ years of experience in coding and build a system enterprise architecture.
Subhash Lamba
循序渐进,学习Spring Boot、Spring Boot & Shiro、Spring Batch、Spring Cloud、Spring Cloud Alibaba、Spring Security & Spring Security OAuth2,博客Spring系列源码:https://mrbird.cc

Spring 系列教程 该仓库为个人博客https://mrbird.cc中Spring系列源码,包含Spring Boot、Spring Boot & Shiro、Spring Cloud,Spring Boot & Spring Security & Spring Security OAuth2

mrbird 24.8k Jan 6, 2023
Demo microservice architecture with Spring ,Spring Cloud Gateway , Spring Cloud config server , Eureuka , keycloak and Docker.

spring-microservice Demo microservice architecture with Spring ,Spring Cloud Gateway , Spring Cloud config server , Eureuka , keycloak and Docker. Arc

null 4 Sep 13, 2022
Sample Spring-Cloud-Api-Gateway Project of Spring Boot

Sample-Spring-Cloud-Api-Gateway Sample Spring-Cloud-Api-Gateway Project of Spring Boot Proejct Stack Spring Webflux Spring Cloud Gateway Spring Data R

Seokhyun 2 Jan 17, 2022
Spring Boot Login and Registration example with MySQL, JWT, Rest Api - Spring Boot Spring Security Login example

Spring Boot Login example with Spring Security, MySQL and JWT Appropriate Flow for User Login and Registration with JWT Spring Boot Rest Api Architect

null 58 Jan 5, 2023
mall-swarm是一套微服务商城系统,采用了 Spring Cloud Hoxton & Alibaba、Spring Boot 2.3、Oauth2、MyBatis、Docker、Elasticsearch、Kubernetes等核心技术,同时提供了基于Vue的管理后台方便快速搭建系统。mall-swarm在电商业务的基础集成了注册中心、配置中心、监控中心、网关等系统功能。文档齐全,附带全套Spring Cloud教程。

mall-swarm 友情提示 快速体验项目:在线访问地址。 全套学习教程:《mall学习教程》。 Spring Cloud全套教程:《SpringCloud学习教程》。 专属学习路线:学习不走弯路,整理了套非常不错的《mall专属学习路线》。 项目交流:想要加群交流项目的朋友,可以加入mall项目

macro 9.7k Jan 3, 2023
Microservice Architecture with Spring Boot, Spring Cloud and Docker

Piggy Metrics Piggy Metrics is a simple financial advisor app built to demonstrate the Microservice Architecture Pattern using Spring Boot, Spring Clo

Alexander Lukyanchikov 12.1k Jan 1, 2023
Spring Boot JdbcTemplate example with SQL Server: CRUD Rest API using Spring Data JDBC, Spring Web MVC

Spring Boot JdbcTemplate example with SQL Server: Build CRUD Rest API Build a Spring Boot CRUD Rest API example that uses Spring Data Jdbc to make CRU

null 7 Dec 20, 2022
该仓库中主要是 Spring Boot 的入门学习教程以及一些常用的 Spring Boot 实战项目教程,包括 Spring Boot 使用的各种示例代码,同时也包括一些实战项目的项目源码和效果展示,实战项目包括基本的 web 开发以及目前大家普遍使用的线上博客项目/企业大型商城系统/前后端分离实践项目等,摆脱各种 hello world 入门案例的束缚,真正的掌握 Spring Boot 开发。

Spring Boot Projects 该仓库中主要是 Spring Boot 的入门学习教程以及一些常用的 Spring Boot 实战项目教程,包括 Spring Boot 使用的各种示例代码,同时也包括一些实战项目的项目源码和效果展示,实战项目包括基本的 web 开发以及目前大家普遍使用的前

十三 4.5k Dec 30, 2022
一个涵盖六个专栏:Spring Boot 2.X、Spring Cloud、Spring Cloud Alibaba、Dubbo、分布式消息队列、分布式事务的仓库。希望胖友小手一抖,右上角来个 Star,感恩 1024

友情提示:因为提供了 50000+ 行示例代码,所以艿艿默认注释了所有 Maven Module。 胖友可以根据自己的需要,修改 pom.xml 即可。 一个涵盖六个主流技术栈的正经仓库: 《Spring Boot 专栏》 《Spring Cloud Alibaba 专栏》 《Spring Clou

芋道源码 15.7k Dec 31, 2022
Google Oauth2 login scenario with Spring boot + React

spring-react-google-oauth2 Google Oauth2 login scenario with Spring boot + React Below diagram is based on oauth implicit flow. Result How to start Pr

배진우 14 Nov 24, 2022