Skip to content

Develop very simple microservices using Spring Cloud, Spring Boot, Eureka Server, Feign, and Hystrix

Notifications You must be signed in to change notification settings

GarySsu/spring-cloud

Repository files navigation

Develop very simple microservices using Spring Cloud, Spring Boot, Eureka Server, Feign, and Hystrix

Reference Documents:

Components:

Project Name Description Port
eureka_server_a Service Registration and Discovery 8888
eureka_server_b Service Registration and Discovery 9999
microservice_order The Service which is going to get data from Server via the Discovery Service from the Service Registry (eureka_server_a, eureka_server_b) 9011
microservice_user Offer user information 9013
hystrix_monitor Monitor a single server microservice_order 8222
microservice_gateway Has a nice integration with an embedded Zuul proxy 7777
microservice_config Offer DB connection for Order and User service 9001
flyway_migrations Mysql database migrations 8080

Instructions for use:

Define Spring Cloud version in parent project

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-dependencies</artifactId>
            <version>Finchley.M9</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

Spring Cloud simple flow

Eureka - Create two servers, when one of them is broken, the service can keep working.

Application Address Description
http://127.0.0.1:8888/ Registry
http://127.0.0.1:9999/ Registry

  • 1.add EnableEurekaServer annotation
@EnableEurekaServer
  • 2.add Eureka server setting in application.yml
    server:
      port: 9999
    spring:
      application:
        name: eureka-server
    eureka:
      client:
        fetch-registry: true
        register-with-eureka: true
        service-url:
          defaultZone: http://127.0.0.1:8888/eureka
      server:
        eviction-interval-timer-in-ms: 5000
        enable-self-preservation: false

Openfeign - It is a convenient framework for calling Spring Cloud remote services.

Application Address Description
http://127.0.0.1:9011/order/4ffcfab8-c765-11ea-826b-6027a2b7af48/ get microservice_order order information and microservice_user user information
{"status":"200","message":"sucess","orderMaster":{"id":1,"orderNum":"4ffcfab8-c765-11ea-826b-6027a2b7af48","game":"Lineage M","device":"mobile","username":"gary ssu","userId":1},"userDto":{"id":1,"username":"gary ssu","address":"New Taipei City","age":20,"lastLoginTime":"2020-07-16 03:00:00"},"orderDetails":null}

Hystrix - Monitor service display data on dashboard. When microservice_user is suspended, the fallback method will be used

Application Address Description
http://127.0.0.1:7777/hystrix/ hystrix dashboard

  • 1.add Hystrix annotation in microservice_order app
@EnableFeignClients // OpenFeign
  • 2.add fallback annotation in your controller
@FeignClient(value = "microservice-user",fallback = UserControllerImpl.class)

Zuul - Communication between a front-end application and a REST API that are deployed separately.

Application Address Description
http://127.0.0.1:8222/ Zuul Proxy
  • 1.add Zuul annotation in microservice_gateway app
@EnableZuulProxy
  • 2.Zuul setting
zuul:
  routes:
    microservice-user:
      path: /microservice-user #url
      serviceId: /microservice-user #server name
    microservice-movie:
      path: /microservice-order #url
      serviceId: /microservice-order #server name
  SendErrorFilter:
    error:
      disable: true

About

Develop very simple microservices using Spring Cloud, Spring Boot, Eureka Server, Feign, and Hystrix

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages