Browse Source

Merge branch 'dev' of chenweida/jw2.0 into dev

chenweida 8 years ago
parent
commit
54ada73c7b

+ 12 - 4
readme.MD

@ -1,11 +1,19 @@
项目结构
     common    公共的一些配置
        common-swagger   swagger工程
        涉及主要技术 swagger
     svr    业务微服务  
        svr-user 用户微服务
     svr-configuration    配置服务
     svr-discovery    发现服务
        涉及主要技术 euruka   
     svr-configuration    配置服务 
        涉及主要技术 git(存储配置文件) 
     svr-discovery    发现服务 
        涉及主要技术 euruka ribbon 
     svr-dashboard    监控服务 
        涉及主要技术 hystrix,hystrix-dashboard
     common-lib-parent-pom    common公共工程的maven父pom
     jw-lib-parent-pom   jw业务公共工程的maven父pom
     jw-lib-parent-pom   jw业务公共工程的maven父pom 
     web-gateway 对外的接口网关
     .gitignore   项目提交忽略配置文件
     .gitignore   项目提交忽略配置文件
     
     

+ 21 - 0
svr-configuration/readme.MD

@ -0,0 +1,21 @@
配置服务:
    存储:git
    地址:http://192.168.1.220:10080/jiwei/jw.config.git
    配置服务的优先级(左到右 高到低)
        git(svr-base.yml)->git(application.yml)->本地(application.yml)->本地(bootstrap.yml)
        注:1.如果以上配置有相同默认采取优先级高的 
    刷新当个微服务的配置
        地址:端口/refresh 
        例 localhost:8080/reflesh
    让微服务添加配置服务代码如下
        spring:
          #从发现服务里面取配置服务的信息
          cloud:
            config:
              username: jw
              password: jkzl
              discovery:
                enabled: true ##使用发现服务
                service-id: svr-configurations ##配置服务的名字
        

+ 5 - 4
svr-configuration/src/main/resources/application.yml

@ -1,4 +1,5 @@
server:
  port: 1221
##配置服务的账号密码
security:
@ -9,7 +10,7 @@ security:
---
spring:
  profiles: dev
  profiles: jwdev
eureka:
  client:
@ -19,7 +20,7 @@ eureka:
---
spring:
  profiles: test
  profiles: jwtest
eureka:
  client:
@ -28,7 +29,7 @@ eureka:
---
spring:
  profiles: prod
  profiles: jwprod
eureka:

+ 3 - 3
svr-configuration/src/main/resources/bootstrap.yml

@ -5,7 +5,7 @@ spring:
---
spring:
  profiles: dev
  profiles: jwdev
##git配置
  cloud:
    config:
@ -17,7 +17,7 @@ spring:
---
spring:
  profiles: test
  profiles: jwtest
##git配置
  cloud:
    config:
@ -28,7 +28,7 @@ spring:
---
spring:
  profiles: prod
  profiles: jwprod
##git配置
  cloud:
    config:

+ 69 - 0
svr-dashboard/pom.xml

@ -0,0 +1,69 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>com.yihu.jw</groupId>
        <artifactId>svr-lib-parent-pom</artifactId>
        <version>1.0.0</version>
        <relativePath>../svr-lib-parent-pom/pom.xml</relativePath>
    </parent>
    <groupId>com.yihu.jw</groupId>
    <artifactId>svr-dashboard</artifactId>
    <version>1.0-SNAPSHOT</version>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-aop</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-eureka</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-config</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-feign</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-hystrix</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-netflix-hystrix-dashboard</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-zuul</artifactId>
        </dependency>
    </dependencies>
</project>

+ 0 - 0
svr-dashboard/readme.MD


+ 26 - 0
svr-dashboard/src/main/java/com/yihu/jw/DashboardApplication.java

@ -0,0 +1,26 @@
package com.yihu.jw;
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.netflix.feign.EnableFeignClients;
import org.springframework.cloud.netflix.hystrix.EnableHystrix;
import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;
import org.springframework.cloud.netflix.zuul.EnableZuulProxy;
/**
 * Created by chenweida on 2017/5/16.
 */
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class})
//@SpringBootApplication
@EnableDiscoveryClient//服务注册到发现服务
@EnableHystrixDashboard //启动Hystrix仪表盘(监控数据)
@EnableFeignClients //声名式的客户端
public class DashboardApplication {
    public static void main(String[] args) {
        SpringApplication.run(DashboardApplication.class, args);
    }
}

+ 39 - 0
svr-dashboard/src/main/resources/application.yml

@ -0,0 +1,39 @@
##如果有配置服务的话,远程服务器和本地服务器配置不一致的情况下,优先远程的为主
spring:
  application:
    name:  svr-dashboard  ##注册到发现服务的id 如果id一样 eurika会自动做负载
---
spring:
  profiles: jwdev
eureka:
  client:
    serviceUrl:
      #http://账号:密码@127.0.0.1:8761/eureka/
      defaultZone: http://jw:jkzl@127.0.0.1:8761/eureka/
---
spring:
  profiles: jwtest
eureka:
  client:
    serviceUrl:
      #http://账号:密码@127.0.0.1:8761/eureka/
      defaultZone: http://jw:jkzl@127.0.0.1:8761/eureka/
---
spring:
  profiles: jwprod
eureka:
  client:
    serviceUrl:
      #http://账号:密码@127.0.0.1:8761/eureka/
      defaultZone: http://jw:jkzl@127.0.0.1:8761/eureka/

+ 6 - 0
svr-dashboard/src/main/resources/banner.txt

@ -0,0 +1,6 @@
 _____              _____            _     _                         _
  / ____|            |  __ \          | |   | |                       | |
 | (_____   ___ __   | |  | | __ _ ___| |__ | |__   ___   __ _ _ __ __| |
  \___ \ \ / / '__|  | |  | |/ _` / __| '_ \| '_ \ / _ \ / _` | '__/ _` |
  ____) \ V /| |     | |__| | (_| \__ \ | | | |_) | (_) | (_| | | | (_| |
 |_____/ \_/ |_|     |_____/ \__,_|___/_| |_|_.__/ \___/ \__,_|_|  \__,_|

+ 14 - 0
svr-discovery/readme.MD

@ -0,0 +1,14 @@
发现服务工程
    端口是8761
    如果有项目要注册到服务列表在yml中配置如下,
    eureka:
      client:
        serviceUrl:
          #http://账号:密码@127.0.0.1:8761/eureka/
          defaultZone: http://jw:jkzl@127.0.0.1:8761/eureka/
    注:
        1.以上配置只有写明注册地址,其他的euruka公用配置已经在配置中心(git)写好
        2.以上配置一般根据不同的环境配置
发现服务高可用的配置
    实现方法:
        启动多个发现服务,每个服务分别注册到对应的发现服务即可

+ 3 - 3
svr-discovery/src/main/resources/application.yml

@ -24,12 +24,12 @@ security:
---
spring:
  profiles: dev
  profiles: jwdev
---
spring:
  profiles: test
  profiles: jwtest
---
spring:
  profiles: prod
  profiles: jwprod

+ 6 - 6
svr/svr-base/src/main/resources/banner.txt

@ -1,6 +1,6 @@
  _____               _    _
  / ____|             | |  | |
 | (_____   ___ __    | |  | |___  ___ _ __
  \___ \ \ / / '__|   | |  | / __|/ _ \ '__|
  ____) \ V /| |      | |__| \__ \  __/ |
 |_____/ \_/ |_|       \____/|___/\___|_|
   _____              ____
  / ____|            |  _ \
 | (_____   ___ __   | |_) | __ _ ___  ___
  \___ \ \ / / '__|  |  _ < / _` / __|/ _ \
  ____) \ V /| |     | |_) | (_| \__ \  __/
 |_____/ \_/ |_|     |____/ \__,_|___/\___|

+ 0 - 4
web-gateway/pom.xml

@ -63,10 +63,6 @@
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-hystrix</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-netflix-hystrix-dashboard</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-zuul</artifactId>

+ 0 - 5
web-gateway/src/main/java/com/yihu/jw/WebGateWayAppliaction.java

@ -1,19 +1,15 @@
package com.yihu.jw;
import org.springframework.beans.factory.annotation.Autowired;
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;
import org.springframework.cloud.netflix.hystrix.EnableHystrix;
import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;
import org.springframework.cloud.netflix.zuul.EnableZuulProxy;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;
/**
 * Created by chenweida on 2017/5/10.
@ -22,7 +18,6 @@ import org.springframework.web.client.RestTemplate;
//@SpringBootApplication
@EnableDiscoveryClient//服务注册到发现服务
@EnableHystrix //启动断路器
@EnableHystrixDashboard //启动Hystrix仪表盘(监控数据)
@EnableZuulProxy //启动zuul代理 路由
@EnableFeignClients //声名式的客户端
@EnableCircuitBreaker

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

@ -6,6 +6,8 @@ import com.yihu.jw.fegin.PatientFegin;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
@ -19,6 +21,7 @@ import org.springframework.web.context.annotation.SessionScope;
@RequestMapping("/rest/patient")
@Api(description = "患者")
public class PatientController {
    private Logger logger= LoggerFactory.getLogger(PatientController.class);
    @Autowired
    private PatientFegin patientFegin;
@ -27,9 +30,16 @@ public class PatientController {
    //配置HystrixProperty 则调用的方法和fallback是同一个线程 否则就不是
    //@HystrixCommand(fallbackMethod = "findByCodeFallback",commandProperties = @HystrixProperty(name = "execution.isolation.strategy",value = "SEMAPHORE"))
//   @HystrixCommand(fallbackMethod = "findByCodeFallback" )
    @HystrixCommand(commandProperties = {
            @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "-1"),//超时时间
            @HystrixProperty(name = "execution.timeout.enabled", value = "false") })
    public String findByCode(
            @ApiParam(name = "code", value = "患者code", required = true) @RequestParam(value = "code", required = true) String code) {
        return patientFegin.findByCode(code);
        logger.info("start");
        String text1 =patientFegin.findByCode(code);
        logger.info("text");
        String text2 =patientFegin.findByCode(code);
        return text1+text2;
    }
//    /**

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

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

+ 7 - 8
web-gateway/src/main/resources/application.yml

@ -3,12 +3,11 @@ spring:
  application:
    name:  web-gateway  ##注册到发现服务的id 如果id一样 eurika会自动做负载
##开启feign断路器
feign:
  hystrix:
    enabled: true
##断路器
#hystrix:
#  metrics:
#    enabled: true
#    polling-interval-ms: 20000 ##熔断间隔时间 默认是2秒
#zuul 默认会代理所有的微服务  路径 /{appliction.name}/**
@ -34,12 +33,12 @@ zuul:
---
spring:
  profiles: dev
  profiles: jwdev
---
spring:
  profiles: test
  profiles: jwtest
---
spring:
  profiles: prod
  profiles: jwprod

+ 3 - 3
web-gateway/src/main/resources/bootstrap.yml

@ -12,7 +12,7 @@ spring:
---
spring:
  profiles: dev
  profiles: jwdev
eureka:
@ -23,7 +23,7 @@ eureka:
---
spring:
  profiles: test
  profiles: jwtest
eureka:
@ -35,7 +35,7 @@ eureka:
---
spring:
  profiles: prod
  profiles: jwprod
eureka: