3

私たちのコードには、いくつかの @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() を追加しても役に立ちません。

4

1 に答える 1

0

リクエストを送信する前に、値を初期化する必要があります。HystrixRequestVariableDefault をオーバーライドする

詳細については、Github のこの問題: https://github.com/Netflix/Hystrix/issues/895

于 2016-09-07T15:04:37.577 に答える