Hystrix 在回退中访问当前执行状态 [英] Hystrix getting access to the current execution state within fallback

查看:35
本文介绍了Hystrix 在回退中访问当前执行状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我成功配置了 spring-cloud(通过 spring-cloud-starter-hystrix)来封装对服务的调用.

I successfully configured spring-cloud (via spring-cloud-starter-hystrix) to wrap a call to a service.

这一切正常,如下所示:

This all works fine and looks like the following:

@Component
public class MyService {

  @HystrixCommand(fallbackMethod = "fallback")
  public void longRunning() {
     // this could fail
  }

  public void fallback() {
    // fallback code
  }
}

我现在的问题是,我想在 longRunning()

My question now is, I would like to log some statistics about the execution error in longRunning()

尝试在回退方法中访问 HystrixRequestLog.getCurrentRequest() 抛出

Trying to access HystrixRequestLog.getCurrentRequest() within the fallback method throws

java.lang.IllegalStateException: HystrixRequestContext.initializeContext() 必须在每个请求开始时调用,然后才能使用 RequestVariable 功能.

java.lang.IllegalStateException: HystrixRequestContext.initializeContext() must be called at the beginning of each request before RequestVariable functionality can be used.

如果调用回退,我正在寻找一种简单的方法来记录 longRunning 的异常.

I am looking for a simple way to log the exception of longRunning if the fallback is called.

使用 v1.0.0.RC2

推荐答案

要查看堆栈跟踪,您只需在 com.netflix.hystrix 中启用 DEBUG 日志记录即可.

To see a stack trace you can just enable DEBUG logging in com.netflix.hystrix.

据我所知,要使用 HystrixRequestContextMyService 的调用者必须在使用之前调用 HystrixRequestContext.initializeContext()服务.太糟糕了,所以如果有人有更好的主意,我很感兴趣.

As far as I can tell, to use the HystrixRequestContext the caller of MyService has to call HystrixRequestContext.initializeContext() before using the service. That sucks, so if anyone has a better idea, I'm interested.

这篇关于Hystrix 在回退中访问当前执行状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆