Reputation: 392
I am using Microsoft C# .NET YARP as an API gateway in front of ASP.NET Core Web API (latest version) with Swagger and Kestrel. YARP is used for intern redirections to many microservices.
Questions:
Ex: https://URL/swagger/index.html => Execute POST FUNCTION => YARP_API_GATEWAY => SERVICE_API_PORT
Ex. configuration:
"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/"
}
}
},
}
Upvotes: 5
Views: 3870
Reputation: 11
As per YARP documentation docs a Custom policy can be implemented by Inheriting from ILoadBalancingPolicy
in Yarp.ReverseProxy.LoadBalancing
namespace, You can incorporate a method within the implementation that issues a request to the desired endpoint before proceeding to the next destination, something like this:
private async Task<Bool> TryForwardToDestination(HttpContext context, DestinationState destinationToReach)
Upvotes: 0
Reputation: 12330
I've not used YARP but going from the docs it looks like:
Default timeout for an outgoing HTTP request is 100 seconds. You can set the timeout per cluster via setting the HttpMessageInvoker timeout, e.g. add the following to the cluster config within each cluster:
"HttpRequest": {
"ActivityTimeout": "00:05:00"
},
You can use passive health checks to avoid destinations after a failed request (again, set at cluster level):
"HealthCheck": {
"Passive": {
"Enabled": "true",
"Policy": "TransportFailureRate",
"ReactivationPeriod": "00:10:00"
}
},
For a faster response to the destination being down, you can configure regular active health checks.
Upvotes: 2