添加服务降级,服务熔断,消息总线,监控中心
This commit is contained in:
@@ -1 +1,3 @@
|
||||
###配置服务中心
|
||||
微服务中,可以将配置中心的值注入到服务的类的属性中。后续可以修改配置中心的
|
||||
配置,然后通过消息总线刷新整个微服务的配置
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>monitor-center</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>ms-monitor-center</name>
|
||||
<description>ms-monitor-center</description>
|
||||
|
||||
<parent>
|
||||
<groupId>com.micro.fast</groupId>
|
||||
<artifactId>ms</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
<java.version>1.8</java.version>
|
||||
<spring-cloud.version>Edgware.SR1</spring-cloud.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<!--配置加载-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-config</artifactId>
|
||||
</dependency>
|
||||
<!--注册-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-eureka</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||
</dependency>
|
||||
<!--对服务的断路由情况进行聚合-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-turbine</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-netflix-turbine</artifactId>
|
||||
</dependency>
|
||||
<!--测试-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
|
||||
</project>
|
||||
+17
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
@@ -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
|
||||
+16
@@ -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() {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
# ms-oauth 认证中心项目说明
|
||||
#### 添加服务消费功能
|
||||
#### 添加服务消费时的服务熔断,降级
|
||||
#### 服务熔断情况的统计
|
||||
监控界面访问地址`/hystrix`,监控数据的获取地址`hystrix.stream`
|
||||
+9
-2
@@ -32,11 +32,12 @@
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-config</artifactId>
|
||||
</dependency>
|
||||
<!--服务提供以及调用负载均衡-->
|
||||
<!--服务注册,服务提供-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-eureka</artifactId>
|
||||
</dependency>
|
||||
<!--服务调用-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-ribbon</artifactId>
|
||||
@@ -45,10 +46,16 @@
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-feign</artifactId>
|
||||
</dependency>
|
||||
<!--熔断,断的是这个服务调用其他服务时失败的时候断-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-hystrix</artifactId>
|
||||
</dependency>
|
||||
</dependency>
|
||||
<!--调用其他服务的时候熔断情况的图形化展示-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-hystrix-dashboard</artifactId>
|
||||
</dependency>
|
||||
<!--测试-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
/**
|
||||
|
||||
+19
@@ -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<UpmsUser> getUserByUserName(String username) {
|
||||
return ServerResponse.error();
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -52,6 +52,7 @@
|
||||
<module>config-server</module>
|
||||
<module>register-center1</module>
|
||||
<module>register-center2</module>
|
||||
<module>monitor-center</module>
|
||||
<module>oauth</module>
|
||||
<module>gateway</module>
|
||||
<module>upms</module>
|
||||
|
||||
+7
-1
@@ -1 +1,7 @@
|
||||
###用户权限管理系统
|
||||
# 用户权限管理系统
|
||||
#### 添加使用消息总线刷新配置客户端的配置
|
||||
修改配置中心的文件配置。访问消息总线中某一个系统的`/bus/refresh`,将会刷新整个集群的配置。
|
||||
也可以访问`/bus/refresh?destination=customers:**`来刷新服务名为`customers`
|
||||
不管ip的配置。
|
||||
#### 服务熔断情况的统计
|
||||
监控界面访问地址`/hystrix`,监控数据的获取地址`hystrix.stream`
|
||||
|
||||
+19
-29
@@ -32,11 +32,12 @@
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-config</artifactId>
|
||||
</dependency>
|
||||
<!--服务提供以及调用负载均衡-->
|
||||
<!--服务注册,服务提供-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-eureka</artifactId>
|
||||
</dependency>
|
||||
<!--服务消费-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-ribbon</artifactId>
|
||||
@@ -45,23 +46,32 @@
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-feign</artifactId>
|
||||
</dependency>
|
||||
<!--测试-->
|
||||
<!--测试-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<!--服务网关,更加强大的负载均衡-->
|
||||
<!--<dependency>-->
|
||||
<!--<groupId>org.springframework.cloud</groupId>-->
|
||||
<!--<artifactId>spring-cloud-starter-zuul</artifactId>-->
|
||||
<!--</dependency>-->
|
||||
|
||||
<!--熔断-->
|
||||
<!--熔断,断的是这个服务调用其他服务时失败的时候断-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-hystrix</artifactId>
|
||||
</dependency>
|
||||
<!--调用其他服务的时候熔断情况的图形化展示-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-hystrix-dashboard</artifactId>
|
||||
</dependency>
|
||||
<!--配置客户端配置刷新-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-bus-amqp</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.retry</groupId>
|
||||
<artifactId>spring-retry</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!--检测服务调用-->
|
||||
<!--<dependency>-->
|
||||
<!--<groupId>org.springframework.cloud</groupId>-->
|
||||
@@ -69,27 +79,7 @@
|
||||
<!--</dependency>-->
|
||||
|
||||
|
||||
<!--对断路由情况进行聚合-->
|
||||
<!--<dependency>-->
|
||||
<!--<groupId>org.springframework.cloud</groupId>-->
|
||||
<!--<artifactId>spring-cloud-starter-turbine</artifactId>-->
|
||||
<!--</dependency>-->
|
||||
<!--<dependency>-->
|
||||
<!--<groupId>org.springframework.cloud</groupId>-->
|
||||
<!--<artifactId>spring-cloud-netflix-turbine</artifactId>-->
|
||||
<!--</dependency>-->
|
||||
|
||||
<!--断路由仪表盘-->
|
||||
<!--<dependency>-->
|
||||
<!--<groupId>org.springframework.cloud</groupId>-->
|
||||
<!--<artifactId>spring-cloud-starter-hystrix-dashboard</artifactId>-->
|
||||
<!--</dependency>-->
|
||||
|
||||
<!--客户端配置刷新-->
|
||||
<!--<dependency>-->
|
||||
<!--<groupId>org.springframework.cloud</groupId>-->
|
||||
<!--<artifactId>spring-cloud-starter-bus-amqp</artifactId>-->
|
||||
<!--</dependency>-->
|
||||
|
||||
<!--服务调展示界面-->
|
||||
<!--<dependency>-->
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user