1.配置一个Eureka集群注册中心的配置如下
spring: profiles: active: first application: name: xxx.system --- spring: profiles: first server: port: 5060 eureka: instance: hostname: http://localhost:5060 preferIpAddress: true client: register-with-eureka: true fetch-registry: true serviceUrl: defaultZone: http://localhost:5061/eureka/,http://localhost:5062/eureka/ server: #实例,此时调用会失败,对于这个问题需要服务消费者端有一些容错机制,如重试、断路器等; enableSelfPreservation: false #扫描失效服务的间隔时间(单位是毫秒,摩恩是60*1000),即60s eviction-interval-timer-in-ms: 10000 --- spring: profiles: second server: port: 5061 eureka: instance: hostname: http://localhost:5060 preferIpAddress: true client: register-with-eureka: true fetch-registry: true serviceUrl: defaultZone: http://localhost:5060/eureka/,http://localhost:5062/eureka/ server: #实例,此时调用会失败,对于这个问题需要服务消费者端有一些容错机制,如重试、断路器等; enableSelfPreservation: false #扫描失效服务的间隔时间(单位是毫秒,摩恩是60*1000),即60s eviction-interval-timer-in-ms: 10000 --- spring: profiles: three server: port: 5062 eureka: instance: hostname: http://localhost:5060 preferIpAddress: true client: register-with-eureka: true fetch-registry: true serviceUrl: defaultZone: http://localhost:5060/eureka/,http://localhost:5061/eureka/ server: #实例,此时调用会失败,对于这个问题需要服务消费者端有一些容错机制,如重试、断路器等; enableSelfPreservation: false #扫描失效服务的间隔时间(单位是毫秒,摩恩是60*1000),即60s eviction-interval-timer-in-ms: 10000
分别启动:
- java -java xxx.jar -- --spring.profiles.active=first
- java -java xxx.jar -- --spring.profiles.active=two
- java -java xxx.jar -- --spring.profiles.active=three
2.先需要在pom.xml引入(以下是springboot2.0.X对应需要的jar包)
<dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>Finchley.SR1</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-openfeign</artifactId> </dependency>
3.提供者配置文件
#eureka配置
eureka:
client:
service-url:
defaultZone: http://localhost:5060/eureka/,http://localhost:5061/eureka/,http://localhost:5062/eureka/
instance:
hostname: dev
prefer-ip-address: true
instance-id: http:localhost:9091 #当前机器的IP最好是IP
feign:
hystrix:
enabled: true
# 关于springcloud-hystrix机制 http://www.jianshu.com/p/b8d21248c9b1
hystrix:
command:
default:
execution:
isolation:
strategy: SEMAPHORE #加上这个就可以获取到HttpServletRequest
thread:
timeoutInMilliseconds: 10000
ribbon: #配置这个为了本地Debug
ReadTimeout: 60000
ConnectTimeout: 60000
******************最好将localhost改为自己的IP**************************************