gpt4 book ai didi

hystrix - Spring Async 方法或事件抛出 HystrixRequestContext.initializeContext() 异常

转载 作者:行者123 更新时间:2023-12-05 07:50:00 35 4
gpt4 key购买 nike

我们的代码有一些@Async 方法和 ApplicationListeners。这些类和方法最终调用具有 @Hystrix 注释的 API 服务。这些调用抛出以下异常:

java.lang.IllegalStateException: HystrixRequestContext.initializeContext() must be called at the beginning of each request before RequestVariable functionality can be used.
at com.netflix.hystrix.strategy.concurrency.HystrixRequestVariableDefault.get(HystrixRequestVariableDefault.java:76) ~[hystrix-core-1.4.10.jar:1.4.10]
at com.netflix.hystrix.strategy.concurrency.HystrixRequestVariableHolder.get(HystrixRequestVariableHolder.java:68) ~[hystrix-core-1.4.10.jar:1.4.10]
at com.netflix.hystrix.HystrixRequestLog.getCurrentRequest(HystrixRequestLog.java:85) ~[hystrix-core-1.4.10.jar:1.4.10]
at com.netflix.hystrix.AbstractCommand.<init>(AbstractCommand.java:274) ~[hystrix-core-1.4.10.jar:1.4.10]
at com.netflix.hystrix.HystrixCommand.<init>(HystrixCommand.java:142) ~[hystrix-core-1.4.10.jar:1.4.10]
at com.netflix.hystrix.HystrixCommand.<init>(HystrixCommand.java:128) ~[hystrix-core-1.4.10.jar:1.4.10]
at com.netflix.hystrix.contrib.javanica.command.AbstractHystrixCommand.<init>(AbstractHystrixCommand.java:55) ~[hystrix-javanica-1.4.10.jar:1.4.10]
at com.netflix.hystrix.contrib.javanica.command.GenericCommand.<init>(GenericCommand.java:33) ~[hystrix-javanica-1.4.10.jar:1.4.10]
at com.netflix.hystrix.contrib.javanica.command.GenericHystrixCommandFactory.create(GenericHystrixCommandFactory.java:32) ~[hystrix-javanica-1.4.10.jar:1.4.10]
at com.netflix.hystrix.contrib.javanica.command.GenericHystrixCommandFactory.create(GenericHystrixCommandFactory.java:21) ~[hystrix-javanica-1.4.10.jar:1.4.10]
at com.netflix.hystrix.contrib.javanica.command.AbstractHystrixCommandFactory.create(AbstractHystrixCommandFactory.java:78) ~[hystrix-javanica-1.4.10.jar:1.4.10]
at com.netflix.hystrix.contrib.javanica.aop.aspectj.HystrixCommandAspect.methodsAnnotatedWithHystrixCommand(HystrixCommandAspect.java:81) ~[hystrix-javanica-1.4.10.jar:1.4.10]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_60]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_60]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_60]
at java.lang.reflect.Method.invoke(Method.java:497) ~[na:1.8.0_60]
at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:621) ~[spring-aop-4.2.3.RELEASE.jar:4.2.3.RELEASE]
at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:610) ~[spring-aop-4.2.3.RELEASE.jar:4.2.3.RELEASE]
at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:68) ~[spring-aop-4.2.3.RELEASE.jar:4.2.3.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:168) [spring-aop-4.2.3.RELEASE.jar:4.2.3.RELEASE]
at org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedingJoinPoint.java:85) ~[spring-aop-4.2.3.RELEASE.jar:4.2.3.RELEASE]
at com.intuit.platform.common.aop.InstrumentationAspect.profile(InstrumentationAspect.java:25) ~[classes/:na]
at sun.reflect.GeneratedMethodAccessor204.invoke(Unknown Source) ~[na:na]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_60]
at java.lang.reflect.Method.invoke(Method.java:497) ~[na:1.8.0_60]

在 Async 方法中添加 HystrixRequestContext.initializeContext() 没有帮助。

最佳答案

您需要在发送请求之前初始化该值。覆盖 HystrixRequestVariableDefault

有关 Github 上这个问题的更多信息:https://github.com/Netflix/Hystrix/issues/895

关于hystrix - Spring Async 方法或事件抛出 HystrixRequestContext.initializeContext() 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36615252/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com