有什么方法可以重试 Azure API 管理中的 'BackendConnectionFailure at transfer-response' 错误
Is there any way to retry 'BackendConnectionFailure at transfer-response' errors in Azure API Management
我遇到旧版 api 的间歇性连接问题,有时会导致
'BackendConnectionFailure at transfer-response' Azure API 管理返回错误。根据我的经验,重试对遗留 api 的请求通常会成功。我有一个类似于下面的重试策略来检查 5xx 状态代码,但是,重试似乎没有发生。
<retry
condition="@(context.Response.StatusCode == 500)"
count="10"
interval="10"
max-interval="100"
delta="10"
first-fast-retry="false">
<forward-request buffer-request-body="true" />
</retry>
经过进一步研究,Application Insights 似乎表明后端依赖项的调用状态 = false,但结果代码 = 200。
是否有任何方法可以检测到这种情况以便进行重试,或者可以使用任何其他策略?
在您上面的策略中,重试仅涵盖从后端接收响应状态代码和 headers。响应 body 不会被 APIM 主动读取,而是直接从后端逐个传输到客户端。这就是 "Transfer response" 的意思。到那时你的所有政策都已经完成。
避免这种情况的一种方法是在 APIM 端主动缓冲来自后端的响应。尝试在出站中添加为第一件事:
<set-body>@(context.Response.Body.As<byte[]>())</set-body>
我遇到旧版 api 的间歇性连接问题,有时会导致 'BackendConnectionFailure at transfer-response' Azure API 管理返回错误。根据我的经验,重试对遗留 api 的请求通常会成功。我有一个类似于下面的重试策略来检查 5xx 状态代码,但是,重试似乎没有发生。
<retry
condition="@(context.Response.StatusCode == 500)"
count="10"
interval="10"
max-interval="100"
delta="10"
first-fast-retry="false">
<forward-request buffer-request-body="true" />
</retry>
经过进一步研究,Application Insights 似乎表明后端依赖项的调用状态 = false,但结果代码 = 200。
是否有任何方法可以检测到这种情况以便进行重试,或者可以使用任何其他策略?
在您上面的策略中,重试仅涵盖从后端接收响应状态代码和 headers。响应 body 不会被 APIM 主动读取,而是直接从后端逐个传输到客户端。这就是 "Transfer response" 的意思。到那时你的所有政策都已经完成。
避免这种情况的一种方法是在 APIM 端主动缓冲来自后端的响应。尝试在出站中添加为第一件事:
<set-body>@(context.Response.Body.As<byte[]>())</set-body>