我们在golang应用程序中使用hystrix,即使没有 hystrix:超时
,在这里我们也会收到 hystrix:电路断开错误hystrix配置:
hystrix.ConfigureCommand(cmd,hystrix.CommandConfig{
Timeout: timeout,MaxConcurrentRequests: 1000,ErrorPercentThreshold: 5,SleepWindow: 15 * 60 * 1000,//15 Minutes
})
在hystrix后备部分中,我们记录错误消息信息。我们可以清楚地看到我们只有 hystrix:电路断开错误,没有其他任何错误
有时它的行为非常随机,在下图中,我们可以看到 hystrix:超时和 hystrix:电路断开
之间没有相关性sudo / sample hystrix代码:
func crawl(vendor string,req *http.Request,timeout int) (result []byte) {
hystrix.Do(vendor,func() error {
resp,err := httpClient.Do(req)
if err != nil {
log.Errorln("Error sending post request: ",err)
} else {
defer resp.Body.Close()
}
respBody,errResp := ioutil.ReadAll(resp.Body)
if errResp != nil {
log.WithFields(log.Fields{"RequestID": requestID}).Errorln("Error reading parser response",errResp,resp.Status)
}
if resp.StatusCode == 200 {
result = respBody
} else {
log.Errorln(" SERVER SIDE ERROR",resp.StatusCode,obj)
}
return nil
},func(err error) error {
logApiTimeouts(vendor,err)
log.WithFields(log.Fields{"RequestID": requestID}).Errorln("Hystrix Error:",err,obj)
return nil
})
}
有人遇到此错误以及如何解决此错误吗?