mirror of
				https://github.com/nsnail/Ocelot.git
				synced 2025-11-04 20:30:50 +08:00 
			
		
		
		
	playing around with lb factory
This commit is contained in:
		@@ -32,12 +32,19 @@ namespace Ocelot.Configuration.Builder
 | 
			
		||||
        private string _downstreamScheme;
 | 
			
		||||
        private string _downstreamHost;
 | 
			
		||||
        private int _dsPort;
 | 
			
		||||
        private string _loadBalancer;
 | 
			
		||||
 | 
			
		||||
        public ReRouteBuilder()
 | 
			
		||||
        {
 | 
			
		||||
            _additionalScopes = new List<string>();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public ReRouteBuilder WithLoadBalancer(string loadBalancer)
 | 
			
		||||
        {
 | 
			
		||||
            _loadBalancer = loadBalancer;
 | 
			
		||||
            return this;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public ReRouteBuilder WithDownstreamScheme(string downstreamScheme)
 | 
			
		||||
        {
 | 
			
		||||
            _downstreamScheme = downstreamScheme;
 | 
			
		||||
@@ -200,7 +207,7 @@ namespace Ocelot.Configuration.Builder
 | 
			
		||||
                _isAuthenticated, new AuthenticationOptions(_authenticationProvider, _authenticationProviderUrl, _scopeName, 
 | 
			
		||||
                _requireHttps, _additionalScopes, _scopeSecret), _configHeaderExtractorProperties, _claimToClaims, _routeClaimRequirement, 
 | 
			
		||||
                _isAuthorised, _claimToQueries, _requestIdHeaderKey, _isCached, _fileCacheOptions, _serviceName, 
 | 
			
		||||
                _useServiceDiscovery, _serviceDiscoveryAddress, _serviceDiscoveryProvider, downstreamHostFunc, _downstreamScheme);
 | 
			
		||||
                _useServiceDiscovery, _serviceDiscoveryAddress, _serviceDiscoveryProvider, downstreamHostFunc, _downstreamScheme, _loadBalancer);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -97,6 +97,13 @@ namespace Ocelot.Configuration.Creator
 | 
			
		||||
                && !string.IsNullOrEmpty(globalConfiguration?.ServiceDiscoveryProvider?.Provider);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
            //can we do the logic in this func to get the host and port from the load balancer?
 | 
			
		||||
            //lBfactory.GetLbForThisDownstreamTemplate
 | 
			
		||||
            //use it in the func to get the next host and port?
 | 
			
		||||
            //how do we release it? cant callback, could access the lb and release later? 
 | 
			
		||||
 | 
			
		||||
            //ideal world we would get the host and port, then make the request using it, then release the connection to the lb
 | 
			
		||||
 | 
			
		||||
            Func<HostAndPort> downstreamHostAndPortFunc = () => new HostAndPort(reRoute.DownstreamHost.Trim('/'), reRoute.DownstreamPort);
 | 
			
		||||
 | 
			
		||||
            if (isAuthenticated)
 | 
			
		||||
@@ -116,7 +123,8 @@ namespace Ocelot.Configuration.Creator
 | 
			
		||||
                    reRoute.RouteClaimsRequirement, isAuthorised, claimsToQueries,
 | 
			
		||||
                    requestIdKey, isCached, new CacheOptions(reRoute.FileCacheOptions.TtlSeconds),
 | 
			
		||||
                    reRoute.ServiceName, useServiceDiscovery, globalConfiguration?.ServiceDiscoveryProvider?.Provider,
 | 
			
		||||
                    globalConfiguration?.ServiceDiscoveryProvider?.Address, downstreamHostAndPortFunc, reRoute.DownstreamScheme);
 | 
			
		||||
                    globalConfiguration?.ServiceDiscoveryProvider?.Address, downstreamHostAndPortFunc, reRoute.DownstreamScheme, 
 | 
			
		||||
                    reRoute.LoadBalancer);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            return new ReRoute(new DownstreamPathTemplate(reRoute.DownstreamPathTemplate), reRoute.UpstreamTemplate, 
 | 
			
		||||
@@ -125,7 +133,8 @@ namespace Ocelot.Configuration.Creator
 | 
			
		||||
                reRoute.RouteClaimsRequirement, isAuthorised, new List<ClaimToThing>(),
 | 
			
		||||
                    requestIdKey, isCached, new CacheOptions(reRoute.FileCacheOptions.TtlSeconds),
 | 
			
		||||
                    reRoute.ServiceName, useServiceDiscovery, globalConfiguration?.ServiceDiscoveryProvider?.Provider,
 | 
			
		||||
                    globalConfiguration?.ServiceDiscoveryProvider?.Address, downstreamHostAndPortFunc, reRoute.DownstreamScheme);
 | 
			
		||||
                    globalConfiguration?.ServiceDiscoveryProvider?.Address, downstreamHostAndPortFunc, reRoute.DownstreamScheme,
 | 
			
		||||
                    reRoute.LoadBalancer);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private string BuildUpstreamTemplate(FileReRoute reRoute)
 | 
			
		||||
 
 | 
			
		||||
@@ -29,5 +29,6 @@ namespace Ocelot.Configuration.File
 | 
			
		||||
        public string DownstreamScheme {get;set;}
 | 
			
		||||
        public string DownstreamHost {get;set;}
 | 
			
		||||
        public int DownstreamPort { get; set; }
 | 
			
		||||
        public string LoadBalancer {get;set;}
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -10,8 +10,10 @@ namespace Ocelot.Configuration
 | 
			
		||||
            bool isAuthenticated, AuthenticationOptions authenticationOptions, List<ClaimToThing> configurationHeaderExtractorProperties, 
 | 
			
		||||
            List<ClaimToThing> claimsToClaims, Dictionary<string, string> routeClaimsRequirement, bool isAuthorised, List<ClaimToThing> claimsToQueries, 
 | 
			
		||||
            string requestIdKey, bool isCached, CacheOptions fileCacheOptions, string serviceName, bool useServiceDiscovery,
 | 
			
		||||
            string serviceDiscoveryProvider, string serviceDiscoveryAddress, Func<HostAndPort> downstreamHostAndPort, string downstreamScheme)
 | 
			
		||||
            string serviceDiscoveryProvider, string serviceDiscoveryAddress, Func<HostAndPort> downstreamHostAndPort, 
 | 
			
		||||
            string downstreamScheme, string loadBalancer)
 | 
			
		||||
        {
 | 
			
		||||
            LoadBalancer = loadBalancer;
 | 
			
		||||
            DownstreamPathTemplate = downstreamPathTemplate;
 | 
			
		||||
            UpstreamTemplate = upstreamTemplate;
 | 
			
		||||
            UpstreamHttpMethod = upstreamHttpMethod;
 | 
			
		||||
@@ -36,7 +38,6 @@ namespace Ocelot.Configuration
 | 
			
		||||
                DownstreamHostAndPort = downstreamHostAndPort;
 | 
			
		||||
                DownstreamScheme = downstreamScheme;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public DownstreamPathTemplate DownstreamPathTemplate { get; private set; }
 | 
			
		||||
        public string UpstreamTemplate { get; private set; }
 | 
			
		||||
        public string UpstreamTemplatePattern { get; private set; }
 | 
			
		||||
@@ -57,5 +58,6 @@ namespace Ocelot.Configuration
 | 
			
		||||
        public string ServiceDiscoveryAddress { get; private set;}
 | 
			
		||||
        public Func<HostAndPort> DownstreamHostAndPort {get;private set;}
 | 
			
		||||
        public string DownstreamScheme {get;private set;}
 | 
			
		||||
        public string LoadBalancer {get;private set;}
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -51,6 +51,8 @@ namespace Ocelot.DownstreamUrlCreator.Middleware
 | 
			
		||||
            
 | 
			
		||||
            //lease the next address from the lb
 | 
			
		||||
 | 
			
		||||
            //this could return the load balancer which you call next on, that gives you the host and port then you can call release in a try catch 
 | 
			
		||||
            //and if the call works?
 | 
			
		||||
            var dsHostAndPort = DownstreamRoute.ReRoute.DownstreamHostAndPort();
 | 
			
		||||
 | 
			
		||||
            var dsUrl = _urlBuilder.Build(dsPath.Data.Value, dsScheme, dsHostAndPort);
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user