mirror of
				https://github.com/nsnail/Ocelot.git
				synced 2025-11-04 09:15:27 +08:00 
			
		
		
		
	implementing load balancers
This commit is contained in:
		@@ -46,12 +46,18 @@ namespace Ocelot.DownstreamUrlCreator.Middleware
 | 
			
		||||
 | 
			
		||||
            var dsScheme = DownstreamRoute.ReRoute.DownstreamScheme;
 | 
			
		||||
 | 
			
		||||
            //here we could have a lb factory that takes stuff or we could just get the load balancer from the reRoute?
 | 
			
		||||
            //returns the lb for this request
 | 
			
		||||
            
 | 
			
		||||
            //lease the next address from the lb
 | 
			
		||||
 | 
			
		||||
            var dsHostAndPort = DownstreamRoute.ReRoute.DownstreamHostAndPort();
 | 
			
		||||
 | 
			
		||||
            var dsUrl = _urlBuilder.Build(dsPath.Data.Value, dsScheme, dsHostAndPort);
 | 
			
		||||
 | 
			
		||||
            if (dsUrl.IsError)
 | 
			
		||||
            {
 | 
			
		||||
                //todo - release the lb connection?
 | 
			
		||||
                _logger.LogDebug("IUrlBuilder returned an error, setting pipeline error");
 | 
			
		||||
 | 
			
		||||
                SetPipelineError(dsUrl.Errors);
 | 
			
		||||
@@ -66,6 +72,8 @@ namespace Ocelot.DownstreamUrlCreator.Middleware
 | 
			
		||||
 | 
			
		||||
            await _next.Invoke(context);
 | 
			
		||||
 | 
			
		||||
            //todo - release the lb connection?
 | 
			
		||||
 | 
			
		||||
            _logger.LogDebug("succesfully called next middleware");
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -21,6 +21,8 @@
 | 
			
		||||
        DownstreamPathTemplateContainsSchemeError,
 | 
			
		||||
        DownstreamPathNullOrEmptyError,
 | 
			
		||||
        DownstreamSchemeNullOrEmptyError,
 | 
			
		||||
        DownstreamHostNullOrEmptyError
 | 
			
		||||
        DownstreamHostNullOrEmptyError,
 | 
			
		||||
        ServicesAreNullError,
 | 
			
		||||
        ServicesAreEmptyError
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -10,5 +10,10 @@
 | 
			
		||||
 | 
			
		||||
        public string DownstreamHost { get; private set; }
 | 
			
		||||
        public int DownstreamPort { get; private set; }
 | 
			
		||||
 | 
			
		||||
        public override string ToString()
 | 
			
		||||
        {
 | 
			
		||||
            return $"{DownstreamHost}:{DownstreamPort}";
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user