spring 启动 hystrix 集成
spring boot hystrix integration
我有以下方法
@HystrixCommand(commandKey="operator",fallbackMethod="getFakeResponse",commandProperties = {
@HystrixProperty(name = "hystrix.command.operator.execution.isolation.thread.timeoutInMilliseconds", value = "30000")
})
public String getResponse(){
try {
Thread.sleep(6000000l);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
// e.printStackTrace();
}
return "the real thing";
}
当我尝试 运行 我的单元测试代码来测试它时,我得到以下异常
com.netflix.hystrix.contrib.javanica.exception.HystrixPropertyException: Failed to set Command properties. groupKey: 'HystrixComponentPOC', commandKey: 'operator', threadPoolKey: ''
at com.netflix.hystrix.contrib.javanica.command.GenericSetterBuilder.build(GenericSetterBuilder.java:88)
at com.netflix.hystrix.contrib.javanica.command.AbstractHystrixCommand.(AbstractHystrixCommand.java:52)
at com.netflix.hystrix.contrib.javanica.command.GenericCommand.(GenericCommand.java:35)
at com.netflix.hystrix.contrib.javanica.command.HystrixCommandFactory.create(HystrixCommandFactory.java:44)
at com.netflix.hystrix.contrib.javanica.aop.aspectj.HystrixCommandAspect.methodsAnnotatedWithHystrixCommand(HystrixCommandAspect.java:85)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:629)
at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:618)
at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:70)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:168)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:655)
at com.masary.topup.HystrixComponentPOC$$EnhancerBySpringCGLIB$f9b3dd.getResponse()
at com.masary.topup.refactor.LedgerUpdateTestCases.test(LedgerUpdateTestCases.java:50)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.runners.model.FrameworkMethod.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:252)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:94)
at org.junit.runners.ParentRunner.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access[=12=]0(ParentRunner.java:58)
at org.junit.runners.ParentRunner.evaluate(ParentRunner.java:268)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:191)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Caused by: java.lang.IllegalArgumentException: unknown command property: hystrix.command.operator.execution.isolation.thread.timeoutInMilliseconds
at com.netflix.hystrix.contrib.javanica.conf.HystrixPropertiesManager.initializeProperties(HystrixPropertiesManager.java:125)
at com.netflix.hystrix.contrib.javanica.conf.HystrixPropertiesManager.initializeCommandProperties(HystrixPropertiesManager.java:99)
at com.netflix.hystrix.contrib.javanica.command.GenericSetterBuilder.build(GenericSetterBuilder.java:86)
... 47 more
但是,当我删除注释并添加
时,我可以 运行 使用异常行为成功
hystrix.command.operator.execution.isolation.thread.timeoutInMilliseconds=30000
到我的属性文件
顺便说一下,我唯一的配置是我的主 class 上的 @EnableHystrix,我正在使用 spring boot 1.4.0.RELEASE
有什么帮助吗?
您确定这是正确的命令 属性 名称吗?
不应该是
@HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "30000")
代替?
我有以下方法
@HystrixCommand(commandKey="operator",fallbackMethod="getFakeResponse",commandProperties = {
@HystrixProperty(name = "hystrix.command.operator.execution.isolation.thread.timeoutInMilliseconds", value = "30000")
})
public String getResponse(){
try {
Thread.sleep(6000000l);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
// e.printStackTrace();
}
return "the real thing";
}
当我尝试 运行 我的单元测试代码来测试它时,我得到以下异常
com.netflix.hystrix.contrib.javanica.exception.HystrixPropertyException: Failed to set Command properties. groupKey: 'HystrixComponentPOC', commandKey: 'operator', threadPoolKey: '' at com.netflix.hystrix.contrib.javanica.command.GenericSetterBuilder.build(GenericSetterBuilder.java:88) at com.netflix.hystrix.contrib.javanica.command.AbstractHystrixCommand.(AbstractHystrixCommand.java:52) at com.netflix.hystrix.contrib.javanica.command.GenericCommand.(GenericCommand.java:35) at com.netflix.hystrix.contrib.javanica.command.HystrixCommandFactory.create(HystrixCommandFactory.java:44) at com.netflix.hystrix.contrib.javanica.aop.aspectj.HystrixCommandAspect.methodsAnnotatedWithHystrixCommand(HystrixCommandAspect.java:85) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:629) at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:618) at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:70) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:168) at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:655) at com.masary.topup.HystrixComponentPOC$$EnhancerBySpringCGLIB$f9b3dd.getResponse() at com.masary.topup.refactor.LedgerUpdateTestCases.test(LedgerUpdateTestCases.java:50) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.junit.runners.model.FrameworkMethod.runReflectiveCall(FrameworkMethod.java:50) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26) at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75) at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86) at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:252) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:94) at org.junit.runners.ParentRunner.run(ParentRunner.java:290) at org.junit.runners.ParentRunner.schedule(ParentRunner.java:71) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access[=12=]0(ParentRunner.java:58) at org.junit.runners.ParentRunner.evaluate(ParentRunner.java:268) at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61) at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:191) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192) Caused by: java.lang.IllegalArgumentException: unknown command property: hystrix.command.operator.execution.isolation.thread.timeoutInMilliseconds at com.netflix.hystrix.contrib.javanica.conf.HystrixPropertiesManager.initializeProperties(HystrixPropertiesManager.java:125) at com.netflix.hystrix.contrib.javanica.conf.HystrixPropertiesManager.initializeCommandProperties(HystrixPropertiesManager.java:99) at com.netflix.hystrix.contrib.javanica.command.GenericSetterBuilder.build(GenericSetterBuilder.java:86) ... 47 more
但是,当我删除注释并添加
时,我可以 运行 使用异常行为成功hystrix.command.operator.execution.isolation.thread.timeoutInMilliseconds=30000
到我的属性文件
顺便说一下,我唯一的配置是我的主 class 上的 @EnableHystrix,我正在使用 spring boot 1.4.0.RELEASE
有什么帮助吗?
您确定这是正确的命令 属性 名称吗? 不应该是
@HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "30000")
代替?