mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-06-19 06:48:16 +08:00
Feature/remove pivotal (#541)
* #529 removed eureka client * #529 removed some unused code
This commit is contained in:
@ -42,8 +42,6 @@ namespace Ocelot.DependencyInjection
|
||||
using Ocelot.Infrastructure;
|
||||
using Ocelot.Middleware.Multiplexer;
|
||||
using ServiceDiscovery.Providers;
|
||||
using Steeltoe.Common.Discovery;
|
||||
using Pivotal.Discovery.Client;
|
||||
using Ocelot.Request.Creator;
|
||||
|
||||
public class OcelotBuilder : IOcelotBuilder
|
||||
@ -109,16 +107,6 @@ namespace Ocelot.DependencyInjection
|
||||
Services.TryAddSingleton<IHttpHandlerOptionsCreator, HttpHandlerOptionsCreator>();
|
||||
Services.TryAddSingleton<IDownstreamAddressesCreator, DownstreamAddressesCreator>();
|
||||
Services.TryAddSingleton<IDelegatingHandlerHandlerFactory, DelegatingHandlerHandlerFactory>();
|
||||
|
||||
if (UsingEurekaServiceDiscoveryProvider(configurationRoot))
|
||||
{
|
||||
Services.AddDiscoveryClient(configurationRoot);
|
||||
}
|
||||
else
|
||||
{
|
||||
Services.TryAddSingleton<IDiscoveryClient, FakeEurekaDiscoveryClient>();
|
||||
}
|
||||
|
||||
Services.TryAddSingleton<IHttpRequester, HttpClientHttpRequester>();
|
||||
|
||||
// see this for why we register this as singleton http://stackoverflow.com/questions/37371264/invalidoperationexception-unable-to-resolve-service-for-type-microsoft-aspnetc
|
||||
|
@ -18,7 +18,6 @@
|
||||
using Rafty.Concensus;
|
||||
using Rafty.Infrastructure;
|
||||
using Ocelot.Middleware.Pipeline;
|
||||
using Pivotal.Discovery.Client;
|
||||
using Rafty.Concensus.Node;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
@ -48,15 +47,9 @@
|
||||
SetUpRafty(builder);
|
||||
}
|
||||
|
||||
if (UsingEurekaServiceDiscoveryProvider(configuration))
|
||||
{
|
||||
builder.UseDiscoveryClient();
|
||||
}
|
||||
|
||||
ConfigureDiagnosticListener(builder);
|
||||
|
||||
return CreateOcelotPipeline(builder, pipelineConfiguration);
|
||||
|
||||
}
|
||||
|
||||
private static IApplicationBuilder CreateOcelotPipeline(IApplicationBuilder builder, OcelotPipelineConfiguration pipelineConfiguration)
|
||||
@ -84,11 +77,6 @@
|
||||
return builder;
|
||||
}
|
||||
|
||||
private static bool UsingEurekaServiceDiscoveryProvider(IInternalConfiguration configuration)
|
||||
{
|
||||
return configuration?.ServiceProviderConfiguration != null && configuration.ServiceProviderConfiguration.Type?.ToLower() == "eureka";
|
||||
}
|
||||
|
||||
private static bool UsingRafty(IApplicationBuilder builder)
|
||||
{
|
||||
var node = builder.ApplicationServices.GetService<INode>();
|
||||
|
@ -48,7 +48,6 @@
|
||||
<PackageReference Include="System.Text.RegularExpressions" Version="4.3.0" />
|
||||
<PackageReference Include="Polly" Version="6.0.1" />
|
||||
<PackageReference Include="IdentityServer4" Version="2.2.0" />
|
||||
<PackageReference Include="Pivotal.Discovery.ClientCore" Version="2.0.1" />
|
||||
<PackageReference Include="Rafty" Version="0.4.4" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
@ -1,34 +0,0 @@
|
||||
namespace Ocelot.ServiceDiscovery.Providers
|
||||
{
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Steeltoe.Common.Discovery;
|
||||
using Values;
|
||||
|
||||
public class EurekaServiceDiscoveryProvider : IServiceDiscoveryProvider
|
||||
{
|
||||
private readonly IDiscoveryClient _client;
|
||||
private readonly string _serviceName;
|
||||
|
||||
public EurekaServiceDiscoveryProvider(string serviceName, IDiscoveryClient client)
|
||||
{
|
||||
_client = client;
|
||||
_serviceName = serviceName;
|
||||
}
|
||||
|
||||
public Task<List<Service>> Get()
|
||||
{
|
||||
var services = new List<Service>();
|
||||
|
||||
var instances = _client.GetInstances(_serviceName);
|
||||
|
||||
if (instances != null && instances.Any())
|
||||
{
|
||||
services.AddRange(instances.Select(i => new Service(i.ServiceId, new ServiceHostAndPort(i.Host, i.Port), "", "", new List<string>())));
|
||||
}
|
||||
|
||||
return Task.FromResult(services);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
namespace Ocelot.ServiceDiscovery.Providers
|
||||
{
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Steeltoe.Common.Discovery;
|
||||
|
||||
public class FakeEurekaDiscoveryClient : IDiscoveryClient
|
||||
{
|
||||
public IServiceInstance GetLocalServiceInstance()
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
public IList<IServiceInstance> GetInstances(string serviceId)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
public Task ShutdownAsync()
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
public string Description { get; }
|
||||
public IList<string> Services { get; }
|
||||
}
|
||||
}
|
@ -9,19 +9,16 @@ namespace Ocelot.ServiceDiscovery
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Steeltoe.Common.Discovery;
|
||||
|
||||
public class ServiceDiscoveryProviderFactory : IServiceDiscoveryProviderFactory
|
||||
{
|
||||
private readonly IOcelotLoggerFactory _factory;
|
||||
private readonly IDiscoveryClient _eurekaClient;
|
||||
private readonly List<ServiceDiscoveryFinderDelegate> _delegates;
|
||||
private readonly IServiceProvider _provider;
|
||||
|
||||
public ServiceDiscoveryProviderFactory(IOcelotLoggerFactory factory, IDiscoveryClient eurekaClient, IServiceProvider provider)
|
||||
public ServiceDiscoveryProviderFactory(IOcelotLoggerFactory factory, IServiceProvider provider)
|
||||
{
|
||||
_factory = factory;
|
||||
_eurekaClient = eurekaClient;
|
||||
_provider = provider;
|
||||
_delegates = provider
|
||||
.GetServices<ServiceDiscoveryFinderDelegate>()
|
||||
@ -55,11 +52,6 @@ namespace Ocelot.ServiceDiscovery
|
||||
return new ServiceFabricServiceDiscoveryProvider(sfConfig);
|
||||
}
|
||||
|
||||
if (config.Type?.ToLower() == "eureka")
|
||||
{
|
||||
return new EurekaServiceDiscoveryProvider(key, _eurekaClient);
|
||||
}
|
||||
|
||||
foreach (var serviceDiscoveryFinderDelegate in _delegates)
|
||||
{
|
||||
var provider = serviceDiscoveryFinderDelegate?.Invoke(_provider, config, key);
|
||||
|
Reference in New Issue
Block a user