Springboot2.0.X升级到SpringCloud详解及问题

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

分别启动:

  1. java -java  xxx.jar -- --spring.profiles.active=first
  2. java -java  xxx.jar -- --spring.profiles.active=two
  3. java -java  xxx.jar -- --spring.profiles.active=three

2.先需要在pom.xml引入(以下是springboot2.0.X对应需要的jar包)


    
        
            org.springframework.cloud
            spring-cloud-dependencies
            Finchley.SR1
            pom
            import
        
    



 org.springframework.cloud
 spring-cloud-starter-netflix-eureka-client



 org.springframework.cloud
 spring-cloud-starter-openfeign

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**************************************

你可能感兴趣的:(springcloud,eureka,feign)