Develop very simple microservices using Spring Cloud, Spring Boot, Eureka Server, Feign, and Hystrix
- https://spring.io/projects/spring-cloud
- https://www.baeldung.com/spring-cloud-netflix-eureka
- https://www.baeldung.com/spring-cloud-openfeign
- https://www.baeldung.com/spring-cloud-netflix-hystrix
- https://www.baeldung.com/spring-rest-with-zuul-proxy
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 |
<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>
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
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)
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