コード例 #1
0
        public static void ConfigureSameNodeHandler(this IApplicationBuilder app, SameNodeCache sameNodeList, RoundRobin roundRobin)
        {
            app.Use(async(context, next) =>
            {
                // Getting ApiKey from the request stream (defined in ApiAuthenticationHandler)
                //
                var apiKey = context.Items["ProjectApiKey"];
                var ip     = context.GetClientIp();

                var cacheKey = string.Format("{0}-{1}", apiKey, ip);

                var sameNodeRequest    = sameNodeList.GetRequest(cacheKey);
                string currentNodeHost = null;

                // Is Cached
                //
                if (sameNodeRequest != null)
                {
                    currentNodeHost = sameNodeRequest.Host;
                }
                else
                {
                    currentNodeHost = roundRobin.Next().Uri.Host;
                    sameNodeList.SaveRequest(cacheKey, currentNodeHost);
                }

                // Save in request stream for next middleware
                //
                context.Items["NodeHost"] = currentNodeHost;

                // Call the next delegate/middleware in the pipeline
                await next();
            });
        }
コード例 #2
0
ファイル: 05_RoundRobin.cs プロジェクト: wattengard/ProxyKit
            public void Configure(IApplicationBuilder app)
            {
                var roundRobin = new RoundRobin
                {
                    new UpstreamHost("http://localhost:5001", weight: 1),
                    new UpstreamHost("http://localhost:5002", weight: 2)
                };

                app.RunProxy(
                    async context =>
                {
                    var host = roundRobin.Next();

                    var response = await context
                                   .ForwardTo(host)
                                   .ApplyXForwardedHeaders()
                                   .Execute();

                    // failover
                    if (response.StatusCode == HttpStatusCode.ServiceUnavailable)
                    {
                        return(await context
                               .ForwardTo(host)
                               .ApplyXForwardedHeaders()
                               .Execute());
                    }

                    return(response);
                });
            }
コード例 #3
0
    public void Configure(IApplicationBuilder app)
    {
        var roundRobin = new RoundRobin
        {
            new UpstreamHost("http://localhost:5001/", weight: 1),
            new UpstreamHost("http://localhost:5002/", weight: 2)
        };

        app.RunProxy(
            async context =>
        {
            var host = roundRobin.Next();

            return(await context
                   .ForwardTo(host)
                   .Send());
        });
    }
コード例 #4
0
            public void Configure(IApplicationBuilder app)
            {
                var roundRobin = new RoundRobin
                {
                    "http://localhost:5001",
                    "http://localhost:5002"
                };

                app.RunProxy(
                    context =>
                {
                    var host = roundRobin.Next();

                    return(context
                           .ForwardTo(host)
                           .AddXForwardedHeaders()
                           .Send());
                });
            }