コード例 #1
0
        public static IApplicationBuilder MapReverseProxyWithQueueDelegation(this IApplicationBuilder app)
        {
            IServerDelegationFeature delegationFeature = app.ServerFeatures.Get <IServerDelegationFeature>();

            if (delegationFeature == null)
            {
                throw new NotSupportedException($"The {nameof(IServerDelegationFeature)} is not supported by the current OS.");
            }

            var delegationRuleProvider = new QueueDelegationRuleProvider(
                delegationFeature,
                app.ApplicationServices.GetRequiredService <IProxyConfigProvider>(),
                app.ApplicationServices.GetRequiredService <ILogger <QueueDelegationRuleProvider> >());

            app.ApplicationServices.GetRequiredService <IHostApplicationLifetime>().ApplicationStopped.Register(() => delegationRuleProvider.Dispose());

            app.UseRouting();
            app.UseEndpoints(endpoints =>
            {
                endpoints.MapReverseProxy(proxyPipeline =>
                {
                    proxyPipeline.UseMiddleware <QueueDelegationMiddleware>(delegationRuleProvider);
                });
            });

            return(app);
        }
コード例 #2
0
 public QueueDelegationMiddleware(
     RequestDelegate next,
     ILogger <QueueDelegationMiddleware> logger,
     QueueDelegationRuleProvider delegationRuleProvider)
 {
     this.next   = next;
     this.logger = logger;
     this.delegationRuleProvider = delegationRuleProvider;
 }