ソースを参照

配置spring-cloud-config 利用kafka动态刷新配置

chenweida 7 年 前
コミット
119c383543

+ 12 - 0
svr-configuration/pom.xml

@ -36,9 +36,21 @@
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <!--动态刷新配置服务的配置-->
        <!--<dependency>-->
            <!--<groupId>org.springframework.cloud</groupId>-->
            <!--<artifactId>spring-cloud-starter-bus-kafka</artifactId>-->
            <!--<exclusions>-->
                <!--<exclusion>-->
                    <!--<groupId>org.apache.kafka</groupId>-->
                    <!--<artifactId>*</artifactId>-->
                <!--</exclusion>-->
            <!--</exclusions>-->
        <!--</dependency>-->
        <!--<dependency>-->
            <!--<groupId>org.apache.kafka</groupId>-->
            <!--<artifactId>kafka_2.10</artifactId>-->
            <!--<version>0.10.2.0</version>-->
        <!--</dependency>-->
        <!--<dependency>-->
            <!--<groupId>com.fasterxml.jackson.core</groupId>-->

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

@ -73,3 +73,10 @@ spring:
      server:
        native:
          search-locations: file:G:\idea_workspace\jkzl_git\jw.config  ##本地的got配置路径
    stream:
      kafka:
        binder:
          brokers: 172.17.110.201:9092
          zkNodes: 172.17.110.201:2181

+ 12 - 0
web-gateway/pom.xml

@ -80,9 +80,21 @@
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-sleuth-zipkin</artifactId>
        </dependency>
        <!--动态刷新配置服务的配置-->
        <!--<dependency>-->
            <!--<groupId>org.springframework.cloud</groupId>-->
            <!--<artifactId>spring-cloud-starter-bus-kafka</artifactId>-->
            <!--<exclusions>-->
                <!--<exclusion>-->
                    <!--<groupId>org.apache.kafka</groupId>-->
                    <!--<artifactId>*</artifactId>-->
                <!--</exclusion>-->
            <!--</exclusions>-->
        <!--</dependency>-->
        <!--<dependency>-->
            <!--<groupId>org.apache.kafka</groupId>-->
            <!--<artifactId>kafka_2.10</artifactId>-->
            <!--<version>0.10.2.0</version>-->
        <!--</dependency>-->
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>

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

@ -13,7 +13,10 @@ import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.cloud.sleuth.Tracer;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
@ -24,6 +27,7 @@ import javax.servlet.http.HttpServletRequest;
@RestController
@RequestMapping("/{version}/patient")
@Api(description = "患者")
//@RefreshScope
public class PatientController {
    private Logger logger = LoggerFactory.getLogger(PatientController.class);
    @Autowired
@ -32,6 +36,11 @@ public class PatientController {
    @Autowired
    private Tracer tracer;
//
//    @Value("${test.aaa}")
//    private String aaaa;
    @GetMapping("/hello")
    @ApiVersion(1)
    @ResponseBody
@ -59,6 +68,14 @@ public class PatientController {
        return "hello2";
    }
//    @GetMapping("/refresh")
//    @ApiVersion(0)
//    @ResponseBody
//    public String refresh(HttpServletRequest request) throws Exception {
//        return aaaa;
//    }
    @ApiOperation(value = "根据code查找患者")
    @GetMapping(value = "findByCode")
    //配置HystrixProperty 则调用的方法和fallback是同一个线程 否则就不是

+ 3 - 3
web-gateway/src/main/java/com/yihu/jw/controller/base/SaasController.java

@ -2,8 +2,8 @@ package com.yihu.jw.controller.base;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import com.yihu.jw.commnon.base.BaseContants;
import com.yihu.jw.fegin.base.SaasFegin;
import com.yihu.jw.restmodel.base.base.BaseContants;
import com.yihu.jw.restmodel.common.Envelop;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
@ -19,7 +19,7 @@ import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping(BaseContants.base_common)
@RequestMapping(BaseContants.Saas.api_common)
@Api(description = "saas相关")
public class SaasController {
@ -31,7 +31,7 @@ public class SaasController {
    private Tracer tracer;
    @GetMapping(value = BaseContants.Saas.api_getList)
    @GetMapping(value = BaseContants.Saas.api_getSaass)
    @ApiOperation(value = "获取saas,不分页")
    @HystrixCommand(commandProperties = {
            @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "-1"),//超时时间

+ 1 - 1
web-gateway/src/main/java/com/yihu/jw/fegin/base/SaasFegin.java

@ -1,7 +1,7 @@
package com.yihu.jw.fegin.base;
import com.yihu.jw.fegin.fallbackfactory.base.SaasFeginFallbackFactory;
import com.yihu.jw.restmodel.base.BaseContants;
import com.yihu.jw.restmodel.base.base.BaseContants;
import com.yihu.jw.restmodel.common.CommonContants;
import com.yihu.jw.restmodel.common.Envelop;
import org.springframework.cloud.netflix.feign.FeignClient;