mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-06-19 07:18:16 +08:00
started adding consul acceptance test
This commit is contained in:
@ -11,7 +11,8 @@ namespace Ocelot.Configuration
|
||||
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,
|
||||
string downstreamScheme, string loadBalancer, string downstreamHost, int downstreamPort, string loadBalancerKey)
|
||||
string downstreamScheme, string loadBalancer, string downstreamHost, int downstreamPort,
|
||||
string loadBalancerKey)
|
||||
{
|
||||
LoadBalancerKey = loadBalancerKey;
|
||||
LoadBalancer = loadBalancer;
|
||||
|
@ -61,7 +61,7 @@ namespace Ocelot.DependencyInjection
|
||||
{
|
||||
services.AddMvcCore().AddJsonFormatters();
|
||||
services.AddLogging();
|
||||
services.AddSingleton<IServiceProviderFactory, ServiceProviderFactory>();
|
||||
services.AddSingleton<IServiceDiscoveryProviderFactory, ServiceDiscoveryProviderFactory>();
|
||||
services.AddSingleton<ILoadBalancerFactory, LoadBalancerFactory>();
|
||||
services.AddSingleton<ILoadBalancerHouse, LoadBalancerHouse>();
|
||||
services.AddSingleton<IOcelotLoggerFactory, AspDotNetLoggerFactory>();
|
||||
|
@ -24,7 +24,7 @@
|
||||
DownstreamHostNullOrEmptyError,
|
||||
ServicesAreNullError,
|
||||
ServicesAreEmptyError,
|
||||
UnableToFindServiceProviderError,
|
||||
UnableToFindServiceDiscoveryProviderError,
|
||||
UnableToFindLoadBalancerError
|
||||
}
|
||||
}
|
||||
|
@ -5,19 +5,20 @@ namespace Ocelot.LoadBalancer.LoadBalancers
|
||||
{
|
||||
public class LoadBalancerFactory : ILoadBalancerFactory
|
||||
{
|
||||
private readonly IServiceProviderFactory _serviceProviderFactory;
|
||||
public LoadBalancerFactory(IServiceProviderFactory serviceProviderFactory)
|
||||
private readonly IServiceDiscoveryProviderFactory _serviceProviderFactory;
|
||||
public LoadBalancerFactory(IServiceDiscoveryProviderFactory serviceProviderFactory)
|
||||
{
|
||||
_serviceProviderFactory = serviceProviderFactory;
|
||||
}
|
||||
|
||||
public ILoadBalancer Get(ReRoute reRoute)
|
||||
{
|
||||
var serviceConfig = new ServiceConfiguraion(
|
||||
var serviceConfig = new ServiceProviderConfiguraion(
|
||||
reRoute.ServiceName,
|
||||
reRoute.DownstreamHost,
|
||||
reRoute.DownstreamPort,
|
||||
reRoute.UseServiceDiscovery);
|
||||
reRoute.UseServiceDiscovery,
|
||||
reRoute.ServiceDiscoveryProvider);
|
||||
|
||||
var serviceProvider = _serviceProviderFactory.Get(serviceConfig);
|
||||
|
||||
|
@ -1,9 +1,9 @@
|
||||
using System.Collections.Generic;
|
||||
using Ocelot.Values;
|
||||
|
||||
|
||||
namespace Ocelot.ServiceDiscovery
|
||||
{
|
||||
public class ConfigurationServiceProvider : IServiceProvider
|
||||
public class ConfigurationServiceProvider : IServiceDiscoveryProvider
|
||||
{
|
||||
private List<Service> _services;
|
||||
|
||||
|
@ -3,7 +3,7 @@ using Ocelot.Values;
|
||||
|
||||
namespace Ocelot.ServiceDiscovery
|
||||
{
|
||||
public interface IServiceProvider
|
||||
public interface IServiceDiscoveryProvider
|
||||
{
|
||||
List<Service> Get();
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
using System;
|
||||
|
||||
namespace Ocelot.ServiceDiscovery
|
||||
{
|
||||
public interface IServiceDiscoveryProviderFactory
|
||||
{
|
||||
IServiceDiscoveryProvider Get(ServiceProviderConfiguraion serviceConfig);
|
||||
}
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
using System;
|
||||
|
||||
namespace Ocelot.ServiceDiscovery
|
||||
{
|
||||
public interface IServiceProviderFactory
|
||||
{
|
||||
IServiceProvider Get(ServiceConfiguraion serviceConfig);
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
using System.Collections.Generic;
|
||||
using Ocelot.Values;
|
||||
|
||||
namespace Ocelot.ServiceDiscovery
|
||||
{
|
||||
public class ServiceDiscoveryProviderFactory : IServiceDiscoveryProviderFactory
|
||||
{
|
||||
public IServiceDiscoveryProvider Get(ServiceProviderConfiguraion serviceConfig)
|
||||
{
|
||||
var services = new List<Service>()
|
||||
{
|
||||
new Service(serviceConfig.ServiceName, new HostAndPort(serviceConfig.DownstreamHost, serviceConfig.DownstreamPort))
|
||||
};
|
||||
|
||||
return new ConfigurationServiceProvider(services);
|
||||
}
|
||||
}
|
||||
}
|
21
src/Ocelot/ServiceDiscovery/ServiceProviderConfiguraion.cs
Normal file
21
src/Ocelot/ServiceDiscovery/ServiceProviderConfiguraion.cs
Normal file
@ -0,0 +1,21 @@
|
||||
namespace Ocelot.ServiceDiscovery
|
||||
{
|
||||
public class ServiceProviderConfiguraion
|
||||
{
|
||||
public ServiceProviderConfiguraion(string serviceName, string downstreamHost,
|
||||
int downstreamPort, bool useServiceDiscovery, string serviceDiscoveryProvider)
|
||||
{
|
||||
ServiceName = serviceName;
|
||||
DownstreamHost = downstreamHost;
|
||||
DownstreamPort = downstreamPort;
|
||||
UseServiceDiscovery = useServiceDiscovery;
|
||||
ServiceDiscoveryProvider = serviceDiscoveryProvider;
|
||||
}
|
||||
|
||||
public string ServiceName { get; }
|
||||
public string DownstreamHost { get; }
|
||||
public int DownstreamPort { get; }
|
||||
public bool UseServiceDiscovery { get; }
|
||||
public string ServiceDiscoveryProvider {get;}
|
||||
}
|
||||
}
|
@ -1,34 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using Ocelot.Values;
|
||||
|
||||
namespace Ocelot.ServiceDiscovery
|
||||
{
|
||||
public class ServiceProviderFactory : IServiceProviderFactory
|
||||
{
|
||||
public IServiceProvider Get(ServiceConfiguraion serviceConfig)
|
||||
{
|
||||
var services = new List<Service>()
|
||||
{
|
||||
new Service(serviceConfig.ServiceName, new HostAndPort(serviceConfig.DownstreamHost, serviceConfig.DownstreamPort))
|
||||
};
|
||||
|
||||
return new ConfigurationServiceProvider(services);
|
||||
}
|
||||
}
|
||||
|
||||
public class ServiceConfiguraion
|
||||
{
|
||||
public ServiceConfiguraion(string serviceName, string downstreamHost, int downstreamPort, bool useServiceDiscovery)
|
||||
{
|
||||
ServiceName = serviceName;
|
||||
DownstreamHost = downstreamHost;
|
||||
DownstreamPort = downstreamPort;
|
||||
UseServiceDiscovery = useServiceDiscovery;
|
||||
}
|
||||
|
||||
public string ServiceName { get; }
|
||||
public string DownstreamHost { get; }
|
||||
public int DownstreamPort { get; }
|
||||
public bool UseServiceDiscovery { get; }
|
||||
}
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
using Ocelot.Errors;
|
||||
|
||||
namespace Ocelot.ServiceDiscovery
|
||||
{
|
||||
public class UnableToFindServiceDiscoveryProviderError : Error
|
||||
{
|
||||
public UnableToFindServiceDiscoveryProviderError(string message)
|
||||
: base(message, OcelotErrorCode.UnableToFindServiceDiscoveryProviderError)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
using Ocelot.Errors;
|
||||
|
||||
namespace Ocelot.ServiceDiscovery
|
||||
{
|
||||
public class UnableToFindServiceProviderError : Error
|
||||
{
|
||||
public UnableToFindServiceProviderError(string message)
|
||||
: base(message, OcelotErrorCode.UnableToFindServiceProviderError)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user