Gur*_*_07 5 c# failover api-gateway ms-yarp
我使用 Microsoft C# .NET YARP作为 ASP.NET Core Web API(最新版本)以及 Swagger 和 Kestrel 前面的 API 网关。YARP 用于到许多微服务的内部重定向。
问题:
例如:https://URL/swagger/index.html => 执行 POST FUNCTION => YARP_API_GATEWAY => SERVICE_API_PORT
前任。配置:
"ReverseProxy": {
"Routes": [
{
"RouteId": "Service1",
"ClusterId": "ServiceCluster1",
"Match": {
"Path": "/api/Action1/{**rest}"
},
"Transforms": [
{ "RequestHeadersCopy": "true" },
{ "RequestHeaderOriginalHost": "true" }
]
},
{
"RouteId": "Service2",
"ClusterId": "ServiceCluster2",
"Match": {
"Path": "/api/Action2/{**rest}"
},
"Transforms": [
{ "RequestHeadersCopy": "true" },
{ "RequestHeaderOriginalHost": "true" }
]
],
"Clusters": {
"ServiceCluster1": {
"Destinations": {
"ServiceCluster1/destination1": {
"Address": "http://localhost:5001/"
},
"ServiceCluster1/destination2": {
"Address": "http://localhost:5002/"
}
}
},
"ServiceCluster2": {
"Destinations": {
"ServiceCluster2/destination1": {
"Address": "http://localhost:5003/"
},
"ServiceCluster2/destination2": {
"Address": "http://localhost:5004/"
}
}
},
}
Run Code Online (Sandbox Code Playgroud)
我没有使用过 YARP,但从文档来看它看起来像:
传出 HTTP 请求的默认超时为 100 秒。您可以通过设置 HttpMessageInvoker 超时来设置每个集群的超时,例如,将以下内容添加到每个集群内的集群配置中:
"HttpRequest": {
"ActivityTimeout": "00:05:00"
},
Run Code Online (Sandbox Code Playgroud)
您可以使用被动运行状况检查来避免请求失败后的目的地(同样,在集群级别设置):
"HealthCheck": {
"Passive": {
"Enabled": "true",
"Policy": "TransportFailureRate",
"ReactivationPeriod": "00:10:00"
}
},
Run Code Online (Sandbox Code Playgroud)
为了更快地响应目标关闭,您可以配置定期主动运行状况检查。
| 归档时间: |
|
| 查看次数: |
2457 次 |
| 最近记录: |