To build a microservice architecture, I personally feel that the following modules must be used:
- config-service
- api-gateway
- circuit-breaker
- registry
- monitor
- ***-service
The first step is to build config-service, log in to http://start.spring.io/, select gradle, maven, basic information, and more importantly, select the required dependencies
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-config-server</artifactId> </dependency>
If you need to customize the port and repo address, here I declare that the port is 8877, and the repo is local. Assuming that you follow the CI, you can read the url address. There is no need for native here, but the git.uri address is required.
spring: cloud: config: server: native: search-locations: classpath:/profiles server: port: 8877
After the build is complete, the first config-service is completed
Build registry-service, a very important point EnableEurekaServer
spring: application: name: registry cloud: config: uri: http://localhost:8877 fail-fast: true password: 123456 username: user eureka: instance: prefer-ip-address: true client: registerWithEureka: false fetchRegistry: false server: waitTimeInMsWhenSyncEmpty: 0
How to solve the fuse? It can be done by fallbackmethod
@Override @HystrixCommand(groupKey = "say", fallbackMethod = "fallBackCall") public String ping() { return service2.ping(); }
To be continued~~~~