How use multiple cluster with same match route?? #1481
-
i want to use yarp to forward my selected url to another selected destination url based on (header-key), but if any the same match url with different cluster the second match route for the last cluster that i regitered is doesnt redirect to selection destination. lets say i have three json data like this [
{
"appName": "hello-world-app",
"apis": [
{
"apiUrl": "/api/v1/test",
"apiDestination": "/posts/3",
"hostDestination": "https://jsonplaceholder.typicode.com/"
}
]
},
{
"appName": "my-app",
"apis": [
{
"apiUrl": "/api/v1/test",
"apiDestination": "/posts/1",
"hostDestination": "https://jsonplaceholder.typicode.com/"
},
{
"apiUrl": "/api/v2/test",
"apiDestination": "/posts/2",
"hostDestination": "https://jsonplaceholder.typicode.com/"
}
]
}
] theres is two data with same apiUrl (it will be the same match route but different cluster) but different appName (its will be unique header values for Apus-app header key) foreach (var app in apiByAppGroups)
{
var destinations = new Dictionary<string, DestinationConfig>(StringComparer.OrdinalIgnoreCase);
foreach (var api in app.Apis)
{
routes.Add(new RouteConfig
{
RouteId = api.ApiUrl,
ClusterId = app.AppName,
Match = new RouteMatch
{
Path = api.ApiUrl,
Headers = new List<RouteHeader>
{
new RouteHeader
{
IsCaseSensitive = false,
Name = "apus-app",
Values = new List<string>
{
app.AppName
}
}
}
},
Transforms = new List<Dictionary<string, string>>
{
new Dictionary<string, string>
{
{ "PathSet", api.ApiDestination }
}
}
});
destinations.Add(api.ApiDestination, new DestinationConfig()
{
Address = api.HostDestination
});
}
clusters.Add( new ClusterConfig
{
ClusterId = app.AppName,
Destinations = destinations
});
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
Each route will direct to one cluster. I think what you are trying to ask is can you have 2 routes that match the same URL, but differentiate based on a header in the request? That is possible, and then those two routes can point at different clusters. |
Beta Was this translation helpful? Give feedback.
Each route will direct to one cluster. I think what you are trying to ask is can you have 2 routes that match the same URL, but differentiate based on a header in the request? That is possible, and then those two routes can point at different clusters.