chenweida 8 éve
szülő
commit
17d395afa8

+ 1 - 12
svr-configuration/src/main/resources/application.yml

@ -1,17 +1,6 @@
server:
  port: 1221
eureka:
  client:
    healthcheck:
      enabled: true #启动监控检查
  instance:
    #eurika使用IP不使用host
    prefer-ip-address: true
    #定制化在eurika中显示的名称
    instance-id: ${spring.application.name}:${spring.application.instance_id:${server.port}}
##配置服务的账号密码
security:
  user:
    name: jw

+ 0 - 1
svr-configuration/src/main/resources/bootstrap.yml

@ -3,7 +3,6 @@ spring:
    name: svr-configurations
---
spring:
  profiles: dev

+ 0 - 14
svr/svr-base/src/main/resources/application.yml

@ -1,22 +1,8 @@
##如果有配置服务的话,远程服务器和本地服务器配置不一致的情况下,优先远程的为主  git上 svr-base ->  git application ->本地 appliction ->本地 bootstarp
server:
  port: 10020
spring:
  application:
    name:  svr-base  ##注册到发现服务的id 如果id一样 eurika会自动做负载
eureka:
  client:
    healthcheck:
      enabled: true #启动监控检查
  instance:
    #eurika使用IP不使用host
    prefer-ip-address: true
    #定制化在eurika中显示的名称
    instance-id: ${spring.application.name}:${spring.application.instance_id:${server.port}}
---
spring:

+ 1 - 1
svr/svr-base/src/main/resources/bootstrap.yml

@ -14,7 +14,7 @@ spring:
spring:
  profiles: dev
##发现服务的地址
eureka:
  client:
    serviceUrl:

+ 7 - 5
web-gateway/src/main/java/com/yihu/jw/Application.java

@ -5,6 +5,7 @@ import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.netflix.feign.EnableFeignClients;
@ -17,16 +18,17 @@ import org.springframework.web.client.RestTemplate;
/**
 * Created by chenweida on 2017/5/10.
 */
//@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class})
@SpringBootApplication
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class})
//@SpringBootApplication
@EnableDiscoveryClient//服务注册到发现服务
@EnableFeignClients //声名式的客户端
@EnableHystrix //启动断路器
@EnableHystrixDashboard //启动Hystrix仪表盘(监控数据)
@EnableZuulProxy //启动zuul代理 路由
public class Application {
@EnableFeignClients //声名式的客户端
@EnableCircuitBreaker
public class WebGateWayAppliaction {
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
        SpringApplication.run(WebGateWayAppliaction.class, args);
    }
}

+ 1 - 1
web-gateway/src/main/java/com/yihu/jw/controller/PatientController.java

@ -26,7 +26,7 @@ public class PatientController {
    @GetMapping(value = "findByCode")
    //配置HystrixProperty 则调用的方法和fallback是同一个线程 否则就不是
    //@HystrixCommand(fallbackMethod = "findByCodeFallback",commandProperties = @HystrixProperty(name = "execution.isolation.strategy",value = "SEMAPHORE"))
    @HystrixCommand(fallbackMethod = "findByCodeFallback" )
    //@HystrixCommand(fallbackMethod = "findByCodeFallback" )
    public String findByCode(
            @ApiParam(name = "code", value = "患者code", required = true) @RequestParam(value = "code", required = true) String code) {
        return patientFegin.findByCode(code);

+ 2 - 6
web-gateway/src/main/java/com/yihu/jw/fegin/PatientFegin.java

@ -1,10 +1,7 @@
package com.yihu.jw.fegin;
import com.yihu.jw.fegin.fallback.PatientFeginFallback;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
@ -13,14 +10,13 @@ import org.springframework.web.bind.annotation.RequestParam;
 * Created by chenweida on 2017/5/10.
 */
@FeignClient(
        name = "svr-user", // name值是eurika的实例名字
        name = "svr-base", // name值是eurika的实例名字
        fallback = PatientFeginFallback.class// fallback是请求超时或者错误的回调函数
//        ,configuration =   //可以配置当个fegin的配置 例如禁用单个feign的hystrix
    )
@RequestMapping("/patient")
public interface PatientFegin {
    @RequestMapping(value = "/findByCode", method = RequestMethod.GET)
    @RequestMapping(value = "/patient/findByCode", method = RequestMethod.GET)
    public String findByCode(@RequestParam(value = "code", required = true) String code);
}

+ 4 - 3
web-gateway/src/main/java/com/yihu/jw/fegin/fallback/PatientFeginFallback.java

@ -8,9 +8,10 @@ import org.springframework.web.bind.annotation.RequestParam;
 * Created by chenweida on 2017/5/13.
 */
@Component
public class PatientFeginFallback implements PatientFegin{
public class PatientFeginFallback implements PatientFegin {
    @Override
    public String findByCode(@RequestParam(value = "code", required = true) String code) {
        return "";
    public String findByCode(String code) {
        return "断路器启动";
    }
}

+ 1 - 26
web-gateway/src/main/resources/application.yml

@ -1,33 +1,10 @@
##如果有配置服务的话,远程服务器和本地服务器配置不一致的情况下,优先远程的为主
server:
server:
  port: 8088
spring:
  application:
    name:  web-gateway  ##注册到发现服务的id 如果id一样 eurika会自动做负载
  cloud:
    config:
      enabled: false    ##是否加入配置服务
eureka:
  client:
    serviceUrl:
      #http://账号:密码@127.0.0.1:8761/eureka/
      defaultZone: http://user:123456@127.0.0.1:8761/eureka/
    healthcheck:
      enabled: true #启动监控检查
  instance:
    #eurika使用IP不使用host
    prefer-ip-address: true
    #定制化在eurika中显示的名称
    instance-id: ${spring.application.name}:${spring.application.instance_id:${server.port}}
##断路器
hystrix:
  metrics:
    polling-interval-ms: 20000 ##熔断间隔时间 默认是2秒 
@ -36,8 +13,6 @@ hystrix:
#zuul 默认会代理所有的微服务  路径 /{appliction.name}/**
zuul:
  ignored-services: '*'  ##忽略全部的代理  忽略单个微服务   ignored-services: svr-user 多个逗号分割
  routes:

+ 33 - 22
web-gateway/src/main/resources/bootstrap.yml

@ -1,36 +1,47 @@
##优先读取 boostarap配置 然后在读取application。yml的配置
##boostarap一般是配置基本不会修改的配置
spring:
  application:
    name: web-gateway  ##写这个配置的话 会先去服务器找web-gateway.yml的配置 没有的话就找application.yml
  #从发现服务里面取配置服务的信息
  cloud:
    config:
      username: jw
      password: jkzl
      discovery:
        enabled: true ##使用发现服务
        service-id: svr-configurations ##配置服务的名字
---
spring:
  profiles: dev
  cloud:
    config:
      username: jw
      password: jkzljw
      uri: http://127.0.0.1:1221
      #uri: http://192.168.1.221:1221
      label: dev
eureka:
  client:
    serviceUrl:
      #http://账号:密码@127.0.0.1:8761/eureka/
      defaultZone: http://jw:jkzl@127.0.0.1:8761/eureka/
---
spring:
  profiles: test
  cloud:
    config:
      username: jw
      password: jkzljw
      uri: http://172.19.103.73:1221
      label: dev
eureka:
  client:
    serviceUrl:
      #http://账号:密码@127.0.0.1:8761/eureka/
      defaultZone: http://jw:jkzl@127.0.0.1:8761/eureka/
---
spring:
  profiles: prod
  cloud:
    config:
      username: jw
      password: jkzljw
      uri: http://11.1.2.21:1221
      label: master
eureka:
  client:
    serviceUrl:
      #http://账号:密码@127.0.0.1:8761/eureka/
      defaultZone: http://jw:jkzl@127.0.0.1:8761/eureka/