-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
65 changed files
with
2,620 additions
and
1,183 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
Delegating Handers | ||
================== | ||
|
||
Ocelot allows the user to add delegating handlers to the HttpClient transport. This feature was requested `GitHub #208 <https://github.com/TomPallister/Ocelot/issues/208>`_ and I decided that it was going to be useful in various ways. | ||
|
||
Usage | ||
^^^^^^ | ||
|
||
In order to add delegating handlers to the HttpClient transport you need to do the following. | ||
|
||
.. code-block:: csharp | ||
services.AddOcelot() | ||
.AddDelegatingHandler(() => new FakeHandler()) | ||
.AddDelegatingHandler(() => new FakeHandler()); | ||
Or for singleton like behaviour.. | ||
|
||
.. code-block:: csharp | ||
var handlerOne = new FakeHandler(); | ||
var handlerTwo = new FakeHandler(); | ||
services.AddOcelot() | ||
.AddDelegatingHandler(() => handlerOne) | ||
.AddDelegatingHandler(() => handlerTwo); | ||
You can have as many DelegatingHandlers as you want and they are run in a first in first out order. If you are using Ocelot's QoS functionality then that will always be run after your last delegating handler. | ||
|
||
In order to create a class that can be used a delegating handler it must look as follows | ||
|
||
.. code-block:: csharp | ||
public class FakeHandler : DelegatingHandler | ||
{ | ||
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) | ||
{ | ||
//do stuff and optionally call the base handler.. | ||
return await base.SendAsync(request, cancellationToken); | ||
} | ||
} | ||
Hopefully other people will find this feature useful! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
Tracing | ||
======= | ||
|
||
Ocelot providers tracing functionality from the excellent `Butterfly <https://github.com/ButterflyAPM>`_ project. | ||
|
||
In order to use the tracing please read the Butterfly documentation. | ||
|
||
In ocelot you need to do the following if you wish to trace a ReRoute. | ||
|
||
In your ConfigureServices method | ||
|
||
.. code-block:: csharp | ||
services | ||
.AddOcelot(Configuration) | ||
.AddOpenTracing(option => | ||
{ | ||
//this is the url that the butterfly collector server is running on... | ||
option.CollectorUrl = "http://localhost:9618"; | ||
option.Service = "Ocelot"; | ||
}); | ||
Then in your configuration.json add the following to the ReRoute you want to trace.. | ||
|
||
.. code-block:: json | ||
"HttpHandlerOptions": { | ||
"UseTracing": true | ||
}, | ||
Ocelot will now send tracing information to Butterfly when this ReRoute is called. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"projects": [ "src", "test" ], | ||
"sdk": { | ||
"version": "2.0.2" | ||
"version": "2.1.4" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
src/Ocelot/DependencyInjection/IOcelotAdministrationBuilder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace Ocelot.DependencyInjection | ||
{ | ||
public interface IOcelotAdministrationBuilder | ||
{ | ||
IOcelotAdministrationBuilder AddRafty(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,16 @@ | ||
using CacheManager.Core; | ||
using System; | ||
|
||
namespace Ocelot.DependencyInjection | ||
{ | ||
public interface IOcelotBuilder | ||
{ | ||
IOcelotBuilder AddStoreOcelotConfigurationInConsul(); | ||
IOcelotBuilder AddCacheManager(Action<ConfigurationBuilderCachePart> settings); | ||
IOcelotAdministrationBuilder AddAdministration(string path, string secret); | ||
} | ||
} | ||
using Butterfly.Client.AspNetCore; | ||
using CacheManager.Core; | ||
using System; | ||
using System.Net.Http; | ||
|
||
namespace Ocelot.DependencyInjection | ||
{ | ||
public interface IOcelotBuilder | ||
{ | ||
IOcelotBuilder AddStoreOcelotConfigurationInConsul(); | ||
IOcelotBuilder AddCacheManager(Action<ConfigurationBuilderCachePart> settings); | ||
IOcelotBuilder AddOpenTracing(Action<ButterflyOptions> settings); | ||
IOcelotAdministrationBuilder AddAdministration(string path, string secret); | ||
IOcelotBuilder AddDelegatingHandler(Func<DelegatingHandler> delegatingHandler); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
src/Ocelot/DependencyInjection/OcelotAdministrationBuilder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Ocelot.Raft; | ||
using Rafty.Concensus; | ||
using Rafty.FiniteStateMachine; | ||
using Rafty.Infrastructure; | ||
using Rafty.Log; | ||
|
||
namespace Ocelot.DependencyInjection | ||
{ | ||
public class OcelotAdministrationBuilder : IOcelotAdministrationBuilder | ||
{ | ||
private readonly IServiceCollection _services; | ||
private readonly IConfiguration _configurationRoot; | ||
|
||
public OcelotAdministrationBuilder(IServiceCollection services, IConfiguration configurationRoot) | ||
{ | ||
_configurationRoot = configurationRoot; | ||
_services = services; | ||
} | ||
|
||
public IOcelotAdministrationBuilder AddRafty() | ||
{ | ||
var settings = new InMemorySettings(4000, 5000, 100, 5000); | ||
_services.AddSingleton<ILog, SqlLiteLog>(); | ||
_services.AddSingleton<IFiniteStateMachine, OcelotFiniteStateMachine>(); | ||
_services.AddSingleton<ISettings>(settings); | ||
_services.AddSingleton<IPeersProvider, FilePeersProvider>(); | ||
_services.AddSingleton<INode, Node>(); | ||
_services.Configure<FilePeers>(_configurationRoot); | ||
return this; | ||
} | ||
} | ||
} |
Oops, something went wrong.