Spring cloud 记录hystrix命令中的错误
通过@HystrixCommand注释,可以配置一个回退方法,该方法应在该方法失败时运行Spring cloud 记录hystrix命令中的错误,spring-cloud,hystrix,Spring Cloud,Hystrix,通过@HystrixCommand注释,可以配置一个回退方法,该方法应在该方法失败时运行 public Link defaultDogeLink(Account account) { return null; } @HystrixCommand(fallbackMethod = "defaultDogeLink") public Link buildDogeLink(Account account) { // some cod
public Link defaultDogeLink(Account account) {
return null;
}
@HystrixCommand(fallbackMethod = "defaultDogeLink")
public Link buildDogeLink(Account account) {
// some code that may throw Runtime Exceptions
}
为了记录(在中心类中)所有用@HystrixCommand注释的方法中抛出的运行时异常,我应该做什么
我使用的是SpringCloudNetflix,而不是vanilla hystrix javanica。
我正在寻找类似于org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler类(用于Spring的@Async)的东西,我需要在我的应用程序中实现它
在hystrix core中,HystrixCommand类具有可在回退方法中用于记录异常的方法。有人能告诉我在使用hystrix javanica时如何获得此异常吗?我在hystrix javanica的单元测试中找到了获取最后执行的hystrix命令的方法:
public Link defaultDogeLink(Account account) {
LOG.warn("exception occured while building doge link for account " + account, getCommand().getFailedExecutionException());
return null;
}
@HystrixCommand(fallbackMethod = "defaultDogeLink")
public Link buildDogeLink(Account account) {
// some code that may throw Runtime Exceptions
}
private com.netflix.hystrix.HystrixInvokableInfo<?> getCommand() {
return HystrixRequestLog.getCurrentRequest().getAllExecutedCommands().iterator().next();
}
public Link defaultDogeLink(帐户){
LOG.warn(“为帐户+帐户,getCommand().getFailedExecutionException())构建doge链接时发生异常”;
返回null;
}
@HystrixCommand(fallbackMethod=“defaultDogeLink”)
公共链接buildDogeLink(帐户){
//一些可能引发运行时异常的代码
}
private com.netflix.hystrix.HystrixInvokableInfo getCommand(){
返回HystrixRequestLog.getCurrentRequest().getAllExecutedCommands().iterator().next();
}
它比预期的要详细一点,但满足了我的要求。Plain Hystrix允许您使用HystrixPlugins.getInstance().registerCommandExecutionHook()注册HystrixCommandExecutionHook。我在Spring环境中没有这方面的经验,但您可能想尝试一下。@marius_neo是对的,
@HystrixCommand
是香草hystrix javanica
,目前还没有Spring扩展,所以请尝试一下他的建议。