Add the `IForwarderService` interface to override the implementation logic of `ForwarderMiddleware`
xljiulang opened this issue · comments
I am currently developing a very interesting project called CYarp, which uses YARP to reverse proxy millions of devices with the same http service under NAT. In this project, it cannot be considered that YARP has only one ClusterConfig instance and there are millions of Destinations under this instance. Instead, it should be considered that the http service of each device is a ClusterConfig instance and there is only one Destinations element under this instance. After this, the number of ClusterConfig instances in the project is equal to the number of devices. As devices are frequently connected and disconnected, the number of ClusterConfig instances is also constantly changing. Although it is true that the number of ClusterConfig instances changes frequently, the RouteConfig instances in the project are very stable. They often do not change after being configured in the configuration, and the number is very small. But now I want Route to cover all device instances, I had to create RouteConfig instances that were N times the number of devices, which was too heavy a load for asp.netcore routing and could not get satisfactory performance.
In this project of mine, I really want to use YARP's dynamic routing and powerful routing configuration capabilities, but I don't want to affect the Cluster because a certain device is online or offline, which will ultimately affect the re-creation of dynamic routing. Currently, I find it the most convenient The entry point may be to modify the internal sealed class ForwarderMiddleware
middleware. If YARP can transfer the implementation code of this middleware to a public service interface such as YarpDefaultForwarderService:IForwarderService, as an upper-level developer, I You can register MyDynamicForwarderService to override the default implementation of IForwarderService and implement Http forwarding without relying on the Cluster associated with the current route.
I hope the masters can understand and listen to my needs. Thank you very much!
I found that adding custom middleware to IReverseProxyApplicationBuilder can meet my needs! There is currently only one regret: RouteConfig must have a corresponding ClusterId value.
// app.UseMiddleware<MyDynamicForwarderMiddleware>();
app.MapReverseProxy(yarpApp =>
{
yarpApp.UseMiddleware<MyDynamicForwarderMiddleware>();
});