Commit 9aee62c7 authored by duanledexianxianxian's avatar duanledexianxianxian 😁

add hystric

parent 6763b5ac
Pipeline #114 failed
......@@ -14,7 +14,18 @@ springboot与spring cloud兼容版本
| Edgware | 1.5.x |
| Dalston | 1.5.x |
### 核心组件
- Eureka:服务治理组件,包含服务注册与发现
- Hystrix(豪猪):容错管理组件,实现了熔断器
- Ribbon:客户端负载均衡的服务调用组件
- Feign:基于Ribbon和Hystrix的声明式服务调用组件
- Zuul:网关组件,提供智能路由、访问过滤等功能
- Spring Cloud Config:配置管理工具,实现应用配置的外部化存储,支持客户端配置信息刷新、加密/解密配置内容等。
- Spring Cloud Bus:事件、消息总线,用于传播集群中的状态变化或事件,以及触发后续的处理
- Spring Cloud Security:基于spring security的安全工具包,为我们的应用程序添加安全控制
- Spring Cloud Consul : 封装了Consul操作,Consul是一个服务发现与配置工具(与Eureka作用类似),与Docker容器可以无缝集成
### 应用端口配置
......@@ -30,6 +41,43 @@ springboot与spring cloud兼容版本
user-service:9204
order-service:9203
### 性能指标
**PV** 即 page view,页面浏览量 用户每一次对网站中的每个页面访问均被记录1次。用户对同一页面的多次刷新,访问量累计。
**UV** 即 Unique visitor,独立访客 通过客户端的cookies实现。即同一页面,客户端多次点击只计算一次,访问量不累计。
**IP** 即 Internet Protocol,本意本是指网络协议,在数据统计这块指通过ip的访问量。 即同一页面,客户端使用同一个IP访问多次只计算一次,访问量不累计。
UV、IP的区别
1. 比如你是ADSL拨号上网,拨一次号自动分配一个IP,进入了网站,就算一个IP;断线了而没清理Cookies,又拨号一次自动分配一个IP,又进入了同一个网站,又统计到一个IP,这时统计数据里IP就显示统计了2次。UV没有变,是1次。
2. 同一个局域网内2个人,在2台电脑上访问同一个网站,他们的公网IP是相同的。IP就是1,但UV是2。
**TPS** 即Transactions Per Second的缩写,每秒处理的事务数目。一个事务是指一个客户机向服务器发送请求然后服务器做出反应的过程。客户机在发送请求时开始计时,收到服务器响应后结束计时,以此来计算使用的时间和完成的事务个数,最终利用这些信息作出的评估分。
**QPS** 即Queries Per Second的缩写,每秒能处理查询数目。是一台服务器每秒能够相应的查询次数,是对一个特定的查询服务器在规定时间内所处理流量多少的衡量标准。
**RPS** 即Requests Per Second的缩写,每秒能处理的请求数目。等效于QPS
### 概念
1. **服务雪崩效应**
分布式系统中经常会出现某个基础服务不可用造成整个系统不可用的情况,这种现象被称为服务雪崩效应
2.
### 服务网关
服务网关的作用:**网关作为对外的门户,实现动态路由、监控、授权、安全、调度等功能。**
......@@ -108,4 +156,5 @@ Spring Cloud Gateway VS Zuul
4. https://natapp.cn/article/natapp_newbie
5. https://my.oschina.net/u/3266761/blog/2245498
6. https://segmentfault.com/a/1190000019137876?utm_source=tag-newest
7. https://blog.csdn.net/lvqingyao520/article/details/78756959
......@@ -36,5 +36,9 @@
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bus-amqp</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
</dependencies>
</project>
......@@ -2,7 +2,8 @@ package com.duanledexian.spring.cloud.order;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
/**
* 服务提供方
......@@ -10,7 +11,8 @@ import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
* @author Administrator
*/
@SpringBootApplication
@EnableEurekaClient
@EnableDiscoveryClient
@EnableFeignClients
public class SpringOrderServiceApplication {
public static void main(String[] args) {
......
package com.duanledexian.spring.cloud.order.api;
import org.springframework.stereotype.Component;
/**
* @author duanledexianxianxian
* @date 2019/9/4 3:46
* @since 1.0.0
*/
@Component
public class HelloRemoteHystrix implements IHelloApi {
@Override
public String sayHello(String name) {
return "曹操";
}
}
package com.duanledexian.spring.cloud.order.api;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
/**
* The interface Hello api.
*
* @author Administrator
*/
@FeignClient(name = "user-service", fallback = HelloRemoteHystrix.class)
public interface IHelloApi {
/**
* Say hello string.
*
* @param name the name
* @return the string
*/
@GetMapping("/api/v1/sayHello")
String sayHello(@RequestParam("name") String name);
}
package com.duanledexian.spring.cloud.order.controller;
import com.duanledexian.spring.cloud.order.api.IHelloApi;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
......@@ -16,13 +18,15 @@ import org.springframework.web.bind.annotation.RestController;
@RefreshScope
@Slf4j
public class HomeController {
@Autowired
private IHelloApi helloApi;
@Value("${hello.name:world}")
private String name;
@GetMapping("/sayHello")
public String sayHello() {
return "order-service hello " + name;
return helloApi.sayHello("order service");
}
}
......@@ -22,3 +22,6 @@ eureka:
client:
service-url:
defaultZone: http://localhost:9000/eureka/
feign:
hystrix:
enabled: true
......@@ -18,11 +18,11 @@ import org.springframework.web.bind.annotation.RestController;
public class HomeController {
@Value("${hello.name:world}")
private String name;
private String applicationName;
@GetMapping("/sayHello")
public String sayHello() {
return "hello " + name;
public String sayHello(String name) {
return "hello " + name + " " + applicationName;
}
}
......@@ -22,3 +22,5 @@ eureka:
client:
service-url:
defaultZone: http://localhost:9000/eureka/
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment