From f40c8892e80d84ec542652e927c8960f4018e5ea Mon Sep 17 00:00:00 2001 From: itliusir Date: Mon, 9 Apr 2018 13:33:59 +0800 Subject: [PATCH] init project --- .gitignore | 24 ++ README.md | 257 ++++++++++++++++++ hystrix-dashboard/.gitignore | 25 ++ hystrix-dashboard/mvnw | 225 +++++++++++++++ hystrix-dashboard/mvnw.cmd | 143 ++++++++++ hystrix-dashboard/pom.xml | 69 +++++ .../yss/ms/HystrixDashboardApplication.java | 23 ++ .../src/main/resources/application.yml | 26 ++ .../HystrixDashboardApplicationTests.java | 16 ++ ms-common/.gitignore | 24 ++ ms-common/README.md | 121 +++++++++ ms-common/mvnw | 225 +++++++++++++++ ms-common/mvnw.cmd | 143 ++++++++++ ms-common/pom.xml | 33 +++ .../src/main/java/com/yss/ms/entity/User.java | 24 ++ .../com/yss/ms/exception/BaseException.java | 45 +++ .../ms/handler/GlobalExceptionHandler.java | 62 +++++ .../java/com/yss/ms/msg/BaseResponse.java | 33 +++ .../com/yss/ms/msg/ObjectRestResponse.java | 21 ++ ms-platform-center/.gitignore | 24 ++ ms-platform-center/pom.xml | 49 ++++ .../com/yss/ms/center/CenterBootstrap.java | 14 + .../src/main/resources/application.yml | 14 + ms-sidecar/.gitignore | 24 ++ ms-sidecar/mvnw | 225 +++++++++++++++ ms-sidecar/mvnw.cmd | 143 ++++++++++ ms-sidecar/pom.xml | 216 +++++++++++++++ .../java/com/yss/ms/MsSidecarApplication.java | 14 + ms-sidecar/src/main/resources/application.yml | 43 +++ .../com/yss/ms/MsSidecarApplicationTests.java | 16 ++ pom.xml | 109 ++++++++ service-consumer/.gitignore | 25 ++ service-consumer/mvnw | 225 +++++++++++++++ service-consumer/mvnw.cmd | 143 ++++++++++ service-consumer/pom.xml | 67 +++++ .../yss/ms/ServiceConsumerApplication.java | 39 +++ .../com/yss/ms/feign/IServiceProvider.java | 35 +++ .../com/yss/ms/feign/IServiceSideCar.java | 17 ++ .../com/yss/ms/rest/ConsumerController.java | 100 +++++++ .../src/main/resources/application.yml | 42 +++ .../ServiceConsumerApplicationTests.java | 16 ++ service-provider/.gitignore | 25 ++ service-provider/mvnw | 225 +++++++++++++++ service-provider/mvnw.cmd | 143 ++++++++++ service-provider/pom.xml | 64 +++++ .../yss/ms/ServiceProviderApplication.java | 37 +++ .../com/yss/ms/rest/ProviderController.java | 34 +++ .../src/main/resources/application.yml | 41 +++ .../ServiceProviderApplicationTests.java | 16 ++ zuul-server/.gitignore | 25 ++ zuul-server/mvnw | 225 +++++++++++++++ zuul-server/mvnw.cmd | 143 ++++++++++ zuul-server/pom.xml | 54 ++++ .../com/yss/ms/ZuulServerApplication.java | 16 ++ .../java/com/yss/ms/filter/AuthFilter.java | 55 ++++ .../com/yss/ms/filter/RatelimitFilter.java | 31 +++ .../src/main/resources/application.yml | 52 ++++ .../ZuulServerApplicationTests.java | 16 ++ 58 files changed, 4341 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 hystrix-dashboard/.gitignore create mode 100644 hystrix-dashboard/mvnw create mode 100644 hystrix-dashboard/mvnw.cmd create mode 100644 hystrix-dashboard/pom.xml create mode 100644 hystrix-dashboard/src/main/java/com/yss/ms/HystrixDashboardApplication.java create mode 100644 hystrix-dashboard/src/main/resources/application.yml create mode 100644 hystrix-dashboard/src/test/java/com/yss/ms/hystrixdashboard/HystrixDashboardApplicationTests.java create mode 100644 ms-common/.gitignore create mode 100644 ms-common/README.md create mode 100644 ms-common/mvnw create mode 100644 ms-common/mvnw.cmd create mode 100644 ms-common/pom.xml create mode 100644 ms-common/src/main/java/com/yss/ms/entity/User.java create mode 100644 ms-common/src/main/java/com/yss/ms/exception/BaseException.java create mode 100644 ms-common/src/main/java/com/yss/ms/handler/GlobalExceptionHandler.java create mode 100644 ms-common/src/main/java/com/yss/ms/msg/BaseResponse.java create mode 100644 ms-common/src/main/java/com/yss/ms/msg/ObjectRestResponse.java create mode 100644 ms-platform-center/.gitignore create mode 100644 ms-platform-center/pom.xml create mode 100644 ms-platform-center/src/main/java/com/yss/ms/center/CenterBootstrap.java create mode 100644 ms-platform-center/src/main/resources/application.yml create mode 100644 ms-sidecar/.gitignore create mode 100644 ms-sidecar/mvnw create mode 100644 ms-sidecar/mvnw.cmd create mode 100644 ms-sidecar/pom.xml create mode 100644 ms-sidecar/src/main/java/com/yss/ms/MsSidecarApplication.java create mode 100644 ms-sidecar/src/main/resources/application.yml create mode 100644 ms-sidecar/src/test/java/com/yss/ms/MsSidecarApplicationTests.java create mode 100644 pom.xml create mode 100644 service-consumer/.gitignore create mode 100644 service-consumer/mvnw create mode 100644 service-consumer/mvnw.cmd create mode 100644 service-consumer/pom.xml create mode 100644 service-consumer/src/main/java/com/yss/ms/ServiceConsumerApplication.java create mode 100644 service-consumer/src/main/java/com/yss/ms/feign/IServiceProvider.java create mode 100644 service-consumer/src/main/java/com/yss/ms/feign/IServiceSideCar.java create mode 100644 service-consumer/src/main/java/com/yss/ms/rest/ConsumerController.java create mode 100644 service-consumer/src/main/resources/application.yml create mode 100644 service-consumer/src/test/java/com/yss/ms/serviceconsumer/ServiceConsumerApplicationTests.java create mode 100644 service-provider/.gitignore create mode 100644 service-provider/mvnw create mode 100644 service-provider/mvnw.cmd create mode 100644 service-provider/pom.xml create mode 100644 service-provider/src/main/java/com/yss/ms/ServiceProviderApplication.java create mode 100644 service-provider/src/main/java/com/yss/ms/rest/ProviderController.java create mode 100644 service-provider/src/main/resources/application.yml create mode 100644 service-provider/src/test/java/com/yss/ms/serviceprovider/ServiceProviderApplicationTests.java create mode 100644 zuul-server/.gitignore create mode 100644 zuul-server/mvnw create mode 100644 zuul-server/mvnw.cmd create mode 100644 zuul-server/pom.xml create mode 100644 zuul-server/src/main/java/com/yss/ms/ZuulServerApplication.java create mode 100644 zuul-server/src/main/java/com/yss/ms/filter/AuthFilter.java create mode 100644 zuul-server/src/main/java/com/yss/ms/filter/RatelimitFilter.java create mode 100644 zuul-server/src/main/resources/application.yml create mode 100644 zuul-server/src/test/java/com/yss/ms/zuulserver/ZuulServerApplicationTests.java diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2af7cef --- /dev/null +++ b/.gitignore @@ -0,0 +1,24 @@ +target/ +!.mvn/wrapper/maven-wrapper.jar + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +nbproject/private/ +build/ +nbbuild/ +dist/ +nbdist/ +.nb-gradle/ \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..6383ed3 --- /dev/null +++ b/README.md @@ -0,0 +1,257 @@ +# `Spring Cloud Netflix OSS` + +## Spring Cloud Eureka + +提供了对`Netflix`开源项目的集成,使我们可以以Spring Boot编程风格使用`Netflix`旗下相关框架,只需要在程序里添加注解,就可以使用成熟的`Netflix`组件(`Eureka`、`Hystrix`、`Zuul`、`Ribbon`、`Sidecar`) + +### Eureka客户端 + +- 向`Eureka`注册服务 + +- 高可用(HA) + + - 多注册中心主机 + + 如果配置了多个Eureka注册服务器,那么默认情况只有一台可用的服务器,存在注册信息。如果Down掉了,则会选择下一台可用的Eureka服务器。 + +- 配置 + + - 应用间隔 + + `registry-fetch-interval-seconds: `30 去服务端获取注册信息的间隔时间 + + - 同步间隔 + + `instance-info-replication-interval-seconds: `30 更新实例信息的变化到服务端的间隔时间 + + [参考链接](http://cloud.spring.io/spring-cloud-static/Dalston.SR4/single/spring-cloud.html#_appendix_compendium_of_configuration_properties) + +- 注意 + + - 端口不要使用0 + - Eureka缓存 + 1. Eureka Server对注册列表进行缓存,默认时间为30s。 + 2. Eureka Client对获取到的注册信息进行缓存,默认时间为30s。 + 3. Ribbon会从上面提到的Eureka Client获取服务列表,将负载均衡后的结果缓存30s。 + +### Eureka服务端 + +![img](http://ok0qzthrb.bkt.clouddn.com/Eureka.png) + +- 注册中心对比 + +| `Feature` | [Consul](https://github.com/hashicorp/consul) | [zookeeper](https://github.com/apache/zookeeper) | [etcd](https://github.com/coreos/etcd) | [euerka](https://github.com/Netflix/eureka) | +| :------------: | :--------------------------------------: | :--------------------------------------: | :------------------------------------: | :--------------------------------------: | +| 服务健康检查 | 服务状态,内存,硬盘等 | (弱)长连接,`keepalive` | 连接心跳 | 可配支持 | +| 多数据中心 | 支持 | — | — | — | +| kv存储服务 | 支持 | 支持 | 支持 | — | +| 一致性 | `raft` | `paxos` | `raft` | — | +| `cap` | `ca` | `cp` | `cp` | `ap` | +| 使用接口(多语言能力) | 支持`http`和`dns` | 客户端 | `http/grpc` | `http`(sidecar) | +| watch支持 | 全量/支持long polling | 支持 | 支持 long polling | 支持 long polling/大部分增量 | +| 自身监控 | `metrics` | — | `metrics` | `metrics` | +| 安全 | `acl /https` | `acl` | `https`支持(弱) | — | +| spring cloud集成 | 已支持 | 已支持 | 已支持 | 已支持 | + +- CAP + + - *C* **数据一致性** 一致性是指数据的原子性,在经典的数据库中通过事务来保障,事务完成时,无论成功或回滚,数据都会处于一致的状态,在分布式环境下,一致性是指多个节点数据是否一致 + + [raft](http://thesecretlivesofdata.com/raft/) + + - *A* **服务可用性** 服务一直保持可用的状态,当用户发出一个请求,服务能在一定的时间内返回结果 + + - *P* **网络分区故障的容错性** 在分布式应用中,可能因为一些分布式的原因导致系统无法运转,好的分区容忍性,使应用虽然是一个分布式系统,但是好像一个可以正常运转的整体 + +- Consul + + - 服务发现 + - 健康检查 + - 键值存储 + - 多数据中心 + + [官网](https://www.consul.io/intro/index.html) + + [Spring Cloud Consul 参考文档](http://cloud.spring.io/spring-cloud-consul/) + +- Eureka Server高可用配置 + + ```yaml + --- + spring: + profiles: peer1 + eureka: + instance: + hostname: peer1 + client: + serviceUrl: + defaultZone: http://peer2/eureka/ + + --- + spring: + profiles: peer2 + eureka: + instance: + hostname: peer2 + client: + serviceUrl: + defaultZone: http://peer1/eureka/ + ``` + + [参考文档](http://cloud.spring.io/spring-cloud-static/Dalston.SR4/single/spring-cloud.html#_peer_awareness) + +## Spring Cloud Ribbon + +主要功能是为REST客户端实现负载均衡 + +### Netflix Ribbon + +- 依赖 + + ```xml + + org.springframework.cloud + spring-cloud-starter-ribbon + + ``` + +- Ribbon 客户端 + + ```java + @SpringBootApplication + @RibbonClients({ + @RibbonClient(name = "service-provider") + }) + public class Application { + @Bean + public RestTemplate restTemplate(){ + return new RestTemplate(); + } + } + ``` + +- 配置 + + `application.properties` + + ```properties + service-provider.ribbon.listOfServers = \ + http://${host}:${port} + ``` + +### Netflix Ribbon 整合 Eureka + +- Ribbon 客户端 + + ```java + @SpringBootApplication + @RibbonClients({ + @RibbonClient(name = "service-provider") + }) + @EnableDiscoveryClient + public class Application { + @Bean + @LoadBalanced + public RestTemplate restTemplate(){ + return new RestTemplate(); + } + } + ``` + +- 配置 + +## Spring Cloud OpenFeign + +- 发展 + + 9.0.0版本之后groupId `io.netflix.feign`更改为`io.github.openfeign` + + 对应依赖`spring-cloud-starter-feign`-->`spring-cloud-starter-openfeign` + +- 依赖 + + ```xml + + org.springframework.cloud + spring-cloud-starter-feign + + ``` + +- feign 客户端 + + `Application.java` + + ```java + @SpringBootApplication + @EnableFeignClients + public class Application { + + public static void main(String[] args) { + SpringApplication.run(Application.class, args); + } + + } + ``` + + `feignClient.java` + + ```java + @FeignClient(value = "ms-business-task-engine-server") + public interface ITaskEngineService { + @RequestMapping(value = "/TaskQueue/addTaskToQueue",method = RequestMethod.POST) + BaseResponse addTaskToQueue(@RequestBody List subTaskDTOList); + } + + ``` + +- 配置参考ribbon + +## Spring Cloud Hystrix + +hystrix可帮助隔离每个服务,使单个服务的响应失败,避免微服务架构中因个别服务出现异常而引起级联故障蔓延。 + +### 特性 + +- 断路器机制(断路-->半开-->恢复) +- 资源隔离 +- 熔断降级 + +### Hystrix Dashboard 监控 + +## Spring Cloud Zuul + +在没有网关的时候,随着系统不断庞大,运维维护越来越复杂,接口校验逻辑的冗余越来越多,校验逻辑升级更为复杂。 + +### ZuulFilter + +#### 过滤器类型 + +* pre 路由之前执行 +* route 路由请求时被调用 +* post 在route和error过滤器之后被过滤 +* error 处理请求发生错误时候被调用 + +#### 过滤器执行顺序 + +- order越小,优先级越高 + +#### 过滤器是否被执行 + +- shouldFilter = true(结合yaml控制开启) + +#### 过滤器具体逻辑 + +- run() + +### Routes + +路由规则与列表 + +## Spring Cloud Sidecar + +### 非JVM语言接入SpringCloud的两种方案 + +- Sidecar + - 必须去实现一个健康检查接口 + - 只有状态,服务治理只能从网关层控制流量 +- 自己实现注册中心API Http接口(推荐) \ No newline at end of file diff --git a/hystrix-dashboard/.gitignore b/hystrix-dashboard/.gitignore new file mode 100644 index 0000000..82eca33 --- /dev/null +++ b/hystrix-dashboard/.gitignore @@ -0,0 +1,25 @@ +/target/ +!.mvn/wrapper/maven-wrapper.jar + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/build/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ \ No newline at end of file diff --git a/hystrix-dashboard/mvnw b/hystrix-dashboard/mvnw new file mode 100644 index 0000000..5bf251c --- /dev/null +++ b/hystrix-dashboard/mvnw @@ -0,0 +1,225 @@ +#!/bin/sh +# ---------------------------------------------------------------------------- +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# ---------------------------------------------------------------------------- + +# ---------------------------------------------------------------------------- +# Maven2 Start Up Batch script +# +# Required ENV vars: +# ------------------ +# JAVA_HOME - location of a JDK home dir +# +# Optional ENV vars +# ----------------- +# M2_HOME - location of maven2's installed home dir +# MAVEN_OPTS - parameters passed to the Java VM when running Maven +# e.g. to debug Maven itself, use +# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +# MAVEN_SKIP_RC - flag to disable loading of mavenrc files +# ---------------------------------------------------------------------------- + +if [ -z "$MAVEN_SKIP_RC" ] ; then + + if [ -f /etc/mavenrc ] ; then + . /etc/mavenrc + fi + + if [ -f "$HOME/.mavenrc" ] ; then + . "$HOME/.mavenrc" + fi + +fi + +# OS specific support. $var _must_ be set to either true or false. +cygwin=false; +darwin=false; +mingw=false +case "`uname`" in + CYGWIN*) cygwin=true ;; + MINGW*) mingw=true;; + Darwin*) darwin=true + # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home + # See https://developer.apple.com/library/mac/qa/qa1170/_index.html + if [ -z "$JAVA_HOME" ]; then + if [ -x "/usr/libexec/java_home" ]; then + export JAVA_HOME="`/usr/libexec/java_home`" + else + export JAVA_HOME="/Library/Java/Home" + fi + fi + ;; +esac + +if [ -z "$JAVA_HOME" ] ; then + if [ -r /etc/gentoo-release ] ; then + JAVA_HOME=`java-config --jre-home` + fi +fi + +if [ -z "$M2_HOME" ] ; then + ## resolve links - $0 may be a link to maven's home + PRG="$0" + + # need this for relative symlinks + while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG="`dirname "$PRG"`/$link" + fi + done + + saveddir=`pwd` + + M2_HOME=`dirname "$PRG"`/.. + + # make it fully qualified + M2_HOME=`cd "$M2_HOME" && pwd` + + cd "$saveddir" + # echo Using m2 at $M2_HOME +fi + +# For Cygwin, ensure paths are in UNIX format before anything is touched +if $cygwin ; then + [ -n "$M2_HOME" ] && + M2_HOME=`cygpath --unix "$M2_HOME"` + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --unix "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --unix "$CLASSPATH"` +fi + +# For Migwn, ensure paths are in UNIX format before anything is touched +if $mingw ; then + [ -n "$M2_HOME" ] && + M2_HOME="`(cd "$M2_HOME"; pwd)`" + [ -n "$JAVA_HOME" ] && + JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" + # TODO classpath? +fi + +if [ -z "$JAVA_HOME" ]; then + javaExecutable="`which javac`" + if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then + # readlink(1) is not available as standard on Solaris 10. + readLink=`which readlink` + if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then + if $darwin ; then + javaHome="`dirname \"$javaExecutable\"`" + javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" + else + javaExecutable="`readlink -f \"$javaExecutable\"`" + fi + javaHome="`dirname \"$javaExecutable\"`" + javaHome=`expr "$javaHome" : '\(.*\)/bin'` + JAVA_HOME="$javaHome" + export JAVA_HOME + fi + fi +fi + +if [ -z "$JAVACMD" ] ; then + if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + else + JAVACMD="`which java`" + fi +fi + +if [ ! -x "$JAVACMD" ] ; then + echo "Error: JAVA_HOME is not defined correctly." >&2 + echo " We cannot execute $JAVACMD" >&2 + exit 1 +fi + +if [ -z "$JAVA_HOME" ] ; then + echo "Warning: JAVA_HOME environment variable is not set." +fi + +CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher + +# traverses directory structure from process work directory to filesystem root +# first directory with .mvn subdirectory is considered project base directory +find_maven_basedir() { + + if [ -z "$1" ] + then + echo "Path not specified to find_maven_basedir" + return 1 + fi + + basedir="$1" + wdir="$1" + while [ "$wdir" != '/' ] ; do + if [ -d "$wdir"/.mvn ] ; then + basedir=$wdir + break + fi + # workaround for JBEAP-8937 (on Solaris 10/Sparc) + if [ -d "${wdir}" ]; then + wdir=`cd "$wdir/.."; pwd` + fi + # end of workaround + done + echo "${basedir}" +} + +# concatenates all lines of a file +concat_lines() { + if [ -f "$1" ]; then + echo "$(tr -s '\n' ' ' < "$1")" + fi +} + +BASE_DIR=`find_maven_basedir "$(pwd)"` +if [ -z "$BASE_DIR" ]; then + exit 1; +fi + +export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} +echo $MAVEN_PROJECTBASEDIR +MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" + +# For Cygwin, switch paths to Windows format before running java +if $cygwin; then + [ -n "$M2_HOME" ] && + M2_HOME=`cygpath --path --windows "$M2_HOME"` + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --windows "$CLASSPATH"` + [ -n "$MAVEN_PROJECTBASEDIR" ] && + MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` +fi + +WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +exec "$JAVACMD" \ + $MAVEN_OPTS \ + -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ + "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ + ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" diff --git a/hystrix-dashboard/mvnw.cmd b/hystrix-dashboard/mvnw.cmd new file mode 100644 index 0000000..019bd74 --- /dev/null +++ b/hystrix-dashboard/mvnw.cmd @@ -0,0 +1,143 @@ +@REM ---------------------------------------------------------------------------- +@REM Licensed to the Apache Software Foundation (ASF) under one +@REM or more contributor license agreements. See the NOTICE file +@REM distributed with this work for additional information +@REM regarding copyright ownership. The ASF licenses this file +@REM to you under the Apache License, Version 2.0 (the +@REM "License"); you may not use this file except in compliance +@REM with the License. You may obtain a copy of the License at +@REM +@REM http://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, +@REM software distributed under the License is distributed on an +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@REM KIND, either express or implied. See the License for the +@REM specific language governing permissions and limitations +@REM under the License. +@REM ---------------------------------------------------------------------------- + +@REM ---------------------------------------------------------------------------- +@REM Maven2 Start Up Batch script +@REM +@REM Required ENV vars: +@REM JAVA_HOME - location of a JDK home dir +@REM +@REM Optional ENV vars +@REM M2_HOME - location of maven2's installed home dir +@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands +@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending +@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven +@REM e.g. to debug Maven itself, use +@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files +@REM ---------------------------------------------------------------------------- + +@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' +@echo off +@REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' +@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% + +@REM set %HOME% to equivalent of $HOME +if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") + +@REM Execute a user defined script before this one +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre +@REM check for pre script, once with legacy .bat ending and once with .cmd ending +if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" +if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" +:skipRcPre + +@setlocal + +set ERROR_CODE=0 + +@REM To isolate internal variables from possible post scripts, we use another setlocal +@setlocal + +@REM ==== START VALIDATION ==== +if not "%JAVA_HOME%" == "" goto OkJHome + +echo. +echo Error: JAVA_HOME not found in your environment. >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +:OkJHome +if exist "%JAVA_HOME%\bin\java.exe" goto init + +echo. +echo Error: JAVA_HOME is set to an invalid directory. >&2 +echo JAVA_HOME = "%JAVA_HOME%" >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +@REM ==== END VALIDATION ==== + +:init + +@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". +@REM Fallback to current working directory if not found. + +set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% +IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir + +set EXEC_DIR=%CD% +set WDIR=%EXEC_DIR% +:findBaseDir +IF EXIST "%WDIR%"\.mvn goto baseDirFound +cd .. +IF "%WDIR%"=="%CD%" goto baseDirNotFound +set WDIR=%CD% +goto findBaseDir + +:baseDirFound +set MAVEN_PROJECTBASEDIR=%WDIR% +cd "%EXEC_DIR%" +goto endDetectBaseDir + +:baseDirNotFound +set MAVEN_PROJECTBASEDIR=%EXEC_DIR% +cd "%EXEC_DIR%" + +:endDetectBaseDir + +IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig + +@setlocal EnableExtensions EnableDelayedExpansion +for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a +@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% + +:endReadAdditionalConfig + +SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" + +set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" +set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* +if ERRORLEVEL 1 goto error +goto end + +:error +set ERROR_CODE=1 + +:end +@endlocal & set ERROR_CODE=%ERROR_CODE% + +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost +@REM check for post script, once with legacy .bat ending and once with .cmd ending +if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" +if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" +:skipRcPost + +@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' +if "%MAVEN_BATCH_PAUSE%" == "on" pause + +if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% + +exit /B %ERROR_CODE% diff --git a/hystrix-dashboard/pom.xml b/hystrix-dashboard/pom.xml new file mode 100644 index 0000000..aebbc25 --- /dev/null +++ b/hystrix-dashboard/pom.xml @@ -0,0 +1,69 @@ + + + + ms-base-security + com.yss.ms + 1.0-SNAPSHOT + + 4.0.0 + + hystrix-dashboard + war + + hystrix-dashboard + Demo project for Spring Boot + + + UTF-8 + UTF-8 + 1.8 + + + + + org.springframework.boot + spring-boot-starter-actuator + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.cloud + spring-cloud-starter-eureka + + + org.springframework.cloud + spring-cloud-starter-hystrix + + + org.springframework.cloud + spring-cloud-starter-hystrix-dashboard + + + org.springframework.cloud + spring-cloud-starter-turbine + + + org.springframework.cloud + spring-cloud-netflix-turbine + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + + diff --git a/hystrix-dashboard/src/main/java/com/yss/ms/HystrixDashboardApplication.java b/hystrix-dashboard/src/main/java/com/yss/ms/HystrixDashboardApplication.java new file mode 100644 index 0000000..0b4272b --- /dev/null +++ b/hystrix-dashboard/src/main/java/com/yss/ms/HystrixDashboardApplication.java @@ -0,0 +1,23 @@ +package com.yss.ms; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard; +import org.springframework.cloud.netflix.turbine.EnableTurbine; + +/** + * Dashboard + * + * {@link `http://localhost:9100/turbine.stream`} + * @author liugang + * @since 2018-04-08 + */ +@SpringBootApplication +@EnableHystrixDashboard +@EnableTurbine +public class HystrixDashboardApplication { + + public static void main(String[] args) { + SpringApplication.run(HystrixDashboardApplication.class, args); + } +} diff --git a/hystrix-dashboard/src/main/resources/application.yml b/hystrix-dashboard/src/main/resources/application.yml new file mode 100644 index 0000000..f5d03c5 --- /dev/null +++ b/hystrix-dashboard/src/main/resources/application.yml @@ -0,0 +1,26 @@ +server: + port: 9100 + +spring: + application: + name: hystrix-dashboard-turbine +management: + security: + enabled: false +info: + app: + name: hystrix-dashboard-turbine + version: 1.0 +eureka: + instance: + statusPageUrlPath: /hystrix + healthCheckUrlPath: /health + prefer-ip-address: true + ip-address: 127.0.0.1 + client: + serviceUrl: + defaultZone: http://127.0.0.1:8761/eureka/ + registry-fetch-interval-seconds: 30 +turbine: + app-config: service-consumer,service-provider + cluster-name-expression: new String("default") \ No newline at end of file diff --git a/hystrix-dashboard/src/test/java/com/yss/ms/hystrixdashboard/HystrixDashboardApplicationTests.java b/hystrix-dashboard/src/test/java/com/yss/ms/hystrixdashboard/HystrixDashboardApplicationTests.java new file mode 100644 index 0000000..1ee7f72 --- /dev/null +++ b/hystrix-dashboard/src/test/java/com/yss/ms/hystrixdashboard/HystrixDashboardApplicationTests.java @@ -0,0 +1,16 @@ +package com.yss.ms.hystrixdashboard; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@SpringBootTest +public class HystrixDashboardApplicationTests { + + @Test + public void contextLoads() { + } + +} diff --git a/ms-common/.gitignore b/ms-common/.gitignore new file mode 100644 index 0000000..2af7cef --- /dev/null +++ b/ms-common/.gitignore @@ -0,0 +1,24 @@ +target/ +!.mvn/wrapper/maven-wrapper.jar + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +nbproject/private/ +build/ +nbbuild/ +dist/ +nbdist/ +.nb-gradle/ \ No newline at end of file diff --git a/ms-common/README.md b/ms-common/README.md new file mode 100644 index 0000000..cda36b5 --- /dev/null +++ b/ms-common/README.md @@ -0,0 +1,121 @@ +# RPAS基础Common层(迭代中...) + +- **主要根据业务层次的增删改查对JPA做了一层封装** +- **对异常进行统一处理** +- **对返回信息的统一封装** +- **工具类和异常码的定义** +- **通用条件查询的封装** + +--------- + +# Doc + +## 打包(稳定后再传私服) + +```shell + 1. git clone http://1.119.186.147:8085/3.0/Robot/ms-rpas/ms-rpas-common + 2. 项目根目录下执行mvn clean install +``` + +## 依赖层 + +```xml + + com.yss.ms + ms-rpas-common + 1.0-SNAPSHOT + +``` + +## 条件查询Doc + +### Rest层 + +`POST:http://ip:port/demo/page?pageNum=1&pageSize=10` + +`Body`体: + +```json + [ + { + "paramKey":"activitiId", + "paramValue":"activiti1", + "condition":"EQUAL" + } + ] +``` + +`Body`参数介绍: +- `paramKey`: 属性名 +- `paramValue`: 属性值 +- `condition`: 参数条件 + +参数条件目前支持类型: + +```java + public enum ParamCondition { + + /** + * 等于 + * */ + EQUAL, + /** + * 大于 + * */ + GREATERTHAN, + /** + * 小于 + * */ + LESSTHAN, + /** + * 模糊查询 + * */ + LIKE, + /** + * 大于等于 + * */ + GREATERTHANEQUAL, + /** + * 小于等于 + * */ + LESSTHANEQUAL + } +``` + +### Service/Biz层 + +- 带分页参数 + +```java + Page pageBean = xxxBiz.findByCondition(pageNum,pageSize,selectParams); +``` + +- 不带分页参数(用于服务调用数据筛选) + +```java + List list = xxxBiz.findByCondition(selectParams); +``` +## Entity层 + +```java + @EqualsAndHashCode(callSuper = true) + @Entity + @Table(name = "t_task_info") + @Data + @DynamicUpdate + @DynamicInsert + public class TaskInfo extends BaseEntity implements Serializable {} +``` + +## Dao层 + +```java + public interface TaskInfoRepository extends BaseJpaRepository {} +``` + +## Service层 + +```java + @Service + public class TaskMgmentBiz extends BaseService{} +``` \ No newline at end of file diff --git a/ms-common/mvnw b/ms-common/mvnw new file mode 100644 index 0000000..5bf251c --- /dev/null +++ b/ms-common/mvnw @@ -0,0 +1,225 @@ +#!/bin/sh +# ---------------------------------------------------------------------------- +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# ---------------------------------------------------------------------------- + +# ---------------------------------------------------------------------------- +# Maven2 Start Up Batch script +# +# Required ENV vars: +# ------------------ +# JAVA_HOME - location of a JDK home dir +# +# Optional ENV vars +# ----------------- +# M2_HOME - location of maven2's installed home dir +# MAVEN_OPTS - parameters passed to the Java VM when running Maven +# e.g. to debug Maven itself, use +# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +# MAVEN_SKIP_RC - flag to disable loading of mavenrc files +# ---------------------------------------------------------------------------- + +if [ -z "$MAVEN_SKIP_RC" ] ; then + + if [ -f /etc/mavenrc ] ; then + . /etc/mavenrc + fi + + if [ -f "$HOME/.mavenrc" ] ; then + . "$HOME/.mavenrc" + fi + +fi + +# OS specific support. $var _must_ be set to either true or false. +cygwin=false; +darwin=false; +mingw=false +case "`uname`" in + CYGWIN*) cygwin=true ;; + MINGW*) mingw=true;; + Darwin*) darwin=true + # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home + # See https://developer.apple.com/library/mac/qa/qa1170/_index.html + if [ -z "$JAVA_HOME" ]; then + if [ -x "/usr/libexec/java_home" ]; then + export JAVA_HOME="`/usr/libexec/java_home`" + else + export JAVA_HOME="/Library/Java/Home" + fi + fi + ;; +esac + +if [ -z "$JAVA_HOME" ] ; then + if [ -r /etc/gentoo-release ] ; then + JAVA_HOME=`java-config --jre-home` + fi +fi + +if [ -z "$M2_HOME" ] ; then + ## resolve links - $0 may be a link to maven's home + PRG="$0" + + # need this for relative symlinks + while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG="`dirname "$PRG"`/$link" + fi + done + + saveddir=`pwd` + + M2_HOME=`dirname "$PRG"`/.. + + # make it fully qualified + M2_HOME=`cd "$M2_HOME" && pwd` + + cd "$saveddir" + # echo Using m2 at $M2_HOME +fi + +# For Cygwin, ensure paths are in UNIX format before anything is touched +if $cygwin ; then + [ -n "$M2_HOME" ] && + M2_HOME=`cygpath --unix "$M2_HOME"` + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --unix "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --unix "$CLASSPATH"` +fi + +# For Migwn, ensure paths are in UNIX format before anything is touched +if $mingw ; then + [ -n "$M2_HOME" ] && + M2_HOME="`(cd "$M2_HOME"; pwd)`" + [ -n "$JAVA_HOME" ] && + JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" + # TODO classpath? +fi + +if [ -z "$JAVA_HOME" ]; then + javaExecutable="`which javac`" + if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then + # readlink(1) is not available as standard on Solaris 10. + readLink=`which readlink` + if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then + if $darwin ; then + javaHome="`dirname \"$javaExecutable\"`" + javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" + else + javaExecutable="`readlink -f \"$javaExecutable\"`" + fi + javaHome="`dirname \"$javaExecutable\"`" + javaHome=`expr "$javaHome" : '\(.*\)/bin'` + JAVA_HOME="$javaHome" + export JAVA_HOME + fi + fi +fi + +if [ -z "$JAVACMD" ] ; then + if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + else + JAVACMD="`which java`" + fi +fi + +if [ ! -x "$JAVACMD" ] ; then + echo "Error: JAVA_HOME is not defined correctly." >&2 + echo " We cannot execute $JAVACMD" >&2 + exit 1 +fi + +if [ -z "$JAVA_HOME" ] ; then + echo "Warning: JAVA_HOME environment variable is not set." +fi + +CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher + +# traverses directory structure from process work directory to filesystem root +# first directory with .mvn subdirectory is considered project base directory +find_maven_basedir() { + + if [ -z "$1" ] + then + echo "Path not specified to find_maven_basedir" + return 1 + fi + + basedir="$1" + wdir="$1" + while [ "$wdir" != '/' ] ; do + if [ -d "$wdir"/.mvn ] ; then + basedir=$wdir + break + fi + # workaround for JBEAP-8937 (on Solaris 10/Sparc) + if [ -d "${wdir}" ]; then + wdir=`cd "$wdir/.."; pwd` + fi + # end of workaround + done + echo "${basedir}" +} + +# concatenates all lines of a file +concat_lines() { + if [ -f "$1" ]; then + echo "$(tr -s '\n' ' ' < "$1")" + fi +} + +BASE_DIR=`find_maven_basedir "$(pwd)"` +if [ -z "$BASE_DIR" ]; then + exit 1; +fi + +export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} +echo $MAVEN_PROJECTBASEDIR +MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" + +# For Cygwin, switch paths to Windows format before running java +if $cygwin; then + [ -n "$M2_HOME" ] && + M2_HOME=`cygpath --path --windows "$M2_HOME"` + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --windows "$CLASSPATH"` + [ -n "$MAVEN_PROJECTBASEDIR" ] && + MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` +fi + +WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +exec "$JAVACMD" \ + $MAVEN_OPTS \ + -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ + "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ + ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" diff --git a/ms-common/mvnw.cmd b/ms-common/mvnw.cmd new file mode 100644 index 0000000..019bd74 --- /dev/null +++ b/ms-common/mvnw.cmd @@ -0,0 +1,143 @@ +@REM ---------------------------------------------------------------------------- +@REM Licensed to the Apache Software Foundation (ASF) under one +@REM or more contributor license agreements. See the NOTICE file +@REM distributed with this work for additional information +@REM regarding copyright ownership. The ASF licenses this file +@REM to you under the Apache License, Version 2.0 (the +@REM "License"); you may not use this file except in compliance +@REM with the License. You may obtain a copy of the License at +@REM +@REM http://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, +@REM software distributed under the License is distributed on an +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@REM KIND, either express or implied. See the License for the +@REM specific language governing permissions and limitations +@REM under the License. +@REM ---------------------------------------------------------------------------- + +@REM ---------------------------------------------------------------------------- +@REM Maven2 Start Up Batch script +@REM +@REM Required ENV vars: +@REM JAVA_HOME - location of a JDK home dir +@REM +@REM Optional ENV vars +@REM M2_HOME - location of maven2's installed home dir +@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands +@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending +@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven +@REM e.g. to debug Maven itself, use +@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files +@REM ---------------------------------------------------------------------------- + +@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' +@echo off +@REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' +@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% + +@REM set %HOME% to equivalent of $HOME +if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") + +@REM Execute a user defined script before this one +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre +@REM check for pre script, once with legacy .bat ending and once with .cmd ending +if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" +if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" +:skipRcPre + +@setlocal + +set ERROR_CODE=0 + +@REM To isolate internal variables from possible post scripts, we use another setlocal +@setlocal + +@REM ==== START VALIDATION ==== +if not "%JAVA_HOME%" == "" goto OkJHome + +echo. +echo Error: JAVA_HOME not found in your environment. >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +:OkJHome +if exist "%JAVA_HOME%\bin\java.exe" goto init + +echo. +echo Error: JAVA_HOME is set to an invalid directory. >&2 +echo JAVA_HOME = "%JAVA_HOME%" >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +@REM ==== END VALIDATION ==== + +:init + +@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". +@REM Fallback to current working directory if not found. + +set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% +IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir + +set EXEC_DIR=%CD% +set WDIR=%EXEC_DIR% +:findBaseDir +IF EXIST "%WDIR%"\.mvn goto baseDirFound +cd .. +IF "%WDIR%"=="%CD%" goto baseDirNotFound +set WDIR=%CD% +goto findBaseDir + +:baseDirFound +set MAVEN_PROJECTBASEDIR=%WDIR% +cd "%EXEC_DIR%" +goto endDetectBaseDir + +:baseDirNotFound +set MAVEN_PROJECTBASEDIR=%EXEC_DIR% +cd "%EXEC_DIR%" + +:endDetectBaseDir + +IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig + +@setlocal EnableExtensions EnableDelayedExpansion +for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a +@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% + +:endReadAdditionalConfig + +SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" + +set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" +set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* +if ERRORLEVEL 1 goto error +goto end + +:error +set ERROR_CODE=1 + +:end +@endlocal & set ERROR_CODE=%ERROR_CODE% + +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost +@REM check for post script, once with legacy .bat ending and once with .cmd ending +if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" +if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" +:skipRcPost + +@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' +if "%MAVEN_BATCH_PAUSE%" == "on" pause + +if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% + +exit /B %ERROR_CODE% diff --git a/ms-common/pom.xml b/ms-common/pom.xml new file mode 100644 index 0000000..d92913d --- /dev/null +++ b/ms-common/pom.xml @@ -0,0 +1,33 @@ + + + + + ms-base-security + com.yss.ms + 1.0-SNAPSHOT + + 4.0.0 + ms-common + jar + + + UTF-8 + UTF-8 + 1.8 + + + + + org.springframework.boot + spring-boot-starter-web + + + + org.apache.commons + commons-lang3 + 3.3.2 + + + + diff --git a/ms-common/src/main/java/com/yss/ms/entity/User.java b/ms-common/src/main/java/com/yss/ms/entity/User.java new file mode 100644 index 0000000..747015a --- /dev/null +++ b/ms-common/src/main/java/com/yss/ms/entity/User.java @@ -0,0 +1,24 @@ +package com.yss.ms.entity; + +import lombok.Data; + +import java.io.Serializable; + +/** + * TODO + * + * @author liugang + * @since 2018-04-08 + */ +@Data +public class User implements Serializable{ + + + private static final long serialVersionUID = 6741489822065785659L; + + private Integer id; + private String name; + private Integer age; + private Integer port; + +} diff --git a/ms-common/src/main/java/com/yss/ms/exception/BaseException.java b/ms-common/src/main/java/com/yss/ms/exception/BaseException.java new file mode 100644 index 0000000..38db9b3 --- /dev/null +++ b/ms-common/src/main/java/com/yss/ms/exception/BaseException.java @@ -0,0 +1,45 @@ +package com.yss.ms.exception; + + +/** + * 自定义异常 + * + * @author liugang + * @since 2018-03-07 + */ +public class BaseException extends RuntimeException { + private static final long serialVersionUID = -6095912560004884357L; + private int status = 200; + + public int getStatus() { + return status; + } + + public void setStatus(int status) { + this.status = status; + } + + public BaseException() { + } + + public BaseException(String message, int status) { + super(message); + this.status = status; + } + + public BaseException(String message) { + super(message); + } + + public BaseException(String message, Throwable cause) { + super(message, cause); + } + + public BaseException(Throwable cause) { + super(cause); + } + + public BaseException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { + super(message, cause, enableSuppression, writableStackTrace); + } +} diff --git a/ms-common/src/main/java/com/yss/ms/handler/GlobalExceptionHandler.java b/ms-common/src/main/java/com/yss/ms/handler/GlobalExceptionHandler.java new file mode 100644 index 0000000..9c6950b --- /dev/null +++ b/ms-common/src/main/java/com/yss/ms/handler/GlobalExceptionHandler.java @@ -0,0 +1,62 @@ +package com.yss.ms.handler; + +import com.yss.ms.exception.BaseException; +import com.yss.ms.msg.BaseResponse; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.validation.BindingResult; +import org.springframework.validation.FieldError; +import org.springframework.web.bind.MethodArgumentNotValidException; +import org.springframework.web.bind.annotation.ControllerAdvice; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.ResponseBody; + +import javax.servlet.http.HttpServletResponse; + +/** + * 统一异常的处理 + * + * @author liugang + * @since 2018-03-07 + */ +/* +@ControllerAdvice +@ResponseBody +public class GlobalExceptionHandler { + private Logger logger = LoggerFactory.getLogger(GlobalExceptionHandler.class); + @ExceptionHandler(BaseException.class) + public BaseResponse baseExceptionHandler(HttpServletResponse response, BaseException ex) { + logger.error(ex.getMessage(),ex); + return new BaseResponse(ex.getStatus(),ex.getMessage()); + } + + @ExceptionHandler(Exception.class) + public BaseResponse otherExceptionHandler(HttpServletResponse response, Exception ex) { + logger.error(ex.getMessage(),ex); + return new BaseResponse(HttpStatus.INTERNAL_SERVER_ERROR.value(), ex.getMessage()); + } + + */ +/** + * 参数校验产生的异常 + * + * @author liugang 2018-01-01 16:28 + * *//* + + @ExceptionHandler(MethodArgumentNotValidException.class) + public BaseResponse validExceptionHandler(HttpServletResponse response, MethodArgumentNotValidException ex) { + BindingResult bindingResult = ex.getBindingResult(); + StringBuffer stringBuffer = new StringBuffer(); + if(bindingResult.hasErrors()){ + for (FieldError fieldError : bindingResult.getFieldErrors()) { + //该格式仅仅作为response展示和log作用,前端应自己做校验 + stringBuffer.append(fieldError.getObjectName() + "--" + fieldError.getDefaultMessage() + " "); + } + } + logger.error(stringBuffer.toString()); + return new BaseResponse(HttpStatus.BAD_REQUEST.value(), stringBuffer.toString()); + } +} +*/ diff --git a/ms-common/src/main/java/com/yss/ms/msg/BaseResponse.java b/ms-common/src/main/java/com/yss/ms/msg/BaseResponse.java new file mode 100644 index 0000000..bc9ad17 --- /dev/null +++ b/ms-common/src/main/java/com/yss/ms/msg/BaseResponse.java @@ -0,0 +1,33 @@ +package com.yss.ms.msg; + + +public class BaseResponse { + private int status = 200; + private String message = "success"; + + public BaseResponse(int status, String message) { + this.status = status; + this.message = message; + } + + public BaseResponse() { + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public int getStatus() { + return status; + } + + public void setStatus(int status) { + this.status = status; + } + + +} diff --git a/ms-common/src/main/java/com/yss/ms/msg/ObjectRestResponse.java b/ms-common/src/main/java/com/yss/ms/msg/ObjectRestResponse.java new file mode 100644 index 0000000..19ed8d0 --- /dev/null +++ b/ms-common/src/main/java/com/yss/ms/msg/ObjectRestResponse.java @@ -0,0 +1,21 @@ +package com.yss.ms.msg; + + +public class ObjectRestResponse extends BaseResponse { + + T data; + + public ObjectRestResponse data(T data) { + this.setData(data); + return this; + } + public T getData() { + return data; + } + + public void setData(T data) { + this.data = data; + } + + +} diff --git a/ms-platform-center/.gitignore b/ms-platform-center/.gitignore new file mode 100644 index 0000000..2af7cef --- /dev/null +++ b/ms-platform-center/.gitignore @@ -0,0 +1,24 @@ +target/ +!.mvn/wrapper/maven-wrapper.jar + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +nbproject/private/ +build/ +nbbuild/ +dist/ +nbdist/ +.nb-gradle/ \ No newline at end of file diff --git a/ms-platform-center/pom.xml b/ms-platform-center/pom.xml new file mode 100644 index 0000000..6a409fd --- /dev/null +++ b/ms-platform-center/pom.xml @@ -0,0 +1,49 @@ + + + + ms-base-security + com.yss.ms + 1.0-SNAPSHOT + + 4.0.0 + + ms-platform-center + + 1.5.12 + + + + + + org.springframework.cloud + spring-cloud-starter-eureka-server + + + org.springframework.boot + spring-boot-starter-actuator + + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + war + + diff --git a/ms-platform-center/src/main/java/com/yss/ms/center/CenterBootstrap.java b/ms-platform-center/src/main/java/com/yss/ms/center/CenterBootstrap.java new file mode 100644 index 0000000..c18cf05 --- /dev/null +++ b/ms-platform-center/src/main/java/com/yss/ms/center/CenterBootstrap.java @@ -0,0 +1,14 @@ +package com.yss.ms.center; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; + + +@EnableEurekaServer +@SpringBootApplication +public class CenterBootstrap { + public static void main(String[] args) { + SpringApplication.run(CenterBootstrap.class, args); + } +} diff --git a/ms-platform-center/src/main/resources/application.yml b/ms-platform-center/src/main/resources/application.yml new file mode 100644 index 0000000..04a9dd0 --- /dev/null +++ b/ms-platform-center/src/main/resources/application.yml @@ -0,0 +1,14 @@ +spring: + application: + name: ms-platform-center + +server: + port: 8761 #启动端口 + +eureka: + client: + registerWithEureka: false #false:不作为一个客户端注册到注册中心 + fetchRegistry: false + server: + enable-self-preservation: false + eviction-interval-timer-in-ms: 4000 diff --git a/ms-sidecar/.gitignore b/ms-sidecar/.gitignore new file mode 100644 index 0000000..2af7cef --- /dev/null +++ b/ms-sidecar/.gitignore @@ -0,0 +1,24 @@ +target/ +!.mvn/wrapper/maven-wrapper.jar + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +nbproject/private/ +build/ +nbbuild/ +dist/ +nbdist/ +.nb-gradle/ \ No newline at end of file diff --git a/ms-sidecar/mvnw b/ms-sidecar/mvnw new file mode 100644 index 0000000..5bf251c --- /dev/null +++ b/ms-sidecar/mvnw @@ -0,0 +1,225 @@ +#!/bin/sh +# ---------------------------------------------------------------------------- +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# ---------------------------------------------------------------------------- + +# ---------------------------------------------------------------------------- +# Maven2 Start Up Batch script +# +# Required ENV vars: +# ------------------ +# JAVA_HOME - location of a JDK home dir +# +# Optional ENV vars +# ----------------- +# M2_HOME - location of maven2's installed home dir +# MAVEN_OPTS - parameters passed to the Java VM when running Maven +# e.g. to debug Maven itself, use +# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +# MAVEN_SKIP_RC - flag to disable loading of mavenrc files +# ---------------------------------------------------------------------------- + +if [ -z "$MAVEN_SKIP_RC" ] ; then + + if [ -f /etc/mavenrc ] ; then + . /etc/mavenrc + fi + + if [ -f "$HOME/.mavenrc" ] ; then + . "$HOME/.mavenrc" + fi + +fi + +# OS specific support. $var _must_ be set to either true or false. +cygwin=false; +darwin=false; +mingw=false +case "`uname`" in + CYGWIN*) cygwin=true ;; + MINGW*) mingw=true;; + Darwin*) darwin=true + # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home + # See https://developer.apple.com/library/mac/qa/qa1170/_index.html + if [ -z "$JAVA_HOME" ]; then + if [ -x "/usr/libexec/java_home" ]; then + export JAVA_HOME="`/usr/libexec/java_home`" + else + export JAVA_HOME="/Library/Java/Home" + fi + fi + ;; +esac + +if [ -z "$JAVA_HOME" ] ; then + if [ -r /etc/gentoo-release ] ; then + JAVA_HOME=`java-config --jre-home` + fi +fi + +if [ -z "$M2_HOME" ] ; then + ## resolve links - $0 may be a link to maven's home + PRG="$0" + + # need this for relative symlinks + while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG="`dirname "$PRG"`/$link" + fi + done + + saveddir=`pwd` + + M2_HOME=`dirname "$PRG"`/.. + + # make it fully qualified + M2_HOME=`cd "$M2_HOME" && pwd` + + cd "$saveddir" + # echo Using m2 at $M2_HOME +fi + +# For Cygwin, ensure paths are in UNIX format before anything is touched +if $cygwin ; then + [ -n "$M2_HOME" ] && + M2_HOME=`cygpath --unix "$M2_HOME"` + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --unix "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --unix "$CLASSPATH"` +fi + +# For Migwn, ensure paths are in UNIX format before anything is touched +if $mingw ; then + [ -n "$M2_HOME" ] && + M2_HOME="`(cd "$M2_HOME"; pwd)`" + [ -n "$JAVA_HOME" ] && + JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" + # TODO classpath? +fi + +if [ -z "$JAVA_HOME" ]; then + javaExecutable="`which javac`" + if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then + # readlink(1) is not available as standard on Solaris 10. + readLink=`which readlink` + if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then + if $darwin ; then + javaHome="`dirname \"$javaExecutable\"`" + javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" + else + javaExecutable="`readlink -f \"$javaExecutable\"`" + fi + javaHome="`dirname \"$javaExecutable\"`" + javaHome=`expr "$javaHome" : '\(.*\)/bin'` + JAVA_HOME="$javaHome" + export JAVA_HOME + fi + fi +fi + +if [ -z "$JAVACMD" ] ; then + if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + else + JAVACMD="`which java`" + fi +fi + +if [ ! -x "$JAVACMD" ] ; then + echo "Error: JAVA_HOME is not defined correctly." >&2 + echo " We cannot execute $JAVACMD" >&2 + exit 1 +fi + +if [ -z "$JAVA_HOME" ] ; then + echo "Warning: JAVA_HOME environment variable is not set." +fi + +CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher + +# traverses directory structure from process work directory to filesystem root +# first directory with .mvn subdirectory is considered project base directory +find_maven_basedir() { + + if [ -z "$1" ] + then + echo "Path not specified to find_maven_basedir" + return 1 + fi + + basedir="$1" + wdir="$1" + while [ "$wdir" != '/' ] ; do + if [ -d "$wdir"/.mvn ] ; then + basedir=$wdir + break + fi + # workaround for JBEAP-8937 (on Solaris 10/Sparc) + if [ -d "${wdir}" ]; then + wdir=`cd "$wdir/.."; pwd` + fi + # end of workaround + done + echo "${basedir}" +} + +# concatenates all lines of a file +concat_lines() { + if [ -f "$1" ]; then + echo "$(tr -s '\n' ' ' < "$1")" + fi +} + +BASE_DIR=`find_maven_basedir "$(pwd)"` +if [ -z "$BASE_DIR" ]; then + exit 1; +fi + +export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} +echo $MAVEN_PROJECTBASEDIR +MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" + +# For Cygwin, switch paths to Windows format before running java +if $cygwin; then + [ -n "$M2_HOME" ] && + M2_HOME=`cygpath --path --windows "$M2_HOME"` + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --windows "$CLASSPATH"` + [ -n "$MAVEN_PROJECTBASEDIR" ] && + MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` +fi + +WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +exec "$JAVACMD" \ + $MAVEN_OPTS \ + -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ + "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ + ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" diff --git a/ms-sidecar/mvnw.cmd b/ms-sidecar/mvnw.cmd new file mode 100644 index 0000000..019bd74 --- /dev/null +++ b/ms-sidecar/mvnw.cmd @@ -0,0 +1,143 @@ +@REM ---------------------------------------------------------------------------- +@REM Licensed to the Apache Software Foundation (ASF) under one +@REM or more contributor license agreements. See the NOTICE file +@REM distributed with this work for additional information +@REM regarding copyright ownership. The ASF licenses this file +@REM to you under the Apache License, Version 2.0 (the +@REM "License"); you may not use this file except in compliance +@REM with the License. You may obtain a copy of the License at +@REM +@REM http://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, +@REM software distributed under the License is distributed on an +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@REM KIND, either express or implied. See the License for the +@REM specific language governing permissions and limitations +@REM under the License. +@REM ---------------------------------------------------------------------------- + +@REM ---------------------------------------------------------------------------- +@REM Maven2 Start Up Batch script +@REM +@REM Required ENV vars: +@REM JAVA_HOME - location of a JDK home dir +@REM +@REM Optional ENV vars +@REM M2_HOME - location of maven2's installed home dir +@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands +@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending +@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven +@REM e.g. to debug Maven itself, use +@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files +@REM ---------------------------------------------------------------------------- + +@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' +@echo off +@REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' +@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% + +@REM set %HOME% to equivalent of $HOME +if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") + +@REM Execute a user defined script before this one +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre +@REM check for pre script, once with legacy .bat ending and once with .cmd ending +if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" +if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" +:skipRcPre + +@setlocal + +set ERROR_CODE=0 + +@REM To isolate internal variables from possible post scripts, we use another setlocal +@setlocal + +@REM ==== START VALIDATION ==== +if not "%JAVA_HOME%" == "" goto OkJHome + +echo. +echo Error: JAVA_HOME not found in your environment. >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +:OkJHome +if exist "%JAVA_HOME%\bin\java.exe" goto init + +echo. +echo Error: JAVA_HOME is set to an invalid directory. >&2 +echo JAVA_HOME = "%JAVA_HOME%" >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +@REM ==== END VALIDATION ==== + +:init + +@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". +@REM Fallback to current working directory if not found. + +set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% +IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir + +set EXEC_DIR=%CD% +set WDIR=%EXEC_DIR% +:findBaseDir +IF EXIST "%WDIR%"\.mvn goto baseDirFound +cd .. +IF "%WDIR%"=="%CD%" goto baseDirNotFound +set WDIR=%CD% +goto findBaseDir + +:baseDirFound +set MAVEN_PROJECTBASEDIR=%WDIR% +cd "%EXEC_DIR%" +goto endDetectBaseDir + +:baseDirNotFound +set MAVEN_PROJECTBASEDIR=%EXEC_DIR% +cd "%EXEC_DIR%" + +:endDetectBaseDir + +IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig + +@setlocal EnableExtensions EnableDelayedExpansion +for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a +@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% + +:endReadAdditionalConfig + +SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" + +set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" +set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* +if ERRORLEVEL 1 goto error +goto end + +:error +set ERROR_CODE=1 + +:end +@endlocal & set ERROR_CODE=%ERROR_CODE% + +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost +@REM check for post script, once with legacy .bat ending and once with .cmd ending +if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" +if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" +:skipRcPost + +@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' +if "%MAVEN_BATCH_PAUSE%" == "on" pause + +if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% + +exit /B %ERROR_CODE% diff --git a/ms-sidecar/pom.xml b/ms-sidecar/pom.xml new file mode 100644 index 0000000..63c7a38 --- /dev/null +++ b/ms-sidecar/pom.xml @@ -0,0 +1,216 @@ + + + + ms-base-security + com.yss.ms + 1.0-SNAPSHOT + + 4.0.0 + + ms-sidecar + + + UTF-8 + UTF-8 + 1.8 + + + + + org.springframework.boot + spring-boot-starter-actuator + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-test + test + + + org.springframework.cloud + spring-cloud-starter-eureka + + + + org.springframework.cloud + spring-cloud-starter-feign + + + + org.springframework.cloud + spring-cloud-starter-hystrix + + + + org.springframework.cloud + spring-cloud-netflix-sidecar + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.8 + 1.8 + UTF-8 + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + war + + + window + + true + + + + unix + + + + maven-antrun-plugin + + + package + package + + run + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + pre-integration-test + pre-integration-test + + run + + + + + + + + + + + + + + + + cobertura + + + + org.codehaus.mojo + cobertura-maven-plugin + 2.7 + + + html + xml + + + + + + + + findbugs + + + + org.codehaus.mojo + findbugs-maven-plugin + 3.0.5 + + + High + Default + true + + + target/site/findbugs/ + + + + + + + jmeter + + + + com.lazerycode.jmeter + jmeter-maven-plugin + 2.2.0 + + + jmeter-tests + verify + + jmeter + + + + agent.jmx + + + + + + + + + + + \ No newline at end of file diff --git a/ms-sidecar/src/main/java/com/yss/ms/MsSidecarApplication.java b/ms-sidecar/src/main/java/com/yss/ms/MsSidecarApplication.java new file mode 100644 index 0000000..d861393 --- /dev/null +++ b/ms-sidecar/src/main/java/com/yss/ms/MsSidecarApplication.java @@ -0,0 +1,14 @@ +package com.yss.ms; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.netflix.sidecar.EnableSidecar; + +@EnableSidecar +@SpringBootApplication +public class MsSidecarApplication { + + public static void main(String[] args) { + SpringApplication.run(MsSidecarApplication.class, args); + } +} diff --git a/ms-sidecar/src/main/resources/application.yml b/ms-sidecar/src/main/resources/application.yml new file mode 100644 index 0000000..e84a40c --- /dev/null +++ b/ms-sidecar/src/main/resources/application.yml @@ -0,0 +1,43 @@ +server: + port: 8914 +sidecar: + port: 8090 + health-uri: http://localhost:${sidecar.port}/health + home-page-uri: http://localhost:${sidecar.port}/ +spring: + application: + name: ms-sidecar +management: + security: + enabled: false + +info: + app: + name: C# 服务代理 + version: 1.0 + +eureka: + instance: + statusPageUrlPath: /info + healthCheckUrlPath: /health + prefer-ip-address: true + ip-address: 127.0.0.1 + client: + serviceUrl: + defaultZone: http://127.0.0.1:8761/eureka/ +hystrix: + command: + default: + execution: + isolation: + thread: + timeoutInMilliseconds: 20000 # Hystrix的超时时间是对次节点的请求时间的进行熔断 + strategy: THREAD + +ribbon: + ReadTimeout: 20000 # 处理时间 + ConnectTimeout: 20000 # 连接时间 + MaxAutoRetries: 0 # 最大自动重试次数 + MaxAutoRetriesNextServer: 1 # 换实例重试次数 + MaxTotalHttpConnections: 2000 # 最大http连接数,越大越好,但到到达一个临界点之后,就不会提高响应速度了 + MaxConnectionsPerHost: 1000 # 每个host连接数 \ No newline at end of file diff --git a/ms-sidecar/src/test/java/com/yss/ms/MsSidecarApplicationTests.java b/ms-sidecar/src/test/java/com/yss/ms/MsSidecarApplicationTests.java new file mode 100644 index 0000000..e326bde --- /dev/null +++ b/ms-sidecar/src/test/java/com/yss/ms/MsSidecarApplicationTests.java @@ -0,0 +1,16 @@ +package com.yss.ms; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@SpringBootTest +public class MsSidecarApplicationTests { + + @Test + public void contextLoads() { + } + +} diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..a4f4f85 --- /dev/null +++ b/pom.xml @@ -0,0 +1,109 @@ + + + 4.0.0 + + com.yss.ms + ms-base-security + 1.0-SNAPSHOT + + + Apache 2 + http://www.apache.org/licenses/LICENSE-2.0.txt + repo + A business-friendly OSS license + + + + org.springframework.boot + spring-boot-starter-parent + 1.5.6.RELEASE + + + 1.8 + ${basedir} + 1.5.6.RELEASE + Dalston.SR3 + 1.5.5 + 0.7.9 + 4.3.0 + 1.6 + 1.5.5 + 1.6.0 + 2.2.2 + ag + 0.4.13 + 3.4.0 + -Dfile.encoding=UTF-8 + + + hystrix-dashboard + ms-common + ms-platform-center + service-consumer + ms-sidecar + service-provider + zuul-server + + + + + maven-compiler-plugin + + 1.8 + 1.8 + + + + + + + + + com.netflix.hystrix + hystrix-dashboard + ${hystrix-dashboard.version} + + + org.springframework.boot + spring-boot-dependencies + ${spring-boot.version} + pom + import + + + org.springframework.cloud + spring-cloud-dependencies + ${spring-cloud.version} + pom + import + + + com.alibaba + fastjson + 1.2.33 + + + com.alibaba + druid + 1.0.11 + + + + + + + pom + + + + + org.projectlombok + lombok + 1.16.14 + provided + + + + \ No newline at end of file diff --git a/service-consumer/.gitignore b/service-consumer/.gitignore new file mode 100644 index 0000000..82eca33 --- /dev/null +++ b/service-consumer/.gitignore @@ -0,0 +1,25 @@ +/target/ +!.mvn/wrapper/maven-wrapper.jar + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/build/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ \ No newline at end of file diff --git a/service-consumer/mvnw b/service-consumer/mvnw new file mode 100644 index 0000000..5bf251c --- /dev/null +++ b/service-consumer/mvnw @@ -0,0 +1,225 @@ +#!/bin/sh +# ---------------------------------------------------------------------------- +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# ---------------------------------------------------------------------------- + +# ---------------------------------------------------------------------------- +# Maven2 Start Up Batch script +# +# Required ENV vars: +# ------------------ +# JAVA_HOME - location of a JDK home dir +# +# Optional ENV vars +# ----------------- +# M2_HOME - location of maven2's installed home dir +# MAVEN_OPTS - parameters passed to the Java VM when running Maven +# e.g. to debug Maven itself, use +# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +# MAVEN_SKIP_RC - flag to disable loading of mavenrc files +# ---------------------------------------------------------------------------- + +if [ -z "$MAVEN_SKIP_RC" ] ; then + + if [ -f /etc/mavenrc ] ; then + . /etc/mavenrc + fi + + if [ -f "$HOME/.mavenrc" ] ; then + . "$HOME/.mavenrc" + fi + +fi + +# OS specific support. $var _must_ be set to either true or false. +cygwin=false; +darwin=false; +mingw=false +case "`uname`" in + CYGWIN*) cygwin=true ;; + MINGW*) mingw=true;; + Darwin*) darwin=true + # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home + # See https://developer.apple.com/library/mac/qa/qa1170/_index.html + if [ -z "$JAVA_HOME" ]; then + if [ -x "/usr/libexec/java_home" ]; then + export JAVA_HOME="`/usr/libexec/java_home`" + else + export JAVA_HOME="/Library/Java/Home" + fi + fi + ;; +esac + +if [ -z "$JAVA_HOME" ] ; then + if [ -r /etc/gentoo-release ] ; then + JAVA_HOME=`java-config --jre-home` + fi +fi + +if [ -z "$M2_HOME" ] ; then + ## resolve links - $0 may be a link to maven's home + PRG="$0" + + # need this for relative symlinks + while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG="`dirname "$PRG"`/$link" + fi + done + + saveddir=`pwd` + + M2_HOME=`dirname "$PRG"`/.. + + # make it fully qualified + M2_HOME=`cd "$M2_HOME" && pwd` + + cd "$saveddir" + # echo Using m2 at $M2_HOME +fi + +# For Cygwin, ensure paths are in UNIX format before anything is touched +if $cygwin ; then + [ -n "$M2_HOME" ] && + M2_HOME=`cygpath --unix "$M2_HOME"` + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --unix "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --unix "$CLASSPATH"` +fi + +# For Migwn, ensure paths are in UNIX format before anything is touched +if $mingw ; then + [ -n "$M2_HOME" ] && + M2_HOME="`(cd "$M2_HOME"; pwd)`" + [ -n "$JAVA_HOME" ] && + JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" + # TODO classpath? +fi + +if [ -z "$JAVA_HOME" ]; then + javaExecutable="`which javac`" + if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then + # readlink(1) is not available as standard on Solaris 10. + readLink=`which readlink` + if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then + if $darwin ; then + javaHome="`dirname \"$javaExecutable\"`" + javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" + else + javaExecutable="`readlink -f \"$javaExecutable\"`" + fi + javaHome="`dirname \"$javaExecutable\"`" + javaHome=`expr "$javaHome" : '\(.*\)/bin'` + JAVA_HOME="$javaHome" + export JAVA_HOME + fi + fi +fi + +if [ -z "$JAVACMD" ] ; then + if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + else + JAVACMD="`which java`" + fi +fi + +if [ ! -x "$JAVACMD" ] ; then + echo "Error: JAVA_HOME is not defined correctly." >&2 + echo " We cannot execute $JAVACMD" >&2 + exit 1 +fi + +if [ -z "$JAVA_HOME" ] ; then + echo "Warning: JAVA_HOME environment variable is not set." +fi + +CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher + +# traverses directory structure from process work directory to filesystem root +# first directory with .mvn subdirectory is considered project base directory +find_maven_basedir() { + + if [ -z "$1" ] + then + echo "Path not specified to find_maven_basedir" + return 1 + fi + + basedir="$1" + wdir="$1" + while [ "$wdir" != '/' ] ; do + if [ -d "$wdir"/.mvn ] ; then + basedir=$wdir + break + fi + # workaround for JBEAP-8937 (on Solaris 10/Sparc) + if [ -d "${wdir}" ]; then + wdir=`cd "$wdir/.."; pwd` + fi + # end of workaround + done + echo "${basedir}" +} + +# concatenates all lines of a file +concat_lines() { + if [ -f "$1" ]; then + echo "$(tr -s '\n' ' ' < "$1")" + fi +} + +BASE_DIR=`find_maven_basedir "$(pwd)"` +if [ -z "$BASE_DIR" ]; then + exit 1; +fi + +export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} +echo $MAVEN_PROJECTBASEDIR +MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" + +# For Cygwin, switch paths to Windows format before running java +if $cygwin; then + [ -n "$M2_HOME" ] && + M2_HOME=`cygpath --path --windows "$M2_HOME"` + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --windows "$CLASSPATH"` + [ -n "$MAVEN_PROJECTBASEDIR" ] && + MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` +fi + +WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +exec "$JAVACMD" \ + $MAVEN_OPTS \ + -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ + "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ + ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" diff --git a/service-consumer/mvnw.cmd b/service-consumer/mvnw.cmd new file mode 100644 index 0000000..019bd74 --- /dev/null +++ b/service-consumer/mvnw.cmd @@ -0,0 +1,143 @@ +@REM ---------------------------------------------------------------------------- +@REM Licensed to the Apache Software Foundation (ASF) under one +@REM or more contributor license agreements. See the NOTICE file +@REM distributed with this work for additional information +@REM regarding copyright ownership. The ASF licenses this file +@REM to you under the Apache License, Version 2.0 (the +@REM "License"); you may not use this file except in compliance +@REM with the License. You may obtain a copy of the License at +@REM +@REM http://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, +@REM software distributed under the License is distributed on an +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@REM KIND, either express or implied. See the License for the +@REM specific language governing permissions and limitations +@REM under the License. +@REM ---------------------------------------------------------------------------- + +@REM ---------------------------------------------------------------------------- +@REM Maven2 Start Up Batch script +@REM +@REM Required ENV vars: +@REM JAVA_HOME - location of a JDK home dir +@REM +@REM Optional ENV vars +@REM M2_HOME - location of maven2's installed home dir +@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands +@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending +@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven +@REM e.g. to debug Maven itself, use +@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files +@REM ---------------------------------------------------------------------------- + +@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' +@echo off +@REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' +@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% + +@REM set %HOME% to equivalent of $HOME +if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") + +@REM Execute a user defined script before this one +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre +@REM check for pre script, once with legacy .bat ending and once with .cmd ending +if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" +if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" +:skipRcPre + +@setlocal + +set ERROR_CODE=0 + +@REM To isolate internal variables from possible post scripts, we use another setlocal +@setlocal + +@REM ==== START VALIDATION ==== +if not "%JAVA_HOME%" == "" goto OkJHome + +echo. +echo Error: JAVA_HOME not found in your environment. >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +:OkJHome +if exist "%JAVA_HOME%\bin\java.exe" goto init + +echo. +echo Error: JAVA_HOME is set to an invalid directory. >&2 +echo JAVA_HOME = "%JAVA_HOME%" >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +@REM ==== END VALIDATION ==== + +:init + +@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". +@REM Fallback to current working directory if not found. + +set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% +IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir + +set EXEC_DIR=%CD% +set WDIR=%EXEC_DIR% +:findBaseDir +IF EXIST "%WDIR%"\.mvn goto baseDirFound +cd .. +IF "%WDIR%"=="%CD%" goto baseDirNotFound +set WDIR=%CD% +goto findBaseDir + +:baseDirFound +set MAVEN_PROJECTBASEDIR=%WDIR% +cd "%EXEC_DIR%" +goto endDetectBaseDir + +:baseDirNotFound +set MAVEN_PROJECTBASEDIR=%EXEC_DIR% +cd "%EXEC_DIR%" + +:endDetectBaseDir + +IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig + +@setlocal EnableExtensions EnableDelayedExpansion +for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a +@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% + +:endReadAdditionalConfig + +SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" + +set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" +set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* +if ERRORLEVEL 1 goto error +goto end + +:error +set ERROR_CODE=1 + +:end +@endlocal & set ERROR_CODE=%ERROR_CODE% + +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost +@REM check for post script, once with legacy .bat ending and once with .cmd ending +if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" +if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" +:skipRcPost + +@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' +if "%MAVEN_BATCH_PAUSE%" == "on" pause + +if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% + +exit /B %ERROR_CODE% diff --git a/service-consumer/pom.xml b/service-consumer/pom.xml new file mode 100644 index 0000000..01af904 --- /dev/null +++ b/service-consumer/pom.xml @@ -0,0 +1,67 @@ + + + + ms-base-security + com.yss.ms + 1.0-SNAPSHOT + + 4.0.0 + + service-consumer + war + + service-consumer + Demo project for Spring Boot + + + UTF-8 + UTF-8 + 1.8 + + + + + org.springframework.boot + spring-boot-starter-actuator + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.cloud + spring-cloud-starter-eureka + + + org.springframework.cloud + spring-cloud-starter-feign + + + org.springframework.cloud + spring-cloud-starter-hystrix + + + org.springframework.boot + spring-boot-starter-test + test + + + + com.yss.ms + ms-common + 1.0-SNAPSHOT + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + + diff --git a/service-consumer/src/main/java/com/yss/ms/ServiceConsumerApplication.java b/service-consumer/src/main/java/com/yss/ms/ServiceConsumerApplication.java new file mode 100644 index 0000000..91321d4 --- /dev/null +++ b/service-consumer/src/main/java/com/yss/ms/ServiceConsumerApplication.java @@ -0,0 +1,39 @@ +package com.yss.ms; + +import org.springframework.boot.SpringApplication; +import org.springframework.cloud.client.SpringCloudApplication; +import org.springframework.cloud.client.loadbalancer.LoadBalanced; +import org.springframework.cloud.netflix.feign.EnableFeignClients; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.client.RestTemplate; + +/** + * 服务消费方 + * + * @author liugang + * @since 2018-04-08 + */ +@SpringCloudApplication +@EnableFeignClients +@Configuration +public class ServiceConsumerApplication { + + public static void main(String[] args) { + SpringApplication.run(ServiceConsumerApplication.class, args); + } + + /** + * restTemplate + * + * {@link LoadBalanced} 开启客户端负载均衡 默认轮询list.get(n次调用 % list.size) + * {@link org.springframework.cloud.netflix.ribbon.RibbonLoadBalancerClient} + * {@link org.springframework.cloud.client.loadbalancer.LoadBalancerAutoConfiguration} + * @author liugang 2018-04-08 14:48 + * */ + @Bean + @LoadBalanced + RestTemplate restTemplate(){ + return new RestTemplate(); + } +} diff --git a/service-consumer/src/main/java/com/yss/ms/feign/IServiceProvider.java b/service-consumer/src/main/java/com/yss/ms/feign/IServiceProvider.java new file mode 100644 index 0000000..8b673ef --- /dev/null +++ b/service-consumer/src/main/java/com/yss/ms/feign/IServiceProvider.java @@ -0,0 +1,35 @@ +package com.yss.ms.feign; + +import com.yss.ms.entity.User; +import com.yss.ms.exception.BaseException; +import com.yss.ms.msg.ObjectRestResponse; +import org.springframework.cloud.netflix.feign.FeignClient; +import org.springframework.web.bind.annotation.GetMapping; + +/** + * feignClient interface + * + * @author liugang + * @since 2018-04-08 + */ +@FeignClient(name = "service-provider") +public interface IServiceProvider { + + /** + * UserInfo + * + * @return User + * @author liugang 2018-04-08 16:33 + * */ + @GetMapping("/user") + User user() throws BaseException; + + /** + * 模拟错误 + * + * @return User + * @author liugang 2018-04-08 16:40 + * */ + @GetMapping("/user/error") + User error() throws BaseException; +} diff --git a/service-consumer/src/main/java/com/yss/ms/feign/IServiceSideCar.java b/service-consumer/src/main/java/com/yss/ms/feign/IServiceSideCar.java new file mode 100644 index 0000000..65a689b --- /dev/null +++ b/service-consumer/src/main/java/com/yss/ms/feign/IServiceSideCar.java @@ -0,0 +1,17 @@ +package com.yss.ms.feign; + +import org.springframework.cloud.netflix.feign.FeignClient; +import org.springframework.web.bind.annotation.RequestMapping; + +/** + * TODO + * + * @author liugang + * @since 2018-04-08 + */ +@FeignClient(name = "ms-sidecar") +public interface IServiceSideCar { + + @RequestMapping("/api/products") + Object Get(); +} diff --git a/service-consumer/src/main/java/com/yss/ms/rest/ConsumerController.java b/service-consumer/src/main/java/com/yss/ms/rest/ConsumerController.java new file mode 100644 index 0000000..8f707db --- /dev/null +++ b/service-consumer/src/main/java/com/yss/ms/rest/ConsumerController.java @@ -0,0 +1,100 @@ +package com.yss.ms.rest; + +import com.netflix.hystrix.HystrixCircuitBreaker; +import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand; +import com.yss.ms.entity.User; +import com.yss.ms.exception.BaseException; +import com.yss.ms.feign.IServiceProvider; +import com.yss.ms.feign.IServiceSideCar; +import com.yss.ms.msg.ObjectRestResponse; +import feign.FeignException; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.MethodArgumentNotValidException; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.client.RestTemplate; + +/** + * TODO + * + * @author liugang + * @since 2018-04-08 + */ +@Slf4j +@RestController +@RequestMapping("user") +public class ConsumerController { + + @Autowired + private IServiceProvider iServiceProvider; + + @Autowired + private IServiceSideCar iServiceSideCar; + + @Autowired + private RestTemplate restTemplate; + + /** + * 模拟超时 + * + * @author liugang 2018-04-08 23:11 + * */ + @HystrixCommand(fallbackMethod = "error1") + @GetMapping("") + public User user() throws BaseException{ + return iServiceProvider.user(); + } + + public User error1(Throwable throwable) throws BaseException{ + log.error("进入回退方法,异常:" + throwable); + User user = new User(); + user.setId(0); + user.setAge(0); + user.setName("Admin"); + user.setPort(8081); + //throw new BaseException("ConsumerController.user error fallback",500); + return user; + } + + @GetMapping("/ribbon") + public User user1() throws BaseException{ + return restTemplate.getForObject("http://service-provider/user",User.class); + } + + /** + * 模拟异常 + * + * {@link HystrixCircuitBreaker.HystrixCircuitBreakerImpl} + * @author liugang 2018-04-08 21:40 + * */ + @HystrixCommand(fallbackMethod = "error",ignoreExceptions = {FeignException.class}) + @GetMapping("/error") + public User userError() throws BaseException{ + return iServiceProvider.error(); + } + + public User error(Throwable throwable) throws BaseException{ + log.error("进入回退方法,异常:" + throwable); + User user = new User(); + user.setId(0); + user.setAge(0); + user.setName("Admin"); + user.setPort(8080); + //throw new BaseException("ConsumerController.userError error fallback",500); + return user; + } + + /** + * C#服务接口 + * + * @author liugang 2018-01-17 17:11 + * */ + @GetMapping("/sidecar") + public Object getProducts(){ + return iServiceSideCar.Get(); + } + +} diff --git a/service-consumer/src/main/resources/application.yml b/service-consumer/src/main/resources/application.yml new file mode 100644 index 0000000..f693e17 --- /dev/null +++ b/service-consumer/src/main/resources/application.yml @@ -0,0 +1,42 @@ +server: + port: 9095 +spring: + application: + name: service-consumer + +management: + security: + enabled: false + +info: + app: + name: 服务消费方 + version: 1.0 + +eureka: + instance: + statusPageUrlPath: /user + healthCheckUrlPath: /health + prefer-ip-address: true + ip-address: 127.0.0.1 + client: + serviceUrl: + defaultZone: http://127.0.0.1:8761/eureka/ + registry-fetch-interval-seconds: 30 + +hystrix: + command: + default: + execution: + isolation: + thread: + timeoutInMilliseconds: 5000 # Hystrix的超时时间是对次节点的请求时间的进行熔断 + strategy: THREAD + +ribbon: + ReadTimeout: 20000 # 处理时间 + ConnectTimeout: 20000 # 连接时间 + MaxAutoRetries: 0 #最大自动重试次数 + MaxAutoRetriesNextServer: 1 # 换实例重试次数 + MaxTotalHttpConnections: 2000 # 最大http连接数,越大越好,但到到达一个临界点之后,就不会提高响应速度了 + MaxConnectionsPerHost: 1000 # 每个host连接数 \ No newline at end of file diff --git a/service-consumer/src/test/java/com/yss/ms/serviceconsumer/ServiceConsumerApplicationTests.java b/service-consumer/src/test/java/com/yss/ms/serviceconsumer/ServiceConsumerApplicationTests.java new file mode 100644 index 0000000..06e2323 --- /dev/null +++ b/service-consumer/src/test/java/com/yss/ms/serviceconsumer/ServiceConsumerApplicationTests.java @@ -0,0 +1,16 @@ +package com.yss.ms.serviceconsumer; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@SpringBootTest +public class ServiceConsumerApplicationTests { + + @Test + public void contextLoads() { + } + +} diff --git a/service-provider/.gitignore b/service-provider/.gitignore new file mode 100644 index 0000000..82eca33 --- /dev/null +++ b/service-provider/.gitignore @@ -0,0 +1,25 @@ +/target/ +!.mvn/wrapper/maven-wrapper.jar + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/build/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ \ No newline at end of file diff --git a/service-provider/mvnw b/service-provider/mvnw new file mode 100644 index 0000000..5bf251c --- /dev/null +++ b/service-provider/mvnw @@ -0,0 +1,225 @@ +#!/bin/sh +# ---------------------------------------------------------------------------- +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# ---------------------------------------------------------------------------- + +# ---------------------------------------------------------------------------- +# Maven2 Start Up Batch script +# +# Required ENV vars: +# ------------------ +# JAVA_HOME - location of a JDK home dir +# +# Optional ENV vars +# ----------------- +# M2_HOME - location of maven2's installed home dir +# MAVEN_OPTS - parameters passed to the Java VM when running Maven +# e.g. to debug Maven itself, use +# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +# MAVEN_SKIP_RC - flag to disable loading of mavenrc files +# ---------------------------------------------------------------------------- + +if [ -z "$MAVEN_SKIP_RC" ] ; then + + if [ -f /etc/mavenrc ] ; then + . /etc/mavenrc + fi + + if [ -f "$HOME/.mavenrc" ] ; then + . "$HOME/.mavenrc" + fi + +fi + +# OS specific support. $var _must_ be set to either true or false. +cygwin=false; +darwin=false; +mingw=false +case "`uname`" in + CYGWIN*) cygwin=true ;; + MINGW*) mingw=true;; + Darwin*) darwin=true + # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home + # See https://developer.apple.com/library/mac/qa/qa1170/_index.html + if [ -z "$JAVA_HOME" ]; then + if [ -x "/usr/libexec/java_home" ]; then + export JAVA_HOME="`/usr/libexec/java_home`" + else + export JAVA_HOME="/Library/Java/Home" + fi + fi + ;; +esac + +if [ -z "$JAVA_HOME" ] ; then + if [ -r /etc/gentoo-release ] ; then + JAVA_HOME=`java-config --jre-home` + fi +fi + +if [ -z "$M2_HOME" ] ; then + ## resolve links - $0 may be a link to maven's home + PRG="$0" + + # need this for relative symlinks + while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG="`dirname "$PRG"`/$link" + fi + done + + saveddir=`pwd` + + M2_HOME=`dirname "$PRG"`/.. + + # make it fully qualified + M2_HOME=`cd "$M2_HOME" && pwd` + + cd "$saveddir" + # echo Using m2 at $M2_HOME +fi + +# For Cygwin, ensure paths are in UNIX format before anything is touched +if $cygwin ; then + [ -n "$M2_HOME" ] && + M2_HOME=`cygpath --unix "$M2_HOME"` + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --unix "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --unix "$CLASSPATH"` +fi + +# For Migwn, ensure paths are in UNIX format before anything is touched +if $mingw ; then + [ -n "$M2_HOME" ] && + M2_HOME="`(cd "$M2_HOME"; pwd)`" + [ -n "$JAVA_HOME" ] && + JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" + # TODO classpath? +fi + +if [ -z "$JAVA_HOME" ]; then + javaExecutable="`which javac`" + if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then + # readlink(1) is not available as standard on Solaris 10. + readLink=`which readlink` + if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then + if $darwin ; then + javaHome="`dirname \"$javaExecutable\"`" + javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" + else + javaExecutable="`readlink -f \"$javaExecutable\"`" + fi + javaHome="`dirname \"$javaExecutable\"`" + javaHome=`expr "$javaHome" : '\(.*\)/bin'` + JAVA_HOME="$javaHome" + export JAVA_HOME + fi + fi +fi + +if [ -z "$JAVACMD" ] ; then + if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + else + JAVACMD="`which java`" + fi +fi + +if [ ! -x "$JAVACMD" ] ; then + echo "Error: JAVA_HOME is not defined correctly." >&2 + echo " We cannot execute $JAVACMD" >&2 + exit 1 +fi + +if [ -z "$JAVA_HOME" ] ; then + echo "Warning: JAVA_HOME environment variable is not set." +fi + +CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher + +# traverses directory structure from process work directory to filesystem root +# first directory with .mvn subdirectory is considered project base directory +find_maven_basedir() { + + if [ -z "$1" ] + then + echo "Path not specified to find_maven_basedir" + return 1 + fi + + basedir="$1" + wdir="$1" + while [ "$wdir" != '/' ] ; do + if [ -d "$wdir"/.mvn ] ; then + basedir=$wdir + break + fi + # workaround for JBEAP-8937 (on Solaris 10/Sparc) + if [ -d "${wdir}" ]; then + wdir=`cd "$wdir/.."; pwd` + fi + # end of workaround + done + echo "${basedir}" +} + +# concatenates all lines of a file +concat_lines() { + if [ -f "$1" ]; then + echo "$(tr -s '\n' ' ' < "$1")" + fi +} + +BASE_DIR=`find_maven_basedir "$(pwd)"` +if [ -z "$BASE_DIR" ]; then + exit 1; +fi + +export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} +echo $MAVEN_PROJECTBASEDIR +MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" + +# For Cygwin, switch paths to Windows format before running java +if $cygwin; then + [ -n "$M2_HOME" ] && + M2_HOME=`cygpath --path --windows "$M2_HOME"` + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --windows "$CLASSPATH"` + [ -n "$MAVEN_PROJECTBASEDIR" ] && + MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` +fi + +WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +exec "$JAVACMD" \ + $MAVEN_OPTS \ + -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ + "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ + ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" diff --git a/service-provider/mvnw.cmd b/service-provider/mvnw.cmd new file mode 100644 index 0000000..019bd74 --- /dev/null +++ b/service-provider/mvnw.cmd @@ -0,0 +1,143 @@ +@REM ---------------------------------------------------------------------------- +@REM Licensed to the Apache Software Foundation (ASF) under one +@REM or more contributor license agreements. See the NOTICE file +@REM distributed with this work for additional information +@REM regarding copyright ownership. The ASF licenses this file +@REM to you under the Apache License, Version 2.0 (the +@REM "License"); you may not use this file except in compliance +@REM with the License. You may obtain a copy of the License at +@REM +@REM http://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, +@REM software distributed under the License is distributed on an +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@REM KIND, either express or implied. See the License for the +@REM specific language governing permissions and limitations +@REM under the License. +@REM ---------------------------------------------------------------------------- + +@REM ---------------------------------------------------------------------------- +@REM Maven2 Start Up Batch script +@REM +@REM Required ENV vars: +@REM JAVA_HOME - location of a JDK home dir +@REM +@REM Optional ENV vars +@REM M2_HOME - location of maven2's installed home dir +@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands +@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending +@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven +@REM e.g. to debug Maven itself, use +@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files +@REM ---------------------------------------------------------------------------- + +@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' +@echo off +@REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' +@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% + +@REM set %HOME% to equivalent of $HOME +if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") + +@REM Execute a user defined script before this one +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre +@REM check for pre script, once with legacy .bat ending and once with .cmd ending +if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" +if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" +:skipRcPre + +@setlocal + +set ERROR_CODE=0 + +@REM To isolate internal variables from possible post scripts, we use another setlocal +@setlocal + +@REM ==== START VALIDATION ==== +if not "%JAVA_HOME%" == "" goto OkJHome + +echo. +echo Error: JAVA_HOME not found in your environment. >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +:OkJHome +if exist "%JAVA_HOME%\bin\java.exe" goto init + +echo. +echo Error: JAVA_HOME is set to an invalid directory. >&2 +echo JAVA_HOME = "%JAVA_HOME%" >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +@REM ==== END VALIDATION ==== + +:init + +@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". +@REM Fallback to current working directory if not found. + +set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% +IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir + +set EXEC_DIR=%CD% +set WDIR=%EXEC_DIR% +:findBaseDir +IF EXIST "%WDIR%"\.mvn goto baseDirFound +cd .. +IF "%WDIR%"=="%CD%" goto baseDirNotFound +set WDIR=%CD% +goto findBaseDir + +:baseDirFound +set MAVEN_PROJECTBASEDIR=%WDIR% +cd "%EXEC_DIR%" +goto endDetectBaseDir + +:baseDirNotFound +set MAVEN_PROJECTBASEDIR=%EXEC_DIR% +cd "%EXEC_DIR%" + +:endDetectBaseDir + +IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig + +@setlocal EnableExtensions EnableDelayedExpansion +for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a +@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% + +:endReadAdditionalConfig + +SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" + +set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" +set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* +if ERRORLEVEL 1 goto error +goto end + +:error +set ERROR_CODE=1 + +:end +@endlocal & set ERROR_CODE=%ERROR_CODE% + +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost +@REM check for post script, once with legacy .bat ending and once with .cmd ending +if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" +if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" +:skipRcPost + +@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' +if "%MAVEN_BATCH_PAUSE%" == "on" pause + +if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% + +exit /B %ERROR_CODE% diff --git a/service-provider/pom.xml b/service-provider/pom.xml new file mode 100644 index 0000000..f85f886 --- /dev/null +++ b/service-provider/pom.xml @@ -0,0 +1,64 @@ + + + + ms-base-security + com.yss.ms + 1.0-SNAPSHOT + + 4.0.0 + + service-provider + war + + service-provider + Demo project for Spring Boot + + + UTF-8 + UTF-8 + 1.8 + + + + + org.springframework.boot + spring-boot-starter-actuator + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.cloud + spring-cloud-starter-eureka + + + org.springframework.cloud + spring-cloud-starter-hystrix + + + + org.springframework.boot + spring-boot-starter-test + test + + + + com.yss.ms + ms-common + 1.0-SNAPSHOT + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + + diff --git a/service-provider/src/main/java/com/yss/ms/ServiceProviderApplication.java b/service-provider/src/main/java/com/yss/ms/ServiceProviderApplication.java new file mode 100644 index 0000000..4e4d04d --- /dev/null +++ b/service-provider/src/main/java/com/yss/ms/ServiceProviderApplication.java @@ -0,0 +1,37 @@ +package com.yss.ms; + +import com.yss.ms.entity.User; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.SpringApplication; +import org.springframework.cloud.client.SpringCloudApplication; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +/** + * 服务提供方 + * + * @author liugang + * @since 2018-04-08 + */ +@SpringCloudApplication +@Configuration +public class ServiceProviderApplication { + + public static void main(String[] args) { + SpringApplication.run(ServiceProviderApplication.class, args); + } + + @Value("${server.port}") + int port; + + @Bean + User user(){ + User user = new User(); + user.setId(1); + user.setAge(18); + user.setName("小明"); + user.setPort(port); + return user; + } + +} diff --git a/service-provider/src/main/java/com/yss/ms/rest/ProviderController.java b/service-provider/src/main/java/com/yss/ms/rest/ProviderController.java new file mode 100644 index 0000000..8943655 --- /dev/null +++ b/service-provider/src/main/java/com/yss/ms/rest/ProviderController.java @@ -0,0 +1,34 @@ +package com.yss.ms.rest; + +import com.yss.ms.entity.User; +import com.yss.ms.exception.BaseException; +import com.yss.ms.msg.ObjectRestResponse; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * Test + * + * @author liugang + * @since 2018-04-08 + */ +@RestController +@RequestMapping("user") +public class ProviderController { + + @Autowired + private User user; + + @GetMapping("") + public User user() throws BaseException { + return user; + } + + @GetMapping("/error") + public User error() throws BaseException{ + throw new BaseException(HttpStatus.GATEWAY_TIMEOUT.getReasonPhrase(), HttpStatus.GATEWAY_TIMEOUT.value()); + } +} diff --git a/service-provider/src/main/resources/application.yml b/service-provider/src/main/resources/application.yml new file mode 100644 index 0000000..6fe30e2 --- /dev/null +++ b/service-provider/src/main/resources/application.yml @@ -0,0 +1,41 @@ +server: + port: 9091 +spring: + application: + name: service-provider + +management: + security: + enabled: false + +info: + app: + name: 服务提供方 + version: 1.0 + +eureka: + instance: + statusPageUrlPath: /user + healthCheckUrlPath: /health + prefer-ip-address: true + ip-address: 127.0.0.1 + client: + serviceUrl: + defaultZone: http://127.0.0.1:8761/eureka/ + registry-fetch-interval-seconds: 30 + +hystrix: + command: + default: + execution: + isolation: + thread: + timeoutInMilliseconds: 20000 + strategy: THREAD +ribbon: + ReadTimeout: 20000 + ConnectTimeout: 20000 + MaxAutoRetries: 0 + MaxAutoRetriesNextServer: 1 + MaxTotalHttpConnections: 2000 + MaxConnectionsPerHost: 1000 \ No newline at end of file diff --git a/service-provider/src/test/java/com/yss/ms/serviceprovider/ServiceProviderApplicationTests.java b/service-provider/src/test/java/com/yss/ms/serviceprovider/ServiceProviderApplicationTests.java new file mode 100644 index 0000000..987d0de --- /dev/null +++ b/service-provider/src/test/java/com/yss/ms/serviceprovider/ServiceProviderApplicationTests.java @@ -0,0 +1,16 @@ +package com.yss.ms.serviceprovider; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@SpringBootTest +public class ServiceProviderApplicationTests { + + @Test + public void contextLoads() { + } + +} diff --git a/zuul-server/.gitignore b/zuul-server/.gitignore new file mode 100644 index 0000000..82eca33 --- /dev/null +++ b/zuul-server/.gitignore @@ -0,0 +1,25 @@ +/target/ +!.mvn/wrapper/maven-wrapper.jar + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/build/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ \ No newline at end of file diff --git a/zuul-server/mvnw b/zuul-server/mvnw new file mode 100644 index 0000000..5bf251c --- /dev/null +++ b/zuul-server/mvnw @@ -0,0 +1,225 @@ +#!/bin/sh +# ---------------------------------------------------------------------------- +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# ---------------------------------------------------------------------------- + +# ---------------------------------------------------------------------------- +# Maven2 Start Up Batch script +# +# Required ENV vars: +# ------------------ +# JAVA_HOME - location of a JDK home dir +# +# Optional ENV vars +# ----------------- +# M2_HOME - location of maven2's installed home dir +# MAVEN_OPTS - parameters passed to the Java VM when running Maven +# e.g. to debug Maven itself, use +# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +# MAVEN_SKIP_RC - flag to disable loading of mavenrc files +# ---------------------------------------------------------------------------- + +if [ -z "$MAVEN_SKIP_RC" ] ; then + + if [ -f /etc/mavenrc ] ; then + . /etc/mavenrc + fi + + if [ -f "$HOME/.mavenrc" ] ; then + . "$HOME/.mavenrc" + fi + +fi + +# OS specific support. $var _must_ be set to either true or false. +cygwin=false; +darwin=false; +mingw=false +case "`uname`" in + CYGWIN*) cygwin=true ;; + MINGW*) mingw=true;; + Darwin*) darwin=true + # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home + # See https://developer.apple.com/library/mac/qa/qa1170/_index.html + if [ -z "$JAVA_HOME" ]; then + if [ -x "/usr/libexec/java_home" ]; then + export JAVA_HOME="`/usr/libexec/java_home`" + else + export JAVA_HOME="/Library/Java/Home" + fi + fi + ;; +esac + +if [ -z "$JAVA_HOME" ] ; then + if [ -r /etc/gentoo-release ] ; then + JAVA_HOME=`java-config --jre-home` + fi +fi + +if [ -z "$M2_HOME" ] ; then + ## resolve links - $0 may be a link to maven's home + PRG="$0" + + # need this for relative symlinks + while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG="`dirname "$PRG"`/$link" + fi + done + + saveddir=`pwd` + + M2_HOME=`dirname "$PRG"`/.. + + # make it fully qualified + M2_HOME=`cd "$M2_HOME" && pwd` + + cd "$saveddir" + # echo Using m2 at $M2_HOME +fi + +# For Cygwin, ensure paths are in UNIX format before anything is touched +if $cygwin ; then + [ -n "$M2_HOME" ] && + M2_HOME=`cygpath --unix "$M2_HOME"` + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --unix "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --unix "$CLASSPATH"` +fi + +# For Migwn, ensure paths are in UNIX format before anything is touched +if $mingw ; then + [ -n "$M2_HOME" ] && + M2_HOME="`(cd "$M2_HOME"; pwd)`" + [ -n "$JAVA_HOME" ] && + JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" + # TODO classpath? +fi + +if [ -z "$JAVA_HOME" ]; then + javaExecutable="`which javac`" + if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then + # readlink(1) is not available as standard on Solaris 10. + readLink=`which readlink` + if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then + if $darwin ; then + javaHome="`dirname \"$javaExecutable\"`" + javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" + else + javaExecutable="`readlink -f \"$javaExecutable\"`" + fi + javaHome="`dirname \"$javaExecutable\"`" + javaHome=`expr "$javaHome" : '\(.*\)/bin'` + JAVA_HOME="$javaHome" + export JAVA_HOME + fi + fi +fi + +if [ -z "$JAVACMD" ] ; then + if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + else + JAVACMD="`which java`" + fi +fi + +if [ ! -x "$JAVACMD" ] ; then + echo "Error: JAVA_HOME is not defined correctly." >&2 + echo " We cannot execute $JAVACMD" >&2 + exit 1 +fi + +if [ -z "$JAVA_HOME" ] ; then + echo "Warning: JAVA_HOME environment variable is not set." +fi + +CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher + +# traverses directory structure from process work directory to filesystem root +# first directory with .mvn subdirectory is considered project base directory +find_maven_basedir() { + + if [ -z "$1" ] + then + echo "Path not specified to find_maven_basedir" + return 1 + fi + + basedir="$1" + wdir="$1" + while [ "$wdir" != '/' ] ; do + if [ -d "$wdir"/.mvn ] ; then + basedir=$wdir + break + fi + # workaround for JBEAP-8937 (on Solaris 10/Sparc) + if [ -d "${wdir}" ]; then + wdir=`cd "$wdir/.."; pwd` + fi + # end of workaround + done + echo "${basedir}" +} + +# concatenates all lines of a file +concat_lines() { + if [ -f "$1" ]; then + echo "$(tr -s '\n' ' ' < "$1")" + fi +} + +BASE_DIR=`find_maven_basedir "$(pwd)"` +if [ -z "$BASE_DIR" ]; then + exit 1; +fi + +export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} +echo $MAVEN_PROJECTBASEDIR +MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" + +# For Cygwin, switch paths to Windows format before running java +if $cygwin; then + [ -n "$M2_HOME" ] && + M2_HOME=`cygpath --path --windows "$M2_HOME"` + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --windows "$CLASSPATH"` + [ -n "$MAVEN_PROJECTBASEDIR" ] && + MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` +fi + +WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +exec "$JAVACMD" \ + $MAVEN_OPTS \ + -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ + "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ + ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" diff --git a/zuul-server/mvnw.cmd b/zuul-server/mvnw.cmd new file mode 100644 index 0000000..019bd74 --- /dev/null +++ b/zuul-server/mvnw.cmd @@ -0,0 +1,143 @@ +@REM ---------------------------------------------------------------------------- +@REM Licensed to the Apache Software Foundation (ASF) under one +@REM or more contributor license agreements. See the NOTICE file +@REM distributed with this work for additional information +@REM regarding copyright ownership. The ASF licenses this file +@REM to you under the Apache License, Version 2.0 (the +@REM "License"); you may not use this file except in compliance +@REM with the License. You may obtain a copy of the License at +@REM +@REM http://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, +@REM software distributed under the License is distributed on an +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@REM KIND, either express or implied. See the License for the +@REM specific language governing permissions and limitations +@REM under the License. +@REM ---------------------------------------------------------------------------- + +@REM ---------------------------------------------------------------------------- +@REM Maven2 Start Up Batch script +@REM +@REM Required ENV vars: +@REM JAVA_HOME - location of a JDK home dir +@REM +@REM Optional ENV vars +@REM M2_HOME - location of maven2's installed home dir +@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands +@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending +@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven +@REM e.g. to debug Maven itself, use +@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files +@REM ---------------------------------------------------------------------------- + +@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' +@echo off +@REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' +@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% + +@REM set %HOME% to equivalent of $HOME +if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") + +@REM Execute a user defined script before this one +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre +@REM check for pre script, once with legacy .bat ending and once with .cmd ending +if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" +if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" +:skipRcPre + +@setlocal + +set ERROR_CODE=0 + +@REM To isolate internal variables from possible post scripts, we use another setlocal +@setlocal + +@REM ==== START VALIDATION ==== +if not "%JAVA_HOME%" == "" goto OkJHome + +echo. +echo Error: JAVA_HOME not found in your environment. >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +:OkJHome +if exist "%JAVA_HOME%\bin\java.exe" goto init + +echo. +echo Error: JAVA_HOME is set to an invalid directory. >&2 +echo JAVA_HOME = "%JAVA_HOME%" >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +@REM ==== END VALIDATION ==== + +:init + +@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". +@REM Fallback to current working directory if not found. + +set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% +IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir + +set EXEC_DIR=%CD% +set WDIR=%EXEC_DIR% +:findBaseDir +IF EXIST "%WDIR%"\.mvn goto baseDirFound +cd .. +IF "%WDIR%"=="%CD%" goto baseDirNotFound +set WDIR=%CD% +goto findBaseDir + +:baseDirFound +set MAVEN_PROJECTBASEDIR=%WDIR% +cd "%EXEC_DIR%" +goto endDetectBaseDir + +:baseDirNotFound +set MAVEN_PROJECTBASEDIR=%EXEC_DIR% +cd "%EXEC_DIR%" + +:endDetectBaseDir + +IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig + +@setlocal EnableExtensions EnableDelayedExpansion +for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a +@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% + +:endReadAdditionalConfig + +SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" + +set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" +set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* +if ERRORLEVEL 1 goto error +goto end + +:error +set ERROR_CODE=1 + +:end +@endlocal & set ERROR_CODE=%ERROR_CODE% + +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost +@REM check for post script, once with legacy .bat ending and once with .cmd ending +if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" +if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" +:skipRcPost + +@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' +if "%MAVEN_BATCH_PAUSE%" == "on" pause + +if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% + +exit /B %ERROR_CODE% diff --git a/zuul-server/pom.xml b/zuul-server/pom.xml new file mode 100644 index 0000000..d507f33 --- /dev/null +++ b/zuul-server/pom.xml @@ -0,0 +1,54 @@ + + + + ms-base-security + com.yss.ms + 1.0-SNAPSHOT + + 4.0.0 + + zuul-server + war + + zuul-server + Demo project for Spring Boot + + + UTF-8 + UTF-8 + 1.8 + + + + + org.springframework.boot + spring-boot-starter-actuator + + + org.springframework.cloud + spring-cloud-starter-eureka + + + org.springframework.cloud + spring-cloud-starter-zuul + + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + + diff --git a/zuul-server/src/main/java/com/yss/ms/ZuulServerApplication.java b/zuul-server/src/main/java/com/yss/ms/ZuulServerApplication.java new file mode 100644 index 0000000..3c5bcf9 --- /dev/null +++ b/zuul-server/src/main/java/com/yss/ms/ZuulServerApplication.java @@ -0,0 +1,16 @@ +package com.yss.ms; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; +import org.springframework.cloud.netflix.zuul.EnableZuulProxy; + +@SpringBootApplication +@EnableDiscoveryClient +@EnableZuulProxy +public class ZuulServerApplication { + + public static void main(String[] args) { + SpringApplication.run(ZuulServerApplication.class, args); + } +} diff --git a/zuul-server/src/main/java/com/yss/ms/filter/AuthFilter.java b/zuul-server/src/main/java/com/yss/ms/filter/AuthFilter.java new file mode 100644 index 0000000..2343b16 --- /dev/null +++ b/zuul-server/src/main/java/com/yss/ms/filter/AuthFilter.java @@ -0,0 +1,55 @@ +package com.yss.ms.filter; + +import com.netflix.zuul.ZuulFilter; + +/** + * 过滤器 + * + * @author liugang + * @since 2018-04-08 + */ +public class AuthFilter extends ZuulFilter{ + /** + * 过滤器类型 + * - pre 路由之前执行 + * - route 路由请求时被调用 + * - post 在route和error过滤器之后被过滤 + * - error 处理请求发生错误时候被调用 + * + * @author liugang 2018-04-08 22:06 + * */ + @Override + public String filterType() { + return "pre"; + } + + /** + * 过滤器执行顺序,数值越小,优先级越高 + * + * @author liugang 2018-04-08 22:09 + * */ + @Override + public int filterOrder() { + return 0; + } + + /** + * 是否被执行,可结合yaml配置控制开启 + * + * @author liugang 2018-04-08 22:07 + * */ + @Override + public boolean shouldFilter() { + return false; + } + + /** + * 过滤器具体逻辑 + * + * @author liugang 2018-04-08 22:11 + * */ + @Override + public Object run() { + return null; + } +} diff --git a/zuul-server/src/main/java/com/yss/ms/filter/RatelimitFilter.java b/zuul-server/src/main/java/com/yss/ms/filter/RatelimitFilter.java new file mode 100644 index 0000000..9598486 --- /dev/null +++ b/zuul-server/src/main/java/com/yss/ms/filter/RatelimitFilter.java @@ -0,0 +1,31 @@ +package com.yss.ms.filter; + +import com.netflix.zuul.ZuulFilter; + +/** + * TODO + * + * @author liugang + * @since 2018-04-08 + */ +public class RatelimitFilter extends ZuulFilter{ + @Override + public String filterType() { + return null; + } + + @Override + public int filterOrder() { + return 0; + } + + @Override + public boolean shouldFilter() { + return false; + } + + @Override + public Object run() { + return null; + } +} diff --git a/zuul-server/src/main/resources/application.yml b/zuul-server/src/main/resources/application.yml new file mode 100644 index 0000000..9e48bc1 --- /dev/null +++ b/zuul-server/src/main/resources/application.yml @@ -0,0 +1,52 @@ +server: + port: 9099 +spring: + application: + name: zuul-server +management: + security: + enabled: false +info: + app: + name: 网关服务 + version: 1.0 + +zuul: + ignored-services: "*" + sensitive-headers: + prefix: /api # 请求前缀 + routes: + consumer: + path: /consumer/** + serviceId: service-consumer + + provider: + path: /provider/** + serviceId: service-provider + retryable: true + +eureka: + instance: + statusPageUrlPath: /routes + healthCheckUrlPath: /health + prefer-ip-address: true + ip-address: 127.0.0.1 + client: + serviceUrl: + defaultZone: http://127.0.0.1:8761/eureka/ + registry-fetch-interval-seconds: 30 +hystrix: + command: + default: + execution: + isolation: + thread: + timeoutInMilliseconds: 5000 + strategy: THREAD +ribbon: + ReadTimeout: 20000 + ConnectTimeout: 20000 + MaxAutoRetries: 0 + MaxAutoRetriesNextServer: 1 + MaxTotalHttpConnections: 2000 + MaxConnectionsPerHost: 1000 \ No newline at end of file diff --git a/zuul-server/src/test/java/com/yss/ms/zuulserver/ZuulServerApplicationTests.java b/zuul-server/src/test/java/com/yss/ms/zuulserver/ZuulServerApplicationTests.java new file mode 100644 index 0000000..66b9a84 --- /dev/null +++ b/zuul-server/src/test/java/com/yss/ms/zuulserver/ZuulServerApplicationTests.java @@ -0,0 +1,16 @@ +package com.yss.ms.zuulserver; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@SpringBootTest +public class ZuulServerApplicationTests { + + @Test + public void contextLoads() { + } + +}