测试环境
网关程序包:下载 gmp-fm-jt-teng-springgateway-sv-8.2.0-SNAPSHOT.jar
服务提供者包:下载 necp-boot-demo-provider-0.0.1-SNAPSHOT.jar
服务消费者包: 下载necp-boot-demo-consumer-0.0.1-SNAPSHOT.jar
配置
服务提供者配置
-Dtsf_ratelimit_master_ip=10.51.101.185 -Dtsf.swagger.enabled=false -Dtsf_ratelimit_master_port=80 -Dtsf_config_encrypt_password=YGsoft.2022 -Dtsf_token=B7_8OcK4H3_hG3DCXzC_IvwAF1dCAutPWUfZakrF-gE= -Dtsf_namespace_id=namespace-apbldo3y -Dtsf_application_id=application-youg-provider -Dtsf_app_id=51 -Dtsf_group_id=group-yqomolev -Dtsf_consul_ip=10.51.101.185 -Dtsf_consul_port=8500 -Dspring.application.name=tsf-demo-provider
服务消费者配置
-Dtsf_ratelimit_master_ip=10.51.101.185 -Dtsf.swagger.enabled=false -Dtsf_ratelimit_master_port=80 -Dtsf_config_encrypt_password=YGsoft.2022 -Dtsf_token=B7_8OcK4H3_hG3DCXzC_IvwAF1dCAutPWUfZakrF-gE= -Dtsf_namespace_id=namespace-apbldo3y -Dtsf_application_id=application-youg-consmer -Dtsf_app_id=61 -Dtsf_group_id=group-yqomolev -Dtsf_consul_ip=10.51.101.185 -Dtsf_consul_port=8500 -Dspring.application.name=tsf-demo-consumer
网关配置
-Dtsf_ratelimit_master_ip=10.51.101.185 -Dtsf_ratelimit_master_port=80 -Dtsf_config_encrypt_password=YGsoft.2022 -Dtsf_token=B7_8OcK4H3_hG3DCXzC_IvwAF1dCAutPWUfZakrF-gE= -Dtsf_namespace_id=namespace-apbldo3y -Dtsf_application_id=application-yx5o5b4a -Dtsf_app_id=41 -Dtsf_group_id=group-yqomolev -Dtsf_consul_ip=10.51.101.185 -Dtsf_consul_port=8500 -Dspring.application.name=scg-luyong -Dlogging.file.path=D:/LOGS
网关路由配置
hystrix:
# 线程池
threadpool:
default:
#默认为10,基本得原则时保持线程池尽可能小,他主要是为了释放压力,防止资源被阻塞
coreSize: 10
#BlockingQueue的最大队列数,默认值-1
maxQueueSize: 1500
#动态控制线程池队列的上限,即使maxQueueSize没有达到,达到queueSizeRejectionThreshold该值后,请求会被拒绝,默认值5
queueSizeRejectionThreshold: 1000
command:
default:
circuitBreaker:
requestVolumeThreshold: 2 #同一时间窗口最多允许失败并不熔断的线程数,如果值是20,在一个窗口内(比如10秒),收到19个请求,即使这19个请求都失败了,断路器也不会打开
execution:
timeoutInMilliseconds: 2000 #如果集成了ribbon,需大于ribbon的超时 ,此值 如果不配置则以ribbon的超时为主,配置则以配置为主,也可以独立为具体服务配置.
isolation:
thread:
timeoutInMilliseconds: 2000 #如果集成了ribbon,需大于ribbon的超时 ,此值 如果不配置则以ribbon的超时为主,配置则以配置为主,也可以独立为具体服务配置.
coreSize: 100
maxQueueSize: 200
semaphore:
maxConcurrentRequests: 500 #最大允许的并发获得的信号量数,默认为10个
fallback:
isolation:
semaphore:
maxConcurrentRequests: 500 #允许调用降级回调的并发数,超过这个数将无法降级回调.,默认为10个
spring:
servlet:
multipart:
# 单个文件最大大小
max-file-size: 500MB
# 所有上传文件最大大小
max-request-size: 500MB
main:
allow-bean-definition-overriding: true
application:
name: global-tsf-scg
cloud:
consul:
enabled: true
discovery:
preferIpAddress: true
queryPassing: true
enabled: true
register: true #是否将自身服务注册到consul中
#hostname: 10.51.101.185
healthCheckPath: /actuator/health #服务健康检查地址
healthCheckInterval: 15s
serviceName: ${spring.application.name}
tags: tsf scg网关
gateway:
httpclient:
connect-timeout: 2000
response-timeout: 6s
actuator:
verbose:
enabled: true
discovery:
locator:
enabled: false # 默认从注册中还那样动态创建路由的功能,利用微服务名进行路由
# 所有路由都会应用的过滤器
default-filters:
- name: Hystrix # 配置熔断过滤器
args:
name: defaultfallbackcmd
fallbackUri: forward:/defaultfallback
routes:
- id: jt-tsf-demo-provider1
uri: lb://jt-mapp-provider
predicates:
- Path= /fms/prdweb/**
filters:
- StripPrefix=2
以上配置中,对于超时有以下几外配置
gateway:
httpclient:
connect-timeout: 2000
response-timeout: 6s
与
execution:
timeoutInMilliseconds: 2000
isolation:
thread:
timeoutInMilliseconds: 2000
这几处的优先级为哪个最小就优先哪个,以最小的超时时长作为判断点。
熔断测试
1、 启动网关
2、通过postman测试以下地址
http://网关IP:端口/fms/prdweb/jt/mapp/provider/list?param1=1¶m2=2&sleepSeconds=1
其中sleepSeconds为设定的休眠秒数,根据网关的熔断时长来定。
3、 在上述测试的restful接口中休眠超过网关 配置的熔断超时时长
4、网关会打印熔断信息,并返回默认的降级结果
{
"code": "5001",
"msg": "请求发生熔断:http://10.20.28.150:8201/api/jt/mapp/provider/list"
}
5、去掉api中的休眠调用正常。
评论区