Closed ZhangNingPegasus closed 3 years ago
纠正一下: 使用的版本不是6.5.1,而是6.5.0
Discovery Agent和Hystrix增强包两者选一个即可,前者功能比后者强大,可以处理几乎所有异步场景,后者仅仅处理Hystrix异步
您说的Hystrix增强包指的是?
<!-- 当服务用Hystrix做线程隔离的时候,才需要导入下面的包 -->
<!-- <dependency>
<groupId>com.nepxion</groupId>
<artifactId>discovery-plugin-strategy-starter-hystrix</artifactId>
</dependency> -->
如下开关跟上面的增强包是配套的: spring.application.strategy.hystrix.threadlocal.supported=true
非常感谢您的回复,在使用Discovery Agent,并去掉Hystrix增强包(discovery-plugin-strategy-starter-hystrix)的前提下,不再报空指针的错误,但是在多线程的feign调用下,灰度发布出现失效的情况。
相关配置:
feign.hystrix.enabled=true spring.application.strategy.hystrix.threadlocal.supported=false
注册中心:consul
配置中心: Apollo
配置xml (全链路条件灰度发布):
`<?xml version="1.0" encoding="UTF-8"?>
`
说明:
网关会调用服务a,服务a会调用服务b, 网关只有一个版本1.0;a服务有1.1和1.2版本; b服务也有1.1和1.2版本。
在上面的配置下,所有请求都应该调用a服务的1.1版本和b服务的1.1版本
现象: 测试用例中,基于feign的invoke接口(同步调用)、invoke-async接口(加了@async注解)都能够正常的按照上面的灰度发布策略运行, 但是同样基于feign下的invoke-thread接口(单独开线程)和invoke-threadpool接口(使用线程池)却不行,具体表现是:服务a始终能走1.1版本, 但是调用到服务b时,却1.1和1.2版本都会运行。
VM options选项:
-javaagent:E:\Java\middleware\spring-cloud\service-demo\src\main\resources\agent\discovery-agent-starter-1.0.1.jar -Dthread.scan.packages=org.springframework.aop.interceptor;com.netflix.hystrix;org.wyyt.springcloud.service.demo.feign
服务a和服务b的POM依赖: `
<!-- 配置中心插件 -->
<dependency>
<groupId>com.nepxion</groupId>
<artifactId>discovery-plugin-config-center-starter-apollo</artifactId>
</dependency>
<!-- 管理中心插件 -->
<dependency>
<groupId>com.nepxion</groupId>
<artifactId>discovery-plugin-admin-center-starter</artifactId>
</dependency>
<!-- 服务的策略编排插件 -->
<dependency>
<groupId>com.nepxion</groupId>
<artifactId>discovery-plugin-strategy-starter-service</artifactId>
</dependency>
<!-- 熔断器 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
</dependency>`
网关pom: `
<!-- 配置中心插件 -->
<dependency>
<groupId>com.nepxion</groupId>
<artifactId>discovery-plugin-config-center-starter-apollo</artifactId>
</dependency>
<!-- 熔断器 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
</dependency>
<!-- 管理中心插件 -->
<dependency>
<groupId>com.nepxion</groupId>
<artifactId>discovery-plugin-admin-center-starter</artifactId>
</dependency>
<!-- 网关的策略编排插件 -->
<dependency>
<groupId>com.nepxion</groupId>
<artifactId>discovery-plugin-strategy-starter-gateway</artifactId>
</dependency>`
另外: discovery-agent-starter使用的是最新的1.0.1版本,但是控制打印的却是1.0.0版本
其他相关截图:
谢谢,问题已解决。
Nepxion版本: 6.5.1 Discovery Agent版本: 1.0.1 IDE: Intellj idea
问题: 在开启feign.hystrix.enabled=true时候,并使用javaagent进行多线程的调用,【RequestContextHolder.getRequestAttributes()】报空指针的错
报错类型: com.nepxion.discovery.plugin.strategy.service.wrapper.DefaultServiceStrategyCallableWrapper 代码行数: 32行
VM options参数: -javaagent:E:\Java\middleware\spring-cloud\service-demo\src\main\resources\agent\discovery-agent-starter-1.0.1.jar -Dthread.scan.packages=org.springframework.aop.interceptor;com.netflix.hystrix;org.wyyt.springcloud.service.demo.feign
以下两个配置都设置为了true feign.hystrix.enabled=true spring.application.strategy.hystrix.threadlocal.supported=true