From 68a6994c3ad2333b806c1d27e2789903d8bf45be Mon Sep 17 00:00:00 2001
From: winLsy <18332763730@163.com>
Date: Sat, 27 Jan 2018 17:15:56 +0800
Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=9C=8D=E5=8A=A1=E9=99=8D?=
=?UTF-8?q?=E7=BA=A7=EF=BC=8C=E6=9C=8D=E5=8A=A1=E7=86=94=E6=96=AD=EF=BC=8C?=
=?UTF-8?q?=E6=B6=88=E6=81=AF=E6=80=BB=E7=BA=BF=EF=BC=8C=E7=9B=91=E6=8E=A7?=
=?UTF-8?q?=E4=B8=AD=E5=BF=83?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
ms/config-server/README.md | 2 +
ms/monitor-center/pom.xml | 67 +++++++++++++++++++
.../center/MsMonitorCenterApplication.java | 17 +++++
.../src/main/resources/application.yml | 18 +++++
.../src/main/resources/bootstrap.yml | 17 +++++
.../MsMonitorCenterApplicationTests.java | 16 +++++
ms/oauth/README.md | 5 ++
ms/oauth/pom.xml | 11 ++-
.../micro/fast/oauth/OauthApplication.java | 7 ++
.../fast/oauth/feign/UpmsUserService.java | 3 +-
.../fallback/UpmsUserServiceFallback.java | 19 ++++++
ms/oauth/src/main/resources/application.yml | 0
ms/oauth/src/main/resources/bootstrap.yml | 4 ++
ms/pom.xml | 1 +
ms/upms/README.md | 8 ++-
ms/upms/pom.xml | 48 ++++++-------
.../com/micro/fast/upms/UpmsApplication.java | 9 ++-
ms/upms/src/main/resources/bootstrap.yml | 10 ++-
18 files changed, 227 insertions(+), 35 deletions(-)
create mode 100644 ms/monitor-center/pom.xml
create mode 100644 ms/monitor-center/src/main/java/com/micro/fast/monitor/center/MsMonitorCenterApplication.java
create mode 100644 ms/monitor-center/src/main/resources/application.yml
create mode 100644 ms/monitor-center/src/main/resources/bootstrap.yml
create mode 100644 ms/monitor-center/src/test/java/com/micro/fast/monitor/center/MsMonitorCenterApplicationTests.java
create mode 100644 ms/oauth/README.md
create mode 100644 ms/oauth/src/main/java/com/micro/fast/oauth/feign/fallback/UpmsUserServiceFallback.java
delete mode 100644 ms/oauth/src/main/resources/application.yml
diff --git a/ms/config-server/README.md b/ms/config-server/README.md
index 8b24f32..ff0108e 100644
--- a/ms/config-server/README.md
+++ b/ms/config-server/README.md
@@ -1 +1,3 @@
###配置服务中心
+微服务中,可以将配置中心的值注入到服务的类的属性中。后续可以修改配置中心的
+配置,然后通过消息总线刷新整个微服务的配置
diff --git a/ms/monitor-center/pom.xml b/ms/monitor-center/pom.xml
new file mode 100644
index 0000000..662d537
--- /dev/null
+++ b/ms/monitor-center/pom.xml
@@ -0,0 +1,67 @@
+
+
+ 4.0.0
+
+ monitor-center
+ jar
+
+ ms-monitor-center
+ ms-monitor-center
+
+
+ com.micro.fast
+ ms
+ 0.0.1-SNAPSHOT
+
+
+
+ UTF-8
+ UTF-8
+ 1.8
+ Edgware.SR1
+
+
+
+
+
+ org.springframework.cloud
+ spring-cloud-starter-config
+
+
+
+ org.springframework.cloud
+ spring-cloud-starter-eureka
+
+
+ org.springframework.boot
+ spring-boot-starter-actuator
+
+
+
+ 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/ms/monitor-center/src/main/java/com/micro/fast/monitor/center/MsMonitorCenterApplication.java b/ms/monitor-center/src/main/java/com/micro/fast/monitor/center/MsMonitorCenterApplication.java
new file mode 100644
index 0000000..dad62e2
--- /dev/null
+++ b/ms/monitor-center/src/main/java/com/micro/fast/monitor/center/MsMonitorCenterApplication.java
@@ -0,0 +1,17 @@
+package com.micro.fast.monitor.center;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.cloud.client.SpringCloudApplication;
+import org.springframework.cloud.netflix.turbine.EnableTurbine;
+
+/**
+ * @author lsy
+ */
+@SpringCloudApplication
+@EnableTurbine
+public class MsMonitorCenterApplication {
+
+ public static void main(String[] args) {
+ SpringApplication.run(MsMonitorCenterApplication.class, args);
+ }
+}
diff --git a/ms/monitor-center/src/main/resources/application.yml b/ms/monitor-center/src/main/resources/application.yml
new file mode 100644
index 0000000..c099e3b
--- /dev/null
+++ b/ms/monitor-center/src/main/resources/application.yml
@@ -0,0 +1,18 @@
+spring:
+ application:
+ name: monitor-center
+server:
+ port: 10018
+security:
+ basic:
+ enabled: false
+turbine:
+ aggregator:
+# ָ¶¨¾ۺÏÄÄЩ¼¯Ⱥ£¬¶à¸öʹÓÃ","·ָĬÈÏΪdefault¡£¿ÉʹÓÃhttp://.../turbine.stream?cluster={clusterConfig֮һ}·ÃÎÊ
+ cluster-config: default
+# ÅäÖÃEurekaÖеÄserviceIdÁбí£¬±íÃ÷¼à¿ØÄÄЩ·þÎñ
+ app-config: upms,oauth
+ cluster-name-expression: new String("default")
+# 1. clusterNameExpressionָ¶¨¼¯ȺÃû³ƣ¬ĬÈϱí´ïʽappName£»´Ëʱ£ºturbine.aggregator.clusterConfigÐèҪÅäÖÃÏëҪ¼à¿صÄӦÓÃÃû³Æ
+# 2. µ±clusterNameExpression: defaultʱ£¬turbine.aggregator.clusterConfig¿ÉÒԲ»д£¬ÒòΪĬÈϾÍÊÇdefault
+# 3. µ±clusterNameExpression: metadata['cluster']ʱ£¬¼ÙÉèÏëҪ¼à¿صÄӦÓÃÅäÖÃÁËeureka.instance.metadata-map.cluster: ABC£¬ÔòÐèҪÅäÖã¬ͬʱturbine.aggregator.clusterConfig: ABC
\ No newline at end of file
diff --git a/ms/monitor-center/src/main/resources/bootstrap.yml b/ms/monitor-center/src/main/resources/bootstrap.yml
new file mode 100644
index 0000000..6edd051
--- /dev/null
+++ b/ms/monitor-center/src/main/resources/bootstrap.yml
@@ -0,0 +1,17 @@
+spring:
+ cloud:
+ config:
+ profile: dev
+ label: master
+ name: monitorcenter
+ discovery:
+ service-id: config-server
+ enabled: true
+ username: config
+ password: server
+eureka:
+ client:
+ serviceUrl:
+ defaultZone: http://micro:fast@www.register1.com:10002/eureka/,http://micro:fast@www.register2.com:10004/eureka/ #配置所有的注册中心
+ instance:
+ hostname: www.monitorcenter.com
diff --git a/ms/monitor-center/src/test/java/com/micro/fast/monitor/center/MsMonitorCenterApplicationTests.java b/ms/monitor-center/src/test/java/com/micro/fast/monitor/center/MsMonitorCenterApplicationTests.java
new file mode 100644
index 0000000..209fd9c
--- /dev/null
+++ b/ms/monitor-center/src/test/java/com/micro/fast/monitor/center/MsMonitorCenterApplicationTests.java
@@ -0,0 +1,16 @@
+package com.micro.fast.monitor.center;
+
+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 MsMonitorCenterApplicationTests {
+
+ @Test
+ public void contextLoads() {
+ }
+
+}
diff --git a/ms/oauth/README.md b/ms/oauth/README.md
new file mode 100644
index 0000000..2b27c08
--- /dev/null
+++ b/ms/oauth/README.md
@@ -0,0 +1,5 @@
+# ms-oauth 认证中心项目说明
+#### 添加服务消费功能
+#### 添加服务消费时的服务熔断,降级
+#### 服务熔断情况的统计
+监控界面访问地址`/hystrix`,监控数据的获取地址`hystrix.stream`
\ No newline at end of file
diff --git a/ms/oauth/pom.xml b/ms/oauth/pom.xml
index a4fbe48..ccf518b 100644
--- a/ms/oauth/pom.xml
+++ b/ms/oauth/pom.xml
@@ -32,11 +32,12 @@
org.springframework.cloud
spring-cloud-starter-config
-
+
org.springframework.cloud
spring-cloud-starter-eureka
+
org.springframework.cloud
spring-cloud-starter-ribbon
@@ -45,10 +46,16 @@
org.springframework.cloud
spring-cloud-starter-feign
+
org.springframework.cloud
spring-cloud-starter-hystrix
-
+
+
+
+ org.springframework.cloud
+ spring-cloud-starter-hystrix-dashboard
+
org.springframework.boot
diff --git a/ms/oauth/src/main/java/com/micro/fast/oauth/OauthApplication.java b/ms/oauth/src/main/java/com/micro/fast/oauth/OauthApplication.java
index 652313a..163cb56 100644
--- a/ms/oauth/src/main/java/com/micro/fast/oauth/OauthApplication.java
+++ b/ms/oauth/src/main/java/com/micro/fast/oauth/OauthApplication.java
@@ -3,13 +3,20 @@ package com.micro.fast.oauth;
import org.springframework.boot.SpringApplication;
import org.springframework.cloud.client.SpringCloudApplication;
import org.springframework.cloud.netflix.feign.EnableFeignClients;
+import org.springframework.cloud.netflix.hystrix.EnableHystrix;
+import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;
/**
* 前台用户认证中心
* @author lsy
*/
@SpringCloudApplication
+//服务调用
@EnableFeignClients
+//熔断
+@EnableHystrix
+//对用熔断情况进行统计并展示
+@EnableHystrixDashboard
public class OauthApplication {
public static void main(String[] args) {
diff --git a/ms/oauth/src/main/java/com/micro/fast/oauth/feign/UpmsUserService.java b/ms/oauth/src/main/java/com/micro/fast/oauth/feign/UpmsUserService.java
index 91b7bde..5189c03 100644
--- a/ms/oauth/src/main/java/com/micro/fast/oauth/feign/UpmsUserService.java
+++ b/ms/oauth/src/main/java/com/micro/fast/oauth/feign/UpmsUserService.java
@@ -2,6 +2,7 @@ package com.micro.fast.oauth.feign;
import com.micro.fast.boot.starter.common.response.ServerResponse;
import com.micro.fast.oauth.dto.UpmsUser;
+import com.micro.fast.oauth.feign.fallback.UpmsUserServiceFallback;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
@@ -10,7 +11,7 @@ import org.springframework.web.bind.annotation.PathVariable;
* 远程获取用户信息
* @author lsy
*/
-@FeignClient(name = "upms")
+@FeignClient(name = "upms",fallback = UpmsUserServiceFallback.class)
public interface UpmsUserService {
/**
diff --git a/ms/oauth/src/main/java/com/micro/fast/oauth/feign/fallback/UpmsUserServiceFallback.java b/ms/oauth/src/main/java/com/micro/fast/oauth/feign/fallback/UpmsUserServiceFallback.java
new file mode 100644
index 0000000..59079bf
--- /dev/null
+++ b/ms/oauth/src/main/java/com/micro/fast/oauth/feign/fallback/UpmsUserServiceFallback.java
@@ -0,0 +1,19 @@
+package com.micro.fast.oauth.feign.fallback;
+
+import com.micro.fast.boot.starter.common.response.ServerResponse;
+import com.micro.fast.oauth.dto.UpmsUser;
+import com.micro.fast.oauth.feign.UpmsUserService;
+import org.springframework.stereotype.Component;
+
+/**
+ * UpmsUserService类服务调用失败时候调用的方法,需要把这个类注入到ioc中
+ * @author lsy
+ */
+@Component
+public class UpmsUserServiceFallback implements UpmsUserService{
+
+ @Override
+ public ServerResponse getUserByUserName(String username) {
+ return ServerResponse.error();
+ }
+}
diff --git a/ms/oauth/src/main/resources/application.yml b/ms/oauth/src/main/resources/application.yml
deleted file mode 100644
index e69de29..0000000
diff --git a/ms/oauth/src/main/resources/bootstrap.yml b/ms/oauth/src/main/resources/bootstrap.yml
index 58e032c..6fd4d18 100644
--- a/ms/oauth/src/main/resources/bootstrap.yml
+++ b/ms/oauth/src/main/resources/bootstrap.yml
@@ -16,3 +16,7 @@ eureka:
defaultZone: http://micro:fast@www.register1.com:10002/eureka/,http://micro:fast@www.register2.com:10004/eureka/ #配置所有的注册中心
instance:
hostname: www.oauth.com
+# 允许feign负载均衡降级
+feign:
+ hystrix:
+ enabled: true
diff --git a/ms/pom.xml b/ms/pom.xml
index 201531c..ce90f3a 100644
--- a/ms/pom.xml
+++ b/ms/pom.xml
@@ -52,6 +52,7 @@
config-server
register-center1
register-center2
+ monitor-center
oauth
gateway
upms
diff --git a/ms/upms/README.md b/ms/upms/README.md
index faff7e5..7ade729 100644
--- a/ms/upms/README.md
+++ b/ms/upms/README.md
@@ -1 +1,7 @@
-###用户权限管理系统
+# 用户权限管理系统
+#### 添加使用消息总线刷新配置客户端的配置
+修改配置中心的文件配置。访问消息总线中某一个系统的`/bus/refresh`,将会刷新整个集群的配置。
+也可以访问`/bus/refresh?destination=customers:**`来刷新服务名为`customers`
+不管ip的配置。
+#### 服务熔断情况的统计
+监控界面访问地址`/hystrix`,监控数据的获取地址`hystrix.stream`
diff --git a/ms/upms/pom.xml b/ms/upms/pom.xml
index 840dc3b..1dfcae2 100644
--- a/ms/upms/pom.xml
+++ b/ms/upms/pom.xml
@@ -32,11 +32,12 @@
org.springframework.cloud
spring-cloud-starter-config
-
+
org.springframework.cloud
spring-cloud-starter-eureka
+
org.springframework.cloud
spring-cloud-starter-ribbon
@@ -45,23 +46,32 @@
org.springframework.cloud
spring-cloud-starter-feign
-
+
org.springframework.boot
spring-boot-starter-test
test
-
-
-
-
-
-
-
+
org.springframework.cloud
spring-cloud-starter-hystrix
+
+
+ org.springframework.cloud
+ spring-cloud-starter-hystrix-dashboard
+
+
+
+ org.springframework.cloud
+ spring-cloud-starter-bus-amqp
+
+
+ org.springframework.retry
+ spring-retry
+
+
@@ -69,27 +79,7 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/ms/upms/src/main/java/com/micro/fast/upms/UpmsApplication.java b/ms/upms/src/main/java/com/micro/fast/upms/UpmsApplication.java
index 66117a8..ef04401 100644
--- a/ms/upms/src/main/java/com/micro/fast/upms/UpmsApplication.java
+++ b/ms/upms/src/main/java/com/micro/fast/upms/UpmsApplication.java
@@ -6,6 +6,8 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.cloud.client.SpringCloudApplication;
import org.springframework.cloud.netflix.feign.EnableFeignClients;
+import org.springframework.cloud.netflix.hystrix.EnableHystrix;
+import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;
import org.springframework.context.annotation.Bean;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
@@ -13,9 +15,14 @@ import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
* @author lsy
*/
@SpringCloudApplication
-@EnableFeignClients
@MapperScan(basePackages = {"com.micro.fast.upms.dao"})
@EnableAutoConfiguration(exclude = DataSourceAutoConfiguration.class)
+//服务调用
+@EnableFeignClients
+//熔断
+@EnableHystrix
+//对用熔断情况进行统计并展示
+@EnableHystrixDashboard
public class UpmsApplication {
public static void main(String[] args) {
diff --git a/ms/upms/src/main/resources/bootstrap.yml b/ms/upms/src/main/resources/bootstrap.yml
index 3946937..5e9a20c 100644
--- a/ms/upms/src/main/resources/bootstrap.yml
+++ b/ms/upms/src/main/resources/bootstrap.yml
@@ -12,15 +12,23 @@ spring:
enabled: true
username: config
password: server
+# 允许记录消息的所有发送和接收事件
+ bus:
+ trace:
+ enabled: true
+# 消息总线
+ rabbitmq:
+ host: localhost
+ port: 5672
eureka:
client:
serviceUrl:
defaultZone: http://micro:fast@www.register1.com:10002/eureka/,http://micro:fast@www.register2.com:10004/eureka/ #配置所有的注册中心
instance:
hostname: www.upms.com
+# 日志配置
logging:
config: classpath:log4j2.xml
-