[英]Having trouble for hitting two destination in YARP
I have two controller that I want to hit both controllers api at same time but it can hit only once randomly so please guide me solution from which I can solve this problem.我有两个控制器,我想同时命中两个控制器 api,但它只能随机命中一次,所以请指导我解决这个问题的解决方案。
TeaController茶控制器
[Route("api/[controller]")]
[ApiController]
public class TeaController : ControllerBase
{
[HttpGet("Test")]
public IActionResult Test()
{
return Ok("Tea");
}
}
BiscuitController饼干控制器
[Route("api/[controller]")]
[ApiController]
public class BiscuitController : ControllerBase
{
[HttpGet("Test")]
public IActionResult Test()
{
return Ok("Biscuit");
}
}
}
appsettings.json应用设置.json
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*",
"UseCodeBasedConfig": "true",
"ReverseProxy": {
"Routes": {
"ReverseProxy-route": {
"ClusterId": "ReverseProxy-cluster",
"Match": {
"Path": "ReverseProxy/{**catch-all}"
},
"Transforms": [
{
"PathPattern": "{**catch-all}"
}
]
}
},
"Clusters": {
"ReverseProxy-cluster": {
"Destinations": {
"LoadBalancingPolicy": "Random",
"ReverseProxy-cluster/destination1": {
"Address": "https://localhost:7044/api/biscuit"
},
"ReverseProxy-cluster/destination2": {
"Address": "https://localhost:7044/api/tea"
}
}
}
}
}
}
program.cs程序.cs
var builder = WebApplication.CreateBuilder(args);
var proxyBuilder = builder.Services.AddReverseProxy().LoadFromConfig(builder.Configuration.GetSection("ReverseProxy"));
var app = builder.Build();
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Error");
app.UseHsts();
}
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapReverseProxy();
});
app.Run();
You have LoadBalancingPolicy
specified as Random
, with both controllers as one of two destinations.您将
LoadBalancingPolicy
指定为Random
,两个控制器都作为两个目的地之一。 Random
will unsurprisingly: Random
将毫不奇怪:
Select a destination randomly.
随机选择一个目的地。
There doesn't appear to be a way to "hit both at the same time" for the given built in policies.对于给定的内置策略,似乎没有办法“同时击中两者”。 I would recommend you take a look at the policies to see which fits your need.
我建议您查看这些政策,看看哪些适合您的需要。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.