Fixed formatting for code samples
This commit is contained in:
Родитель
a0b9de68bb
Коммит
5f3cb70a33
|
@ -111,7 +111,7 @@
|
|||
|
||||
<pre><code class="xml hljs"><span class="hljs-tag"><<span class="hljs-name">ItemGroup</span>></span>
|
||||
...
|
||||
<span class="hljs-tag"><<span class="hljs-name">PackageReference</span> <span class="hljs-attr">Include</span>=<span class="hljs-string">"Steeltoe.CircuitBreaker.HystrixCore"</span> <span class="hljs-attr">Version</span>= <span class="hljs-string">"2.3.0"</span>/></span>
|
||||
<span class="hljs-tag"><<span class="hljs-name">PackageReference</span> <span class="hljs-attr">Include</span>=<span class="hljs-string">"Steeltoe.CircuitBreaker.HystrixCore"</span> <span class="hljs-attr">Version</span>= <span class="hljs-string">"2.3.0"</span>/></span>
|
||||
...
|
||||
<span class="hljs-tag"></<span class="hljs-name">ItemGroup</span>></span>
|
||||
</code></pre>
|
||||
|
@ -122,7 +122,7 @@
|
|||
|
||||
<pre><code class="xml hljs"><span class="hljs-tag"><<span class="hljs-name">ItemGroup</span>></span>
|
||||
...
|
||||
<span class="hljs-tag"><<span class="hljs-name">PackageReference</span> <span class="hljs-attr">Include</span>=<span class="hljs-string">"Steeltoe.CircuitBreaker.Hystrix.MetricsEventsCore"</span> <span class="hljs-attr">Version</span>= <span class="hljs-string">"2.3.0"</span>/></span>
|
||||
<span class="hljs-tag"><<span class="hljs-name">PackageReference</span> <span class="hljs-attr">Include</span>=<span class="hljs-string">"Steeltoe.CircuitBreaker.Hystrix.MetricsEventsCore"</span> <span class="hljs-attr">Version</span>= <span class="hljs-string">"2.3.0"</span>/></span>
|
||||
...
|
||||
<span class="hljs-tag"></<span class="hljs-name">ItemGroup</span>></span>
|
||||
</code></pre>
|
||||
|
@ -157,8 +157,8 @@
|
|||
|
||||
<pre><code class="xml hljs"><span class="hljs-tag"><<span class="hljs-name">ItemGroup</span>></span>
|
||||
...
|
||||
<span class="hljs-tag"><<span class="hljs-name">PackageReference</span> <span class="hljs-attr">Include</span>=<span class="hljs-string">"Steeltoe.CircuitBreaker.Hystrix.MetricsStreamCore"</span> <span class="hljs-attr">Version</span>= <span class="hljs-string">"2.3.0"</span>/></span>
|
||||
<span class="hljs-tag"><<span class="hljs-name">PackageReference</span> <span class="hljs-attr">Include</span>=<span class="hljs-string">"RabbitMQ.Client"</span> <span class="hljs-attr">Version</span>=<span class="hljs-string">"5.0.1"</span> /></span>
|
||||
<span class="hljs-tag"><<span class="hljs-name">PackageReference</span> <span class="hljs-attr">Include</span>=<span class="hljs-string">"Steeltoe.CircuitBreaker.Hystrix.MetricsStreamCore"</span> <span class="hljs-attr">Version</span>= <span class="hljs-string">"2.3.0"</span>/></span>
|
||||
<span class="hljs-tag"><<span class="hljs-name">PackageReference</span> <span class="hljs-attr">Include</span>=<span class="hljs-string">"RabbitMQ.Client"</span> <span class="hljs-attr">Version</span>=<span class="hljs-string">"5.0.1"</span> /></span>
|
||||
...
|
||||
<span class="hljs-tag"></<span class="hljs-name">ItemGroup</span>></span>
|
||||
</code></pre>
|
||||
|
@ -169,7 +169,7 @@
|
|||
|
||||
<pre><code class="csharp hljs"><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title">HelloWorldCommand</span> : <span class="hljs-title">HystrixCommand</span><<span class="hljs-title">string</span>>
|
||||
{
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">HelloWorldCommand</span>(<span class="hljs-params"><span class="hljs-keyword">string</span> name</span>)
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">HelloWorldCommand</span>(<span class="hljs-params"><span class="hljs-keyword">string</span> name</span>)
|
||||
: <span class="hljs-title">base</span>(<span class="hljs-params">HystrixCommandGroupKeyDefault.AsKey(<span class="hljs-string">"HelloWorldGroup"</span></span>),
|
||||
(<span class="hljs-params"></span>) </span>=> { <span class="hljs-keyword">return</span> <span class="hljs-string">"Hello"</span> + name; },
|
||||
() => { <span class="hljs-keyword">return</span> <span class="hljs-string">"Hello"</span> + name + <span class="hljs-string">" via fallback"</span>; })
|
||||
|
@ -188,20 +188,21 @@
|
|||
|
||||
<pre><code class="csharp hljs"><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title">HelloWorldCommand</span> : <span class="hljs-title">HystrixCommand</span><<span class="hljs-title">string</span>>
|
||||
{
|
||||
<span class="hljs-keyword">private</span> <span class="hljs-keyword">string</span> _name;
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">HelloWorldCommand</span>(<span class="hljs-params"><span class="hljs-keyword">string</span> name</span>)
|
||||
<span class="hljs-keyword">private</span> <span class="hljs-keyword">string</span> _name;
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">HelloWorldCommand</span>(<span class="hljs-params"><span class="hljs-keyword">string</span> name</span>)
|
||||
: <span class="hljs-title">base</span>(<span class="hljs-params">HystrixCommandGroupKeyDefault.AsKey(<span class="hljs-string">"HelloWorldGroup"</span></span>))
|
||||
</span>{
|
||||
_name = name;
|
||||
}
|
||||
|
||||
<span class="hljs-function"><span class="hljs-keyword">protected</span> <span class="hljs-keyword">override</span> <span class="hljs-keyword">async</span> Task<<span class="hljs-keyword">string</span>> <span class="hljs-title">RunAsync</span>(<span class="hljs-params"></span>)
|
||||
<span class="hljs-function"><span class="hljs-keyword">protected</span> <span class="hljs-keyword">override</span> <span class="hljs-keyword">async</span> Task<<span class="hljs-keyword">string</span>> <span class="hljs-title">RunAsync</span>(<span class="hljs-params"></span>)
|
||||
</span>{
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-keyword">await</span> Task.FromResult(<span class="hljs-string">"Hello"</span> + _name);
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-keyword">await</span> Task.FromResult(<span class="hljs-string">"Hello"</span> + _name);
|
||||
}
|
||||
<span class="hljs-function"><span class="hljs-keyword">protected</span> <span class="hljs-keyword">override</span> <span class="hljs-keyword">async</span> Task<<span class="hljs-keyword">string</span>> <span class="hljs-title">RunFallbackAsync</span>(<span class="hljs-params"></span>)
|
||||
|
||||
<span class="hljs-function"><span class="hljs-keyword">protected</span> <span class="hljs-keyword">override</span> <span class="hljs-keyword">async</span> Task<<span class="hljs-keyword">string</span>> <span class="hljs-title">RunFallbackAsync</span>(<span class="hljs-params"></span>)
|
||||
</span>{
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-keyword">await</span> Task.FromResult(<span class="hljs-string">"Hello"</span> + _name + <span class="hljs-string">" via fallback"</span>);
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-keyword">await</span> Task.FromResult(<span class="hljs-string">"Hello"</span> + _name + <span class="hljs-string">" via fallback"</span>);
|
||||
}
|
||||
}
|
||||
</code></pre>
|
||||
|
@ -733,25 +734,25 @@
|
|||
<p>The following example shows some Hystrix settings in JSON that configure the <code>FortuneService</code> command to use a thread pool with a name of <code>FortuneServiceTPool</code>.</p>
|
||||
|
||||
<pre><code class="json hljs">{
|
||||
<span class="hljs-attr">"spring"</span>: {
|
||||
<span class="hljs-attr">"application"</span>: {
|
||||
<span class="hljs-attr">"name"</span>: <span class="hljs-string">"fortuneui"</span>
|
||||
<span class="hljs-attr">"spring"</span>: {
|
||||
<span class="hljs-attr">"application"</span>: {
|
||||
<span class="hljs-attr">"name"</span>: <span class="hljs-string">"fortuneui"</span>
|
||||
}
|
||||
},
|
||||
<span class="hljs-attr">"eureka"</span>: {
|
||||
<span class="hljs-attr">"client"</span>: {
|
||||
<span class="hljs-attr">"serviceUrl"</span>: <span class="hljs-string">"http://localhost:8761/eureka/"</span>,
|
||||
<span class="hljs-attr">"shouldRegisterWithEureka"</span>: <span class="hljs-literal">false</span>
|
||||
}
|
||||
},
|
||||
<span class="hljs-attr">"hystrix"</span>: {
|
||||
<span class="hljs-attr">"command"</span>: {
|
||||
<span class="hljs-attr">"FortuneService"</span>: {
|
||||
<span class="hljs-attr">"threadPoolKeyOverride"</span>: <span class="hljs-string">"FortuneServiceTPool"</span>
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
<span class="hljs-attr">"eureka"</span>: {
|
||||
<span class="hljs-attr">"client"</span>: {
|
||||
<span class="hljs-attr">"serviceUrl"</span>: <span class="hljs-string">"http://localhost:8761/eureka/"</span>,
|
||||
<span class="hljs-attr">"shouldRegisterWithEureka"</span>: <span class="hljs-literal">false</span>
|
||||
}
|
||||
},
|
||||
<span class="hljs-attr">"hystrix"</span>: {
|
||||
<span class="hljs-attr">"command"</span>: {
|
||||
<span class="hljs-attr">"FortuneService"</span>: {
|
||||
<span class="hljs-attr">"threadPoolKeyOverride"</span>: <span class="hljs-string">"FortuneServiceTPool"</span>
|
||||
}
|
||||
}
|
||||
}
|
||||
...
|
||||
...
|
||||
}
|
||||
</code></pre>
|
||||
|
||||
|
@ -771,20 +772,22 @@
|
|||
|
||||
<span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title">Startup</span> {
|
||||
...
|
||||
<span class="hljs-keyword">public</span> IConfiguration Configuration { <span class="hljs-keyword">get</span>; <span class="hljs-keyword">private</span> <span class="hljs-keyword">set</span>; }
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">Startup</span>(<span class="hljs-params">IConfiguration configuration</span>)
|
||||
<span class="hljs-keyword">public</span> IConfiguration Configuration { <span class="hljs-keyword">get</span>; <span class="hljs-keyword">private</span> <span class="hljs-keyword">set</span>; }
|
||||
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">Startup</span>(<span class="hljs-params">IConfiguration configuration</span>)
|
||||
</span>{
|
||||
Configuration = configuration;
|
||||
}
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">ConfigureServices</span>(<span class="hljs-params">IServiceCollection services</span>)
|
||||
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">ConfigureServices</span>(<span class="hljs-params">IServiceCollection services</span>)
|
||||
</span>{
|
||||
<span class="hljs-comment">// Add Steeltoe Discovery Client service</span>
|
||||
<span class="hljs-comment">// Add Steeltoe Discovery Client service</span>
|
||||
services.AddDiscoveryClient(Configuration);
|
||||
|
||||
<span class="hljs-comment">// Add Hystrix command FortuneService to Hystrix group "FortuneService"</span>
|
||||
<span class="hljs-comment">// Add Hystrix command FortuneService to Hystrix group "FortuneService"</span>
|
||||
services.AddHystrixCommand<FortuneServiceCommand>(<span class="hljs-string">"FortuneService"</span>, Configuration);
|
||||
|
||||
<span class="hljs-comment">// Add framework services.</span>
|
||||
<span class="hljs-comment">// Add framework services.</span>
|
||||
services.AddMvc();
|
||||
...
|
||||
}
|
||||
|
@ -800,7 +803,7 @@
|
|||
IFortuneService _fortuneService;
|
||||
ILogger<FortuneServiceCommand> _logger;
|
||||
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">FortuneServiceCommand</span>(<span class="hljs-params">IHystrixCommandOptions options,
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">FortuneServiceCommand</span>(<span class="hljs-params">IHystrixCommandOptions options,
|
||||
IFortuneService fortuneService, ILogger<FortuneServiceCommand> logger</span>) : <span class="hljs-title">base</span>(<span class="hljs-params">options</span>)
|
||||
</span>{
|
||||
_fortuneService = fortuneService;
|
||||
|
@ -824,23 +827,21 @@
|
|||
{
|
||||
FortuneServiceCommand _fortuneServiceCommand;
|
||||
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">HomeController</span>(<span class="hljs-params">FortuneServiceCommand fortuneServiceCommand</span>)
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">HomeController</span>(<span class="hljs-params">FortuneServiceCommand fortuneServiceCommand</span>)
|
||||
</span>{
|
||||
_fortuneServiceCommand = fortuneServiceCommand;
|
||||
}
|
||||
|
||||
[HttpGet(<span class="hljs-string">"random"</span>)]
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">async</span> Task<Fortune> <span class="hljs-title">Random</span>(<span class="hljs-params"></span>)
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">async</span> Task<Fortune> <span class="hljs-title">Random</span>(<span class="hljs-params"></span>)
|
||||
</span>{
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-keyword">await</span> _fortuneServiceCommand.RandomFortuneAsync();
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-keyword">await</span> _fortuneServiceCommand.RandomFortuneAsync();
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> IActionResult <span class="hljs-title">Index</span>(<span class="hljs-params"></span>)
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> IActionResult <span class="hljs-title">Index</span>(<span class="hljs-params"></span>)
|
||||
</span>{
|
||||
<span class="hljs-keyword">return</span> View();
|
||||
}
|
||||
|
||||
<span class="hljs-keyword">return</span> View();
|
||||
}
|
||||
}
|
||||
</code></pre>
|
||||
|
@ -854,28 +855,28 @@
|
|||
IFortuneService _fortuneService;
|
||||
ILogger<FortuneServiceCommand> _logger;
|
||||
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">FortuneServiceCommand</span>(<span class="hljs-params">IHystrixCommandOptions options,
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">FortuneServiceCommand</span>(<span class="hljs-params">IHystrixCommandOptions options,
|
||||
IFortuneService fortuneService, ILogger<FortuneServiceCommand> logger</span>) : <span class="hljs-title">base</span>(<span class="hljs-params">options</span>)
|
||||
</span>{
|
||||
_fortuneService = fortuneService;
|
||||
_logger = logger;
|
||||
IsFallbackUserDefined = <span class="hljs-literal">true</span>;
|
||||
}
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">async</span> Task<Fortune> <span class="hljs-title">RandomFortuneAsync</span>(<span class="hljs-params"></span>)
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">async</span> Task<Fortune> <span class="hljs-title">RandomFortuneAsync</span>(<span class="hljs-params"></span>)
|
||||
</span>{
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-keyword">await</span> ExecuteAsync();
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-keyword">await</span> ExecuteAsync();
|
||||
}
|
||||
<span class="hljs-function"><span class="hljs-keyword">protected</span> <span class="hljs-keyword">override</span> <span class="hljs-keyword">async</span> Task<Fortune> <span class="hljs-title">RunAsync</span>(<span class="hljs-params"></span>)
|
||||
<span class="hljs-function"><span class="hljs-keyword">protected</span> <span class="hljs-keyword">override</span> <span class="hljs-keyword">async</span> Task<Fortune> <span class="hljs-title">RunAsync</span>(<span class="hljs-params"></span>)
|
||||
</span>{
|
||||
<span class="hljs-keyword">var</span> result = <span class="hljs-keyword">await</span> _fortuneService.RandomFortuneAsync();
|
||||
<span class="hljs-keyword">var</span> result = <span class="hljs-keyword">await</span> _fortuneService.RandomFortuneAsync();
|
||||
_logger.LogInformation(<span class="hljs-string">"Run: {0}"</span>, result);
|
||||
<span class="hljs-keyword">return</span> result;
|
||||
<span class="hljs-keyword">return</span> result;
|
||||
}
|
||||
|
||||
<span class="hljs-function"><span class="hljs-keyword">protected</span> <span class="hljs-keyword">override</span> <span class="hljs-keyword">async</span> Task<Fortune> <span class="hljs-title">RunFallbackAsync</span>(<span class="hljs-params"></span>)
|
||||
<span class="hljs-function"><span class="hljs-keyword">protected</span> <span class="hljs-keyword">override</span> <span class="hljs-keyword">async</span> Task<Fortune> <span class="hljs-title">RunFallbackAsync</span>(<span class="hljs-params"></span>)
|
||||
</span>{
|
||||
_logger.LogInformation(<span class="hljs-string">"RunFallback"</span>);
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-keyword">await</span> Task.FromResult<Fortune>(<span class="hljs-keyword">new</span> Fortune() { Id = <span class="hljs-number">9999</span>, Text = <span class="hljs-string">"You will have a happy day!"</span> });
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-keyword">await</span> Task.FromResult<Fortune>(<span class="hljs-keyword">new</span> Fortune() { Id = <span class="hljs-number">9999</span>, Text = <span class="hljs-string">"You will have a happy day!"</span> });
|
||||
}
|
||||
}
|
||||
</code></pre>
|
||||
|
@ -938,20 +939,20 @@ IDisposable subscription = cold.Subscribe((result) => { Console.WriteLine(res
|
|||
|
||||
<span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title">Startup</span> {
|
||||
...
|
||||
<span class="hljs-keyword">public</span> IConfiguration Configuration { <span class="hljs-keyword">get</span>; <span class="hljs-keyword">private</span> <span class="hljs-keyword">set</span>; }
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">Startup</span>(<span class="hljs-params">IConfiguration configuration</span>)
|
||||
<span class="hljs-keyword">public</span> IConfiguration Configuration { <span class="hljs-keyword">get</span>; <span class="hljs-keyword">private</span> <span class="hljs-keyword">set</span>; }
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">Startup</span>(<span class="hljs-params">IConfiguration configuration</span>)
|
||||
</span>{
|
||||
Configuration = configuration;
|
||||
}
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">ConfigureServices</span>(<span class="hljs-params">IServiceCollection services</span>)
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">ConfigureServices</span>(<span class="hljs-params">IServiceCollection services</span>)
|
||||
</span>{
|
||||
<span class="hljs-comment">// Add Steeltoe Discovery Client service</span>
|
||||
<span class="hljs-comment">// Add Steeltoe Discovery Client service</span>
|
||||
services.AddDiscoveryClient(Configuration);
|
||||
|
||||
<span class="hljs-comment">// Add Hystrix collapser to the service container</span>
|
||||
<span class="hljs-comment">// Add Hystrix collapser to the service container</span>
|
||||
services.AddHystrixCollapser<FortuneServiceCollapser>(<span class="hljs-string">"FortuneServiceCollapser"</span>, Configuration);
|
||||
|
||||
<span class="hljs-comment">// Add framework services.</span>
|
||||
<span class="hljs-comment">// Add framework services.</span>
|
||||
services.AddMvc();
|
||||
...
|
||||
}
|
||||
|
@ -969,7 +970,7 @@ IDisposable subscription = cold.Subscribe((result) => { Console.WriteLine(res
|
|||
ILoggerFactory _loggerFactory;
|
||||
IFortuneService _fortuneService;
|
||||
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">FortuneServiceCollapser</span>(<span class="hljs-params">IHystrixCollapserOptions options,
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">FortuneServiceCollapser</span>(<span class="hljs-params">IHystrixCollapserOptions options,
|
||||
IFortuneService fortuneService, ILoggerFactory logFactory</span>) : <span class="hljs-title">base</span>(<span class="hljs-params">options</span>)
|
||||
</span>{
|
||||
_logger = logFactory.CreateLogger<FortuneServiceCollapser>();
|
||||
|
@ -993,30 +994,30 @@ IDisposable subscription = cold.Subscribe((result) => { Console.WriteLine(res
|
|||
{
|
||||
FortuneServiceCollapser _fortuneService;
|
||||
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">HomeController</span>(<span class="hljs-params">FortuneServiceCollapser fortuneService</span>)
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">HomeController</span>(<span class="hljs-params">FortuneServiceCollapser fortuneService</span>)
|
||||
</span>{
|
||||
_fortuneService = fortuneService;
|
||||
}
|
||||
|
||||
[HttpGet(<span class="hljs-string">"random"</span>)]
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">async</span> Task<Fortune> <span class="hljs-title">Random</span>(<span class="hljs-params"></span>)
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">async</span> Task<Fortune> <span class="hljs-title">Random</span>(<span class="hljs-params"></span>)
|
||||
</span>{
|
||||
<span class="hljs-comment">// Fortune IDs are 1000-1049</span>
|
||||
<span class="hljs-keyword">int</span> id = random.Next(<span class="hljs-number">50</span>) + <span class="hljs-number">1000</span>;
|
||||
<span class="hljs-keyword">return</span> GetFortuneById(id);
|
||||
<span class="hljs-comment">// Fortune IDs are 1000-1049</span>
|
||||
<span class="hljs-keyword">int</span> id = random.Next(<span class="hljs-number">50</span>) + <span class="hljs-number">1000</span>;
|
||||
<span class="hljs-keyword">return</span> GetFortuneById(id);
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> IActionResult <span class="hljs-title">Index</span>(<span class="hljs-params"></span>)
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> IActionResult <span class="hljs-title">Index</span>(<span class="hljs-params"></span>)
|
||||
</span>{
|
||||
<span class="hljs-keyword">return</span> View();
|
||||
<span class="hljs-keyword">return</span> View();
|
||||
}
|
||||
|
||||
<span class="hljs-function"><span class="hljs-keyword">protected</span> Task<Fortune> <span class="hljs-title">GetFortuneById</span>(<span class="hljs-params"><span class="hljs-keyword">int</span> id</span>)
|
||||
<span class="hljs-function"><span class="hljs-keyword">protected</span> Task<Fortune> <span class="hljs-title">GetFortuneById</span>(<span class="hljs-params"><span class="hljs-keyword">int</span> id</span>)
|
||||
</span>{
|
||||
<span class="hljs-comment">// Use the FortuneServiceCollapser to obtain a Fortune by its Fortune Id</span>
|
||||
<span class="hljs-comment">// Use the FortuneServiceCollapser to obtain a Fortune by its Fortune Id</span>
|
||||
_fortuneService.FortuneId = id;
|
||||
<span class="hljs-keyword">return</span> _fortuneService.ExecuteAsync();
|
||||
<span class="hljs-keyword">return</span> _fortuneService.ExecuteAsync();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1032,7 +1033,7 @@ IDisposable subscription = cold.Subscribe((result) => { Console.WriteLine(res
|
|||
ILoggerFactory _loggerFactory;
|
||||
IFortuneService _fortuneService;
|
||||
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">FortuneServiceCollapser</span>(<span class="hljs-params">IHystrixCollapserOptions options,
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">FortuneServiceCollapser</span>(<span class="hljs-params">IHystrixCollapserOptions options,
|
||||
IFortuneService fortuneService, ILoggerFactory logFactory</span>) : <span class="hljs-title">base</span>(<span class="hljs-params">options</span>)
|
||||
</span>{
|
||||
_logger = logFactory.CreateLogger<FortuneServiceCollapser>();
|
||||
|
@ -1040,27 +1041,27 @@ IDisposable subscription = cold.Subscribe((result) => { Console.WriteLine(res
|
|||
_fortuneService = fortuneService;
|
||||
}
|
||||
|
||||
<span class="hljs-keyword">public</span> <span class="hljs-keyword">virtual</span> <span class="hljs-keyword">int</span> FortuneId { <span class="hljs-keyword">get</span>; <span class="hljs-keyword">set</span>; }
|
||||
<span class="hljs-keyword">public</span> <span class="hljs-keyword">virtual</span> <span class="hljs-keyword">int</span> FortuneId { <span class="hljs-keyword">get</span>; <span class="hljs-keyword">set</span>; }
|
||||
|
||||
<span class="hljs-keyword">public</span> <span class="hljs-keyword">override</span> <span class="hljs-keyword">int</span> RequestArgument { <span class="hljs-keyword">get</span> { <span class="hljs-keyword">return</span> FortuneId; } }
|
||||
<span class="hljs-keyword">public</span> <span class="hljs-keyword">override</span> <span class="hljs-keyword">int</span> RequestArgument { <span class="hljs-keyword">get</span> { <span class="hljs-keyword">return</span> FortuneId; } }
|
||||
|
||||
<span class="hljs-keyword">protected</span> <span class="hljs-keyword">override</span> HystrixCommand<List<Fortune>> CreateCommand(ICollection<ICollapsedRequest<Fortune, <span class="hljs-keyword">int</span>>> requests)
|
||||
<span class="hljs-keyword">protected</span> <span class="hljs-keyword">override</span> HystrixCommand<List<Fortune>> CreateCommand(ICollection<ICollapsedRequest<Fortune, <span class="hljs-keyword">int</span>>> requests)
|
||||
{
|
||||
_logger.LogInformation(<span class="hljs-string">"Creating MultiFortuneServiceCommand to handle {0} number of requests"</span>, requests.Count);
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> MultiFortuneServiceCommand(
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> MultiFortuneServiceCommand(
|
||||
HystrixCommandGroupKeyDefault.AsKey(<span class="hljs-string">"MultiFortuneService"</span>),
|
||||
requests,
|
||||
_fortuneService,
|
||||
_loggerFactory.CreateLogger<MultiFortuneServiceCommand>());
|
||||
}
|
||||
|
||||
<span class="hljs-function"><span class="hljs-keyword">protected</span> <span class="hljs-keyword">override</span> <span class="hljs-keyword">void</span> <span class="hljs-title">MapResponseToRequests</span>(<span class="hljs-params">List<Fortune> batchResponse, ICollection<ICollapsedRequest<Fortune, <span class="hljs-keyword">int</span>>> requests</span>)
|
||||
<span class="hljs-function"><span class="hljs-keyword">protected</span> <span class="hljs-keyword">override</span> <span class="hljs-keyword">void</span> <span class="hljs-title">MapResponseToRequests</span>(<span class="hljs-params">List<Fortune> batchResponse, ICollection<ICollapsedRequest<Fortune, <span class="hljs-keyword">int</span>>> requests</span>)
|
||||
</span>{
|
||||
<span class="hljs-keyword">foreach</span>(<span class="hljs-keyword">var</span> f <span class="hljs-keyword">in</span> batchResponse)
|
||||
<span class="hljs-keyword">foreach</span>(<span class="hljs-keyword">var</span> f <span class="hljs-keyword">in</span> batchResponse)
|
||||
{
|
||||
<span class="hljs-keyword">foreach</span>(<span class="hljs-keyword">var</span> r <span class="hljs-keyword">in</span> requests)
|
||||
<span class="hljs-keyword">foreach</span>(<span class="hljs-keyword">var</span> r <span class="hljs-keyword">in</span> requests)
|
||||
{
|
||||
<span class="hljs-keyword">if</span> (r.Argument == f.Id)
|
||||
<span class="hljs-keyword">if</span> (r.Argument == f.Id)
|
||||
{
|
||||
r.Response = f;
|
||||
}
|
||||
|
@ -1138,23 +1139,23 @@ IDisposable subscription = cold.Subscribe((result) => { Console.WriteLine(res
|
|||
|
||||
<span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title">Startup</span> {
|
||||
...
|
||||
<span class="hljs-keyword">public</span> IConfiguration Configuration { <span class="hljs-keyword">get</span>; <span class="hljs-keyword">private</span> <span class="hljs-keyword">set</span>; }
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">Startup</span>(<span class="hljs-params">IConfiguration configuration</span>)
|
||||
<span class="hljs-keyword">public</span> IConfiguration Configuration { <span class="hljs-keyword">get</span>; <span class="hljs-keyword">private</span> <span class="hljs-keyword">set</span>; }
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">Startup</span>(<span class="hljs-params">IConfiguration configuration</span>)
|
||||
</span>{
|
||||
Configuration = configuration;
|
||||
Configuration = configuration;
|
||||
}
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">ConfigureServices</span>(<span class="hljs-params">IServiceCollection services</span>)
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">ConfigureServices</span>(<span class="hljs-params">IServiceCollection services</span>)
|
||||
</span>{
|
||||
<span class="hljs-comment">// Add Steeltoe Discovery Client service</span>
|
||||
<span class="hljs-comment">// Add Steeltoe Discovery Client service</span>
|
||||
services.AddDiscoveryClient(Configuration);
|
||||
|
||||
<span class="hljs-comment">// Add Hystrix command FortuneService to Hystrix group "FortuneServices"</span>
|
||||
<span class="hljs-comment">// Add Hystrix command FortuneService to Hystrix group "FortuneServices"</span>
|
||||
services.AddHystrixCommand<IFortuneService, FortuneService>(<span class="hljs-string">"FortuneServices"</span>, Configuration);
|
||||
|
||||
<span class="hljs-comment">// Add framework services.</span>
|
||||
<span class="hljs-comment">// Add framework services.</span>
|
||||
services.AddMvc();
|
||||
|
||||
<span class="hljs-comment">// Add Hystrix Metrics to container</span>
|
||||
<span class="hljs-comment">// Add Hystrix Metrics to container</span>
|
||||
services.AddHystrixMetricsStream(Configuration);
|
||||
...
|
||||
}
|
||||
|
@ -1171,25 +1172,25 @@ IDisposable subscription = cold.Subscribe((result) => { Console.WriteLine(res
|
|||
|
||||
<span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title">Startup</span> {
|
||||
...
|
||||
<span class="hljs-keyword">public</span> IConfiguration Configuration { <span class="hljs-keyword">get</span>; <span class="hljs-keyword">private</span> <span class="hljs-keyword">set</span>; }
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">Startup</span>(<span class="hljs-params">IConfiguration configuration</span>)
|
||||
<span class="hljs-keyword">public</span> IConfiguration Configuration { <span class="hljs-keyword">get</span>; <span class="hljs-keyword">private</span> <span class="hljs-keyword">set</span>; }
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">Startup</span>(<span class="hljs-params">IConfiguration configuration</span>)
|
||||
</span>{
|
||||
Configuration = configuration;
|
||||
Configuration = configuration;
|
||||
}
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">ConfigureServices</span>(<span class="hljs-params">IServiceCollection services</span>)
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">ConfigureServices</span>(<span class="hljs-params">IServiceCollection services</span>)
|
||||
</span>{
|
||||
...
|
||||
}
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">Configure</span>(<span class="hljs-params">IApplicationBuilder app</span>)
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">Configure</span>(<span class="hljs-params">IApplicationBuilder app</span>)
|
||||
</span>{
|
||||
app.UseStaticFiles();
|
||||
|
||||
<span class="hljs-comment">// Use Hystrix Request contexts</span>
|
||||
<span class="hljs-comment">// Use Hystrix Request contexts</span>
|
||||
app.UseHystrixRequestContext();
|
||||
|
||||
app.UseMvc();
|
||||
|
||||
<span class="hljs-comment">// Start Hystrix metrics stream service</span>
|
||||
<span class="hljs-comment">// Start Hystrix metrics stream service</span>
|
||||
app.UseHystrixMetricsStream();
|
||||
}
|
||||
...
|
||||
|
@ -1287,20 +1288,20 @@ cf push <span class="hljs-_">-f</span> manifest-windows.yml -p bin/Debug/net461/
|
|||
|
||||
<pre><code class="csharp hljs"><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title">Program</span> {
|
||||
...
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> IWebHost <span class="hljs-title">BuildWebHost</span>(<span class="hljs-params"><span class="hljs-keyword">string</span>[] args</span>)
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> IWebHost <span class="hljs-title">BuildWebHost</span>(<span class="hljs-params"><span class="hljs-keyword">string</span>[] args</span>)
|
||||
</span>{
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> WebHostBuilder()
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> WebHostBuilder()
|
||||
...
|
||||
.UseCloudFoundryHosting()
|
||||
...
|
||||
.ConfigureAppConfiguration((builderContext, configBuilder) =>
|
||||
{
|
||||
<span class="hljs-keyword">var</span> env = builderContext.HostingEnvironment;
|
||||
<span class="hljs-keyword">var</span> env = builderContext.HostingEnvironment;
|
||||
configBuilder.SetBasePath(env.ContentRootPath)
|
||||
.AddJsonFile(<span class="hljs-string">"appsettings.json"</span>, optional: <span class="hljs-literal">true</span>, reloadOnChange: <span class="hljs-literal">true</span>)
|
||||
.AddJsonFile(<span class="hljs-string">$"appsettings.<span class="hljs-subst">{env.EnvironmentName}</span>.json"</span>, optional: <span class="hljs-literal">true</span>)
|
||||
.AddEnvironmentVariables()
|
||||
<span class="hljs-comment">// Add to configuration the Cloudfoundry VCAP settings</span>
|
||||
<span class="hljs-comment">// Add to configuration the Cloudfoundry VCAP settings</span>
|
||||
.AddCloudFoundry();
|
||||
})
|
||||
.Build();
|
||||
|
|
|
@ -90,7 +90,7 @@
|
|||
|
||||
<pre><code class="xml hljs"><span class="hljs-tag"><<span class="hljs-name">ItemGroup</span>></span>
|
||||
...
|
||||
<span class="hljs-tag"><<span class="hljs-name">PackageReference</span> <span class="hljs-attr">Include</span>=<span class="hljs-string">"Steeltoe.Discovery.ClientCore"</span> <span class="hljs-attr">Version</span>= <span class="hljs-string">"2.3.0"</span>/></span>
|
||||
<span class="hljs-tag"><<span class="hljs-name">PackageReference</span> <span class="hljs-attr">Include</span>=<span class="hljs-string">"Steeltoe.Discovery.ClientCore"</span> <span class="hljs-attr">Version</span>= <span class="hljs-string">"2.3.0"</span>/></span>
|
||||
...
|
||||
<span class="hljs-tag"></<span class="hljs-name">ItemGroup</span>></span>
|
||||
</code></pre>
|
||||
|
@ -105,36 +105,35 @@
|
|||
|
||||
<p>You do these two things in the <code>ConfigureServices()</code> and <code>Configure()</code> methods of the <code>Startup</code> class, as shown in the following example:</p>
|
||||
|
||||
<pre><code class="csharp hljs"><span class="hljs-keyword">using</span> Pivotal.Discovery.Client;
|
||||
<span class="hljs-comment">// or</span>
|
||||
<pre><code class="csharp hljs">
|
||||
<span class="hljs-keyword">using</span> Steeltoe.Discovery.Client;
|
||||
|
||||
<span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title">Startup</span> {
|
||||
...
|
||||
<span class="hljs-keyword">public</span> IConfiguration Configuration { <span class="hljs-keyword">get</span>; <span class="hljs-keyword">private</span> <span class="hljs-keyword">set</span>; }
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">Startup</span>(<span class="hljs-params">...</span>)
|
||||
</span>{
|
||||
...
|
||||
}
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">ConfigureServices</span>(<span class="hljs-params">IServiceCollection services</span>)
|
||||
</span>{
|
||||
<span class="hljs-comment">// Add Steeltoe Discovery Client service</span>
|
||||
services.AddDiscoveryClient(Configuration);
|
||||
...
|
||||
<span class="hljs-keyword">public</span> IConfiguration Configuration { <span class="hljs-keyword">get</span>; <span class="hljs-keyword">private</span> <span class="hljs-keyword">set</span>; }
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">Startup</span>(<span class="hljs-params">...</span>)
|
||||
</span>{
|
||||
...
|
||||
}
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">ConfigureServices</span>(<span class="hljs-params">IServiceCollection services</span>)
|
||||
</span>{
|
||||
<span class="hljs-comment">// Add Steeltoe Discovery Client service</span>
|
||||
services.AddDiscoveryClient(Configuration);
|
||||
|
||||
<span class="hljs-comment">// Add framework services.</span>
|
||||
services.AddMvc();
|
||||
...
|
||||
}
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">Configure</span>(<span class="hljs-params">IApplicationBuilder app, ...</span>)
|
||||
</span>{
|
||||
...
|
||||
app.UseStaticFiles();
|
||||
app.UseMvc();
|
||||
<span class="hljs-comment">// Add framework services.</span>
|
||||
services.AddMvc();
|
||||
...
|
||||
}
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">Configure</span>(<span class="hljs-params">IApplicationBuilder app, ...</span>)
|
||||
</span>{
|
||||
...
|
||||
app.UseStaticFiles();
|
||||
app.UseMvc();
|
||||
|
||||
<span class="hljs-comment">// Use the Steeltoe Discovery Client service</span>
|
||||
app.UseDiscoveryClient();
|
||||
}
|
||||
...
|
||||
<span class="hljs-comment">// Use the Steeltoe Discovery Client service</span>
|
||||
app.UseDiscoveryClient();
|
||||
}
|
||||
...
|
||||
</code></pre>
|
||||
|
||||
<blockquote>
|
||||
|
@ -165,30 +164,29 @@
|
|||
|
||||
<p>This <code>FortuneService</code> class retrieves fortunes from the Fortune microservice, which is registered under a name of <code>fortuneService</code>:</p>
|
||||
|
||||
<pre><code class="csharp hljs"><span class="hljs-keyword">using</span> Pivotal.Discovery.Client;
|
||||
<span class="hljs-comment">// or</span>
|
||||
<span class="hljs-comment">// using Steeltoe.Discovery.Client;</span>
|
||||
<pre><code class="csharp hljs">
|
||||
<span class="hljs-keyword">using Steeltoe.Discovery.Client;</span>
|
||||
|
||||
...
|
||||
<span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title">FortuneService</span> : <span class="hljs-title">IFortuneService</span>
|
||||
{
|
||||
DiscoveryHttpClientHandler _handler;
|
||||
<span class="hljs-keyword">private</span> <span class="hljs-keyword">const</span> <span class="hljs-keyword">string</span> RANDOM_FORTUNE_URL = <span class="hljs-string">"https://fortuneService/api/fortunes/random"</span>;
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">FortuneService</span>(<span class="hljs-params">IDiscoveryClient client</span>)
|
||||
<span class="hljs-keyword">private</span> <span class="hljs-keyword">const</span> <span class="hljs-keyword">string</span> RANDOM_FORTUNE_URL = <span class="hljs-string">"https://fortuneService/api/fortunes/random"</span>;
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">FortuneService</span>(<span class="hljs-params">IDiscoveryClient client</span>)
|
||||
</span>{
|
||||
_handler = <span class="hljs-keyword">new</span> DiscoveryHttpClientHandler(client);
|
||||
}
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">async</span> Task<<span class="hljs-keyword">string</span>> <span class="hljs-title">RandomFortuneAsync</span>(<span class="hljs-params"></span>)
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">async</span> Task<<span class="hljs-keyword">string</span>> <span class="hljs-title">RandomFortuneAsync</span>(<span class="hljs-params"></span>)
|
||||
</span>{
|
||||
<span class="hljs-keyword">var</span> client = GetClient();
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-keyword">await</span> client.GetStringAsync(RANDOM_FORTUNE_URL);
|
||||
<span class="hljs-keyword">var</span> client = GetClient();
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-keyword">await</span> client.GetStringAsync(RANDOM_FORTUNE_URL);
|
||||
}
|
||||
<span class="hljs-function"><span class="hljs-keyword">private</span> HttpClient <span class="hljs-title">GetClient</span>(<span class="hljs-params"></span>)
|
||||
<span class="hljs-function"><span class="hljs-keyword">private</span> HttpClient <span class="hljs-title">GetClient</span>(<span class="hljs-params"></span>)
|
||||
</span>{
|
||||
<span class="hljs-comment">// WARNING: do NOT create a new HttpClient for every request in your code</span>
|
||||
<span class="hljs-comment">// -- you may experience socket exhaustion if you do!</span>
|
||||
<span class="hljs-keyword">var</span> client = <span class="hljs-keyword">new</span> HttpClient(_handler, <span class="hljs-literal">false</span>);
|
||||
<span class="hljs-keyword">return</span> client;
|
||||
<span class="hljs-comment">// WARNING: do NOT create a new HttpClient for every request in your code</span>
|
||||
<span class="hljs-comment">// -- you may experience socket exhaustion if you do!</span>
|
||||
<span class="hljs-keyword">var</span> client = <span class="hljs-keyword">new</span> HttpClient(_handler, <span class="hljs-literal">false</span>);
|
||||
<span class="hljs-keyword">return</span> client;
|
||||
}
|
||||
}
|
||||
</code></pre>
|
||||
|
@ -214,20 +212,20 @@
|
|||
<pre><code class="csharp hljs"><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title">Startup</span>
|
||||
{
|
||||
...
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">ConfigureServices</span>(<span class="hljs-params">IServiceCollection services</span>)
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">ConfigureServices</span>(<span class="hljs-params">IServiceCollection services</span>)
|
||||
</span>{
|
||||
...
|
||||
<span class="hljs-comment">// Add Steeltoe handler to container (this line can be omitted when using Steeltoe versions >= 2.2.0)</span>
|
||||
services.AddTransient<DiscoveryHttpMessageHandler>();
|
||||
...
|
||||
<span class="hljs-comment">// Add Steeltoe handler to container (this line can be omitted when using Steeltoe versions >= 2.2.0)</span>
|
||||
services.AddTransient<DiscoveryHttpMessageHandler>();
|
||||
|
||||
<span class="hljs-comment">// Configure HttpClient</span>
|
||||
services.AddHttpClient(<span class="hljs-string">"fortunes"</span>, c =>
|
||||
{
|
||||
c.BaseAddress = <span class="hljs-keyword">new</span> Uri(<span class="hljs-string">"https://fortuneService/api/fortunes/"</span>);
|
||||
})
|
||||
.AddHttpMessageHandler<DiscoveryHttpMessageHandler>()
|
||||
.AddTypedClient<IFortuneService, FortuneService>();
|
||||
...
|
||||
<span class="hljs-comment">// Configure HttpClient</span>
|
||||
services.AddHttpClient(<span class="hljs-string">"fortunes"</span>, c =>
|
||||
{
|
||||
c.BaseAddress = <span class="hljs-keyword">new</span> Uri(<span class="hljs-string">"https://fortuneService/api/fortunes/"</span>);
|
||||
})
|
||||
.AddHttpMessageHandler<DiscoveryHttpMessageHandler>()
|
||||
.AddTypedClient<IFortuneService, FortuneService>();
|
||||
...
|
||||
}
|
||||
...
|
||||
}
|
||||
|
@ -237,15 +235,15 @@
|
|||
|
||||
<pre><code class="csharp hljs"><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title">FortuneService</span> : <span class="hljs-title">IFortuneService</span>
|
||||
{
|
||||
<span class="hljs-keyword">private</span> <span class="hljs-keyword">const</span> <span class="hljs-keyword">string</span> RANDOM_FORTUNE_URL = <span class="hljs-string">"https://fortuneService/api/fortunes/random"</span>;
|
||||
<span class="hljs-keyword">private</span> HttpClient _client;
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">FortuneService</span>(<span class="hljs-params">HttpClient client</span>)
|
||||
<span class="hljs-keyword">private</span> <span class="hljs-keyword">const</span> <span class="hljs-keyword">string</span> RANDOM_FORTUNE_URL = <span class="hljs-string">"https://fortuneService/api/fortunes/random"</span>;
|
||||
<span class="hljs-keyword">private</span> HttpClient _client;
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">FortuneService</span>(<span class="hljs-params">HttpClient client</span>)
|
||||
</span>{
|
||||
_client = client;
|
||||
}
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">async</span> Task<<span class="hljs-keyword">string</span>> <span class="hljs-title">RandomFortuneAsync</span>(<span class="hljs-params"></span>)
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">async</span> Task<<span class="hljs-keyword">string</span>> <span class="hljs-title">RandomFortuneAsync</span>(<span class="hljs-params"></span>)
|
||||
</span>{
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-keyword">await</span> _client.GetStringAsync(RANDOM_FORTUNE_URL);
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-keyword">await</span> _client.GetStringAsync(RANDOM_FORTUNE_URL);
|
||||
}
|
||||
}
|
||||
</code></pre>
|
||||
|
@ -285,22 +283,22 @@ IList<<span class="hljs-keyword">string</span>> Services { <span class="hl
|
|||
|
||||
<pre><code class="csharp hljs"> <span class="hljs-keyword">public</span> <span class="hljs-keyword">interface</span> <span class="hljs-title">ILoadBalancer</span>
|
||||
{
|
||||
<span class="hljs-comment"><span class="hljs-doctag">///</span> <span class="hljs-doctag"><summary></span></span>
|
||||
<span class="hljs-comment"><span class="hljs-doctag">///</span> Evaluates a Uri for a host name that can be resolved into a service instance</span>
|
||||
<span class="hljs-comment"><span class="hljs-doctag">///</span> <span class="hljs-doctag"></summary></span></span>
|
||||
<span class="hljs-comment"><span class="hljs-doctag">///</span> <span class="hljs-doctag"><param name="request"></span>A Uri containing a service name that can be resolved into one or more service instances<span class="hljs-doctag"></param></span></span>
|
||||
<span class="hljs-comment"><span class="hljs-doctag">///</span> <span class="hljs-doctag"><returns></span>The original Uri, with serviceName replaced by the host:port of a service instance<span class="hljs-doctag"></returns></span></span>
|
||||
<span class="hljs-function">Task<Uri> <span class="hljs-title">ResolveServiceInstanceAsync</span>(<span class="hljs-params">Uri request</span>)</span>;
|
||||
<span class="hljs-comment"><span class="hljs-doctag">///</span> <span class="hljs-doctag"><summary></span></span>
|
||||
<span class="hljs-comment"><span class="hljs-doctag">///</span> Evaluates a Uri for a host name that can be resolved into a service instance</span>
|
||||
<span class="hljs-comment"><span class="hljs-doctag">///</span> <span class="hljs-doctag"></summary></span></span>
|
||||
<span class="hljs-comment"><span class="hljs-doctag">///</span> <span class="hljs-doctag"><param name="request"></span>A Uri containing a service name that can be resolved into one or more service instances<span class="hljs-doctag"></param></span></span>
|
||||
<span class="hljs-comment"><span class="hljs-doctag">///</span> <span class="hljs-doctag"><returns></span>The original Uri, with serviceName replaced by the host:port of a service instance<span class="hljs-doctag"></returns></span></span>
|
||||
<span class="hljs-function">Task<Uri> <span class="hljs-title">ResolveServiceInstanceAsync</span>(<span class="hljs-params">Uri request</span>)</span>;
|
||||
|
||||
<span class="hljs-comment"><span class="hljs-doctag">///</span> <span class="hljs-doctag"><summary></span></span>
|
||||
<span class="hljs-comment"><span class="hljs-doctag">///</span> A mechanism for tracking statistics for service instances</span>
|
||||
<span class="hljs-comment"><span class="hljs-doctag">///</span> <span class="hljs-doctag"></summary></span></span>
|
||||
<span class="hljs-comment"><span class="hljs-doctag">///</span> <span class="hljs-doctag"><param name="originalUri"></span>The original request Uri<span class="hljs-doctag"></param></span></span>
|
||||
<span class="hljs-comment"><span class="hljs-doctag">///</span> <span class="hljs-doctag"><param name="resolvedUri"></span>The Uri resolved by the load balancer<span class="hljs-doctag"></param></span></span>
|
||||
<span class="hljs-comment"><span class="hljs-doctag">///</span> <span class="hljs-doctag"><param name="responseTime"></span>The amount of time taken for a remote call to complete<span class="hljs-doctag"></param></span></span>
|
||||
<span class="hljs-comment"><span class="hljs-doctag">///</span> <span class="hljs-doctag"><param name="exception"></span>Any exception called during calls to a resolved service instance<span class="hljs-doctag"></param></span></span>
|
||||
<span class="hljs-comment"><span class="hljs-doctag">///</span> <span class="hljs-doctag"><returns></span>A task<span class="hljs-doctag"></returns></span></span>
|
||||
<span class="hljs-function">Task <span class="hljs-title">UpdateStatsAsync</span>(<span class="hljs-params">Uri originalUri, Uri resolvedUri, TimeSpan responseTime, Exception exception</span>)</span>;
|
||||
<span class="hljs-comment"><span class="hljs-doctag">///</span> <span class="hljs-doctag"><summary></span></span>
|
||||
<span class="hljs-comment"><span class="hljs-doctag">///</span> A mechanism for tracking statistics for service instances</span>
|
||||
<span class="hljs-comment"><span class="hljs-doctag">///</span> <span class="hljs-doctag"></summary></span></span>
|
||||
<span class="hljs-comment"><span class="hljs-doctag">///</span> <span class="hljs-doctag"><param name="originalUri"></span>The original request Uri<span class="hljs-doctag"></param></span></span>
|
||||
<span class="hljs-comment"><span class="hljs-doctag">///</span> <span class="hljs-doctag"><param name="resolvedUri"></span>The Uri resolved by the load balancer<span class="hljs-doctag"></param></span></span>
|
||||
<span class="hljs-comment"><span class="hljs-doctag">///</span> <span class="hljs-doctag"><param name="responseTime"></span>The amount of time taken for a remote call to complete<span class="hljs-doctag"></param></span></span>
|
||||
<span class="hljs-comment"><span class="hljs-doctag">///</span> <span class="hljs-doctag"><param name="exception"></span>Any exception called during calls to a resolved service instance<span class="hljs-doctag"></param></span></span>
|
||||
<span class="hljs-comment"><span class="hljs-doctag">///</span> <span class="hljs-doctag"><returns></span>A task<span class="hljs-doctag"></returns></span></span>
|
||||
<span class="hljs-function">Task <span class="hljs-title">UpdateStatsAsync</span>(<span class="hljs-params">Uri originalUri, Uri resolvedUri, TimeSpan responseTime, Exception exception</span>)</span>;
|
||||
}
|
||||
</code></pre>
|
||||
|
||||
|
@ -331,12 +329,12 @@ IList<<span class="hljs-keyword">string</span>> Services { <span class="hl
|
|||
<p>The random load balancer can be used with the included <code>HttpClientHandler</code> that works with any <code>ILoadBalancer</code>:</p>
|
||||
|
||||
<pre><code class="csharp hljs"> <span class="hljs-keyword">private</span> HttpClient _httpClient;
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">FortuneService</span>(<span class="hljs-params">IDiscoveryClient discoveryClient</span>)
|
||||
</span>{
|
||||
<span class="hljs-keyword">var</span> loadBalancer = <span class="hljs-keyword">new</span> RandomLoadBalancer(discoveryClient);
|
||||
<span class="hljs-keyword">var</span> handler = <span class="hljs-keyword">new</span> LoadBalancerHttpClientHandler(loadBalancer);
|
||||
_httpClient = <span class="hljs-keyword">new</span> HttpClient(handler);
|
||||
}
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">FortuneService</span>(<span class="hljs-params">IDiscoveryClient discoveryClient</span>)
|
||||
</span>{
|
||||
<span class="hljs-keyword">var</span> loadBalancer = <span class="hljs-keyword">new</span> RandomLoadBalancer(discoveryClient);
|
||||
<span class="hljs-keyword">var</span> handler = <span class="hljs-keyword">new</span> LoadBalancerHttpClientHandler(loadBalancer);
|
||||
_httpClient = <span class="hljs-keyword">new</span> HttpClient(handler);
|
||||
}
|
||||
</code></pre>
|
||||
|
||||
<h3 id="1-4-3-round-robin-load-balancer">1.4.3 Round Robin Load Balancer</h3>
|
||||
|
@ -360,13 +358,14 @@ IList<<span class="hljs-keyword">string</span>> Services { <span class="hl
|
|||
|
||||
<p>The round robin load balancer can be used with the included <code>HttpClientHandler</code> that works with any <code>ILoadBalancer</code>:</p>
|
||||
|
||||
<pre><code class="csharp hljs"> <span class="hljs-keyword">private</span> HttpClient _httpClient;
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">FortuneService</span>(<span class="hljs-params">IDiscoveryClient discoveryClient</span>)
|
||||
</span>{
|
||||
<span class="hljs-keyword">var</span> loadBalancer = <span class="hljs-keyword">new</span> RoundRobinLoadBalancer(discoveryClient);
|
||||
<span class="hljs-keyword">var</span> handler = <span class="hljs-keyword">new</span> LoadBalancerHttpClientHandler(loadBalancer);
|
||||
_httpClient = <span class="hljs-keyword">new</span> HttpClient(handler);
|
||||
}
|
||||
<pre><code class="csharp hljs">
|
||||
<span class="hljs-keyword">private</span> HttpClient _httpClient;
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">FortuneService</span>(<span class="hljs-params">IDiscoveryClient discoveryClient</span>)
|
||||
</span>{
|
||||
<span class="hljs-keyword">var</span> loadBalancer = <span class="hljs-keyword">new</span> RoundRobinLoadBalancer(discoveryClient);
|
||||
<span class="hljs-keyword">var</span> handler = <span class="hljs-keyword">new</span> LoadBalancerHttpClientHandler(loadBalancer);
|
||||
_httpClient = <span class="hljs-keyword">new</span> HttpClient(handler);
|
||||
}
|
||||
</code></pre>
|
||||
|
||||
<h3 id="1-4-4-custom-iloadbalancer">1.4.4 Custom ILoadBalancer</h3>
|
||||
|
@ -375,23 +374,24 @@ IList<<span class="hljs-keyword">string</span>> Services { <span class="hl
|
|||
|
||||
<p>This example shows a load balancer that would always return the first listed instance, no matter what:</p>
|
||||
|
||||
<pre><code class="csharp hljs"> <span class="hljs-keyword">private</span> <span class="hljs-keyword">readonly</span> IServiceInstanceProvider _serviceInstanceProvider;
|
||||
<pre><code class="csharp hljs">
|
||||
<span class="hljs-keyword">private</span> <span class="hljs-keyword">readonly</span> IServiceInstanceProvider _serviceInstanceProvider;
|
||||
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">FirstInstanceLoadBalancer</span>(<span class="hljs-params">IServiceInstanceProvider serviceInstanceProvider</span>)
|
||||
</span>{
|
||||
_serviceInstanceProvider = serviceInstanceProvider;
|
||||
}
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">FirstInstanceLoadBalancer</span>(<span class="hljs-params">IServiceInstanceProvider serviceInstanceProvider</span>)
|
||||
</span>{
|
||||
_serviceInstanceProvider = serviceInstanceProvider;
|
||||
}
|
||||
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> Task<Uri> <span class="hljs-title">ResolveServiceInstanceAsync</span>(<span class="hljs-params">Uri request</span>)
|
||||
</span>{
|
||||
<span class="hljs-keyword">var</span> availableServiceInstances = _serviceInstanceProvider.GetInstances(request.Host);
|
||||
<span class="hljs-keyword">return</span> Task.FromResult(<span class="hljs-keyword">new</span> Uri(availableServiceInstances[<span class="hljs-number">0</span>].Uri, request.PathAndQuery));
|
||||
}
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> Task<Uri> <span class="hljs-title">ResolveServiceInstanceAsync</span>(<span class="hljs-params">Uri request</span>)
|
||||
</span>{
|
||||
<span class="hljs-keyword">var</span> availableServiceInstances = _serviceInstanceProvider.GetInstances(request.Host);
|
||||
<span class="hljs-keyword">return</span> Task.FromResult(<span class="hljs-keyword">new</span> Uri(availableServiceInstances[<span class="hljs-number">0</span>].Uri, request.PathAndQuery));
|
||||
}
|
||||
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> Task <span class="hljs-title">UpdateStatsAsync</span>(<span class="hljs-params">Uri originalUri, Uri resolvedUri, TimeSpan responseTime, Exception exception</span>)
|
||||
</span>{
|
||||
<span class="hljs-keyword">return</span> Task.CompletedTask;
|
||||
}
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> Task <span class="hljs-title">UpdateStatsAsync</span>(<span class="hljs-params">Uri originalUri, Uri resolvedUri, TimeSpan responseTime, Exception exception</span>)
|
||||
</span>{
|
||||
<span class="hljs-keyword">return</span> Task.CompletedTask;
|
||||
}
|
||||
</code></pre>
|
||||
|
||||
<h4 id="1-4-4-1-usage-with-httpclientfactory">1.4.4.1 Usage with HttpClientFactory</h4>
|
||||
|
@ -408,13 +408,14 @@ IList<<span class="hljs-keyword">string</span>> Services { <span class="hl
|
|||
|
||||
<p>Additionally, your custom load balancer can also be used with the included <code>HttpClientHandler</code>. Create an instance of your load balancer, pass it to a <code>LoadBalancerHttpClientHandler</code> and create an <code>HttpClient</code> that uses that handler:</p>
|
||||
|
||||
<pre><code class="csharp hljs"> <span class="hljs-keyword">private</span> HttpClient _httpClient;
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">FortuneService</span>(<span class="hljs-params">IDiscoveryClient discoveryClient</span>)
|
||||
</span>{
|
||||
<span class="hljs-keyword">var</span> loadBalancer = <span class="hljs-keyword">new</span> FirstInstanceLoadBalancer(discoveryClient);
|
||||
<span class="hljs-keyword">var</span> handler = <span class="hljs-keyword">new</span> LoadBalancerHttpClientHandler(loadBalancer);
|
||||
_httpClient = <span class="hljs-keyword">new</span> HttpClient(handler);
|
||||
}
|
||||
<pre><code class="csharp hljs">
|
||||
<span class="hljs-keyword">private</span> HttpClient _httpClient;
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">FortuneService</span>(<span class="hljs-params">IDiscoveryClient discoveryClient</span>)
|
||||
</span>{
|
||||
<span class="hljs-keyword">var</span> loadBalancer = <span class="hljs-keyword">new</span> FirstInstanceLoadBalancer(discoveryClient);
|
||||
<span class="hljs-keyword">var</span> handler = <span class="hljs-keyword">new</span> LoadBalancerHttpClientHandler(loadBalancer);
|
||||
_httpClient = <span class="hljs-keyword">new</span> HttpClient(handler);
|
||||
}
|
||||
</code></pre>
|
||||
|
||||
<h2 id="1-5-enable-logging">1.5 Enable Logging</h2>
|
||||
|
@ -424,14 +425,14 @@ IList<<span class="hljs-keyword">string</span>> Services { <span class="hl
|
|||
<p>Here is an example <code>appsettings.json</code> file:</p>
|
||||
|
||||
<pre><code class="json hljs">{
|
||||
<span class="hljs-attr">"Logging"</span>: {
|
||||
<span class="hljs-attr">"IncludeScopes"</span>: <span class="hljs-literal">false</span>,
|
||||
<span class="hljs-attr">"LogLevel"</span>: {
|
||||
<span class="hljs-attr">"Default"</span>: <span class="hljs-string">"Warning"</span>,
|
||||
<span class="hljs-attr">"Pivotal"</span>: <span class="hljs-string">"Debug"</span>,
|
||||
<span class="hljs-attr">"Steeltoe"</span>: <span class="hljs-string">"Debug"</span>
|
||||
}
|
||||
},
|
||||
<span class="hljs-attr">"Logging"</span>: {
|
||||
<span class="hljs-attr">"IncludeScopes"</span>: <span class="hljs-literal">false</span>,
|
||||
<span class="hljs-attr">"LogLevel"</span>: {
|
||||
<span class="hljs-attr">"Default"</span>: <span class="hljs-string">"Warning"</span>,
|
||||
<span class="hljs-attr">"Pivotal"</span>: <span class="hljs-string">"Debug"</span>,
|
||||
<span class="hljs-attr">"Steeltoe"</span>: <span class="hljs-string">"Debug"</span>
|
||||
}
|
||||
},
|
||||
...
|
||||
}
|
||||
</code></pre>
|
||||
|
@ -761,14 +762,15 @@ IList<<span class="hljs-keyword">string</span>> Services { <span class="hl
|
|||
|
||||
<pre><code class="json hljs">{
|
||||
<span class="hljs-attr">"spring"</span>: {
|
||||
<span class="hljs-attr">"application"</span>: {
|
||||
<span class="hljs-attr">"name"</span>: <span class="hljs-string">"fortuneUI"</span>
|
||||
<span class="hljs-attr">"application"</span>:
|
||||
{
|
||||
<span class="hljs-attr">"name"</span>: <span class="hljs-string">"fortuneUI"</span>
|
||||
}
|
||||
},
|
||||
<span class="hljs-attr">"eureka"</span>: {
|
||||
<span class="hljs-attr">"client"</span>: {
|
||||
<span class="hljs-attr">"serviceUrl"</span>: <span class="hljs-string">"http://localhost:8761/eureka/"</span>,
|
||||
<span class="hljs-attr">"shouldRegisterWithEureka"</span>: <span class="hljs-literal">false</span>
|
||||
<span class="hljs-attr">"eureka"</span>: {
|
||||
<span class="hljs-attr">"client"</span>: {
|
||||
<span class="hljs-attr">"serviceUrl"</span>: <span class="hljs-string">"http://localhost:8761/eureka/"</span>,
|
||||
<span class="hljs-attr">"shouldRegisterWithEureka"</span>: <span class="hljs-literal">false</span>
|
||||
}
|
||||
}
|
||||
...
|
||||
|
@ -786,20 +788,20 @@ IList<<span class="hljs-keyword">string</span>> Services { <span class="hl
|
|||
<p>The following example shows the clients settings in JSON that are necessary to cause the client to register a service named <code>fortuneService</code> with a Eureka Server at an address of <code>http://localhost:8761/eureka/</code>:</p>
|
||||
|
||||
<pre><code class="json hljs">{
|
||||
<span class="hljs-attr">"spring"</span>: {
|
||||
<span class="hljs-attr">"application"</span>: {
|
||||
<span class="hljs-attr">"name"</span>: <span class="hljs-string">"fortuneService"</span>
|
||||
}
|
||||
},
|
||||
<span class="hljs-attr">"eureka"</span>: {
|
||||
<span class="hljs-attr">"client"</span>: {
|
||||
<span class="hljs-attr">"serviceUrl"</span>: <span class="hljs-string">"http://localhost:8761/eureka/"</span>,
|
||||
<span class="hljs-attr">"shouldFetchRegistry"</span>: <span class="hljs-literal">false</span>
|
||||
<span class="hljs-attr">"spring"</span>: {
|
||||
<span class="hljs-attr">"application"</span>: {
|
||||
<span class="hljs-attr">"name"</span>: <span class="hljs-string">"fortuneService"</span>
|
||||
}
|
||||
},
|
||||
<span class="hljs-attr">"instance"</span>: {
|
||||
<span class="hljs-attr">"port"</span>: <span class="hljs-number">5000</span>
|
||||
<span class="hljs-attr">"eureka"</span>: {
|
||||
<span class="hljs-attr">"client"</span>: {
|
||||
<span class="hljs-attr">"serviceUrl"</span>: <span class="hljs-string">"http://localhost:8761/eureka/"</span>,
|
||||
<span class="hljs-attr">"shouldFetchRegistry"</span>: <span class="hljs-literal">false</span>
|
||||
},
|
||||
<span class="hljs-attr">"instance"</span>: {
|
||||
<span class="hljs-attr">"port"</span>: <span class="hljs-number">5000</span>
|
||||
}
|
||||
}
|
||||
}
|
||||
...
|
||||
}
|
||||
</code></pre>
|
||||
|
@ -834,14 +836,14 @@ cf restage myApp
|
|||
<p>Sometimes, it is desirable to turn on debug logging in the Eureka client. To do that simply add the following to your <code>appsettings.json</code>:</p>
|
||||
|
||||
<pre><code class="json hljs">{
|
||||
<span class="hljs-attr">"Logging"</span>: {
|
||||
<span class="hljs-attr">"IncludeScopes"</span>: <span class="hljs-literal">false</span>,
|
||||
<span class="hljs-attr">"LogLevel"</span>: {
|
||||
<span class="hljs-attr">"Default"</span>: <span class="hljs-string">"Information"</span>,
|
||||
<span class="hljs-attr">"Pivotal"</span>: <span class="hljs-string">"Debug"</span>,
|
||||
<span class="hljs-attr">"Steeltoe"</span>: <span class="hljs-string">"Debug"</span>
|
||||
<span class="hljs-attr">"Logging"</span>: {
|
||||
<span class="hljs-attr">"IncludeScopes"</span>: <span class="hljs-literal">false</span>,
|
||||
<span class="hljs-attr">"LogLevel"</span>: {
|
||||
<span class="hljs-attr">"Default"</span>: <span class="hljs-string">"Information"</span>,
|
||||
<span class="hljs-attr">"Pivotal"</span>: <span class="hljs-string">"Debug"</span>,
|
||||
<span class="hljs-attr">"Steeltoe"</span>: <span class="hljs-string">"Debug"</span>
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</code></pre>
|
||||
|
||||
|
@ -1166,14 +1168,14 @@ cf restage myApp
|
|||
<p>Sometimes, it is desirable to turn on debug logging. To do that simply add the following to your <code>appsettings.json</code>:</p>
|
||||
|
||||
<pre><code class="json hljs">{
|
||||
<span class="hljs-attr">"Logging"</span>: {
|
||||
<span class="hljs-attr">"IncludeScopes"</span>: <span class="hljs-literal">false</span>,
|
||||
<span class="hljs-attr">"LogLevel"</span>: {
|
||||
<span class="hljs-attr">"Default"</span>: <span class="hljs-string">"Information"</span>,
|
||||
<span class="hljs-attr">"Pivotal"</span>: <span class="hljs-string">"Debug"</span>,
|
||||
<span class="hljs-attr">"Steeltoe"</span>: <span class="hljs-string">"Debug"</span>
|
||||
<span class="hljs-attr">"Logging"</span>: {
|
||||
<span class="hljs-attr">"IncludeScopes"</span>: <span class="hljs-literal">false</span>,
|
||||
<span class="hljs-attr">"LogLevel"</span>: {
|
||||
<span class="hljs-attr">"Default"</span>: <span class="hljs-string">"Information"</span>,
|
||||
<span class="hljs-attr">"Pivotal"</span>: <span class="hljs-string">"Debug"</span>,
|
||||
<span class="hljs-attr">"Steeltoe"</span>: <span class="hljs-string">"Debug"</span>
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</code></pre>
|
||||
|
||||
|
@ -1196,22 +1198,22 @@ cf restage myApp
|
|||
<p>Tags with the form <code>key=value</code> will be split and used as <code>IDictionary</code> keys and values respectively. Tags without the equal sign will be used as both the key and value. You can add metadata with the <code>consul:discovery:tags</code> string array:</p>
|
||||
|
||||
<pre><code class="json hljs">{
|
||||
<span class="hljs-attr">"consul"</span>: {
|
||||
<span class="hljs-attr">"discovery"</span>: {
|
||||
<span class="hljs-attr">"tags"</span>: [
|
||||
<span class="hljs-string">"somekey=somevalue"</span>,
|
||||
<span class="hljs-string">"someothervalue"</span>
|
||||
]
|
||||
<span class="hljs-attr">"consul"</span>: {
|
||||
<span class="hljs-attr">"discovery"</span>: {
|
||||
<span class="hljs-attr">"tags"</span>: [
|
||||
<span class="hljs-string">"somekey=somevalue"</span>,
|
||||
<span class="hljs-string">"someothervalue"</span>
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</code></pre>
|
||||
|
||||
<p>The above tag list results in metadata that looks like this:</p>
|
||||
|
||||
<pre><code class="json hljs">{
|
||||
<span class="hljs-attr">"somekey"</span>: <span class="hljs-string">"somevalue"</span>,
|
||||
<span class="hljs-attr">"someothervalue"</span>: <span class="hljs-string">"someothervalue"</span>
|
||||
<span class="hljs-attr">"somekey"</span>: <span class="hljs-string">"somevalue"</span>,
|
||||
<span class="hljs-attr">"someothervalue"</span>: <span class="hljs-string">"someothervalue"</span>
|
||||
}
|
||||
</code></pre>
|
||||
|
||||
|
@ -1283,20 +1285,20 @@ cf push <span class="hljs-_">-f</span> manifest-windows.yml -p bin/Debug/net461/
|
|||
|
||||
<pre><code class="csharp hljs"><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title">Program</span> {
|
||||
...
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> IWebHost <span class="hljs-title">BuildWebHost</span>(<span class="hljs-params"><span class="hljs-keyword">string</span>[] args</span>)
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> IWebHost <span class="hljs-title">BuildWebHost</span>(<span class="hljs-params"><span class="hljs-keyword">string</span>[] args</span>)
|
||||
</span>{
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> WebHostBuilder()
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> WebHostBuilder()
|
||||
...
|
||||
.UseCloudFoundryHosting()
|
||||
...
|
||||
.ConfigureAppConfiguration((builderContext, configBuilder) =>
|
||||
{
|
||||
<span class="hljs-keyword">var</span> env = builderContext.HostingEnvironment;
|
||||
<span class="hljs-keyword">var</span> env = builderContext.HostingEnvironment;
|
||||
configBuilder.SetBasePath(env.ContentRootPath)
|
||||
.AddJsonFile(<span class="hljs-string">"appsettings.json"</span>, optional: <span class="hljs-literal">true</span>, reloadOnChange: <span class="hljs-literal">true</span>)
|
||||
.AddJsonFile(<span class="hljs-string">$"appsettings.<span class="hljs-subst">{env.EnvironmentName}</span>.json"</span>, optional: <span class="hljs-literal">true</span>)
|
||||
.AddEnvironmentVariables()
|
||||
<span class="hljs-comment">// Add to configuration the Cloudfoundry VCAP settings</span>
|
||||
<span class="hljs-comment">// Add to configuration the Cloudfoundry VCAP settings</span>
|
||||
.AddCloudFoundry();
|
||||
})
|
||||
.Build();
|
||||
|
|
|
@ -65,7 +65,7 @@
|
|||
|
||||
<pre><code class="xml hljs"><span class="hljs-tag"><<span class="hljs-name">ItemGroup</span>></span>
|
||||
...
|
||||
<span class="hljs-tag"><<span class="hljs-name">PackageReference</span> <span class="hljs-attr">Include</span>=<span class="hljs-string">"Steeltoe.Extensions.Logging.DynamicLogger"</span> <span class="hljs-attr">Version</span>= <span class="hljs-string">"2.3.0"</span>/></span>
|
||||
<span class="hljs-tag"><<span class="hljs-name">PackageReference</span> <span class="hljs-attr">Include</span>=<span class="hljs-string">"Steeltoe.Extensions.Logging.DynamicLogger"</span> <span class="hljs-attr">Version</span>= <span class="hljs-string">"2.3.0"</span>/></span>
|
||||
...
|
||||
<span class="hljs-tag"></<span class="hljs-name">ItemGroup</span>></span>
|
||||
</code></pre>
|
||||
|
@ -81,9 +81,9 @@
|
|||
<pre><code class="csharp hljs"><span class="hljs-keyword">using</span> Steeltoe.Extensions.Logging;
|
||||
<span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title">Program</span>
|
||||
{
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">Main</span>(<span class="hljs-params"><span class="hljs-keyword">string</span>[] args</span>)
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">Main</span>(<span class="hljs-params"><span class="hljs-keyword">string</span>[] args</span>)
|
||||
</span>{
|
||||
<span class="hljs-keyword">var</span> host = <span class="hljs-keyword">new</span> WebHostBuilder()
|
||||
<span class="hljs-keyword">var</span> host = <span class="hljs-keyword">new</span> WebHostBuilder()
|
||||
.UseKestrel()
|
||||
.UseCloudFoundryHosting()
|
||||
.UseContentRoot(Directory.GetCurrentDirectory())
|
||||
|
@ -102,7 +102,7 @@
|
|||
{
|
||||
loggingBuilder.AddConfiguration(builderContext.Configuration.GetSection(<span class="hljs-string">"Logging"</span>));
|
||||
|
||||
<span class="hljs-comment">// Add Steeltoe Dynamic Logging provider</span>
|
||||
<span class="hljs-comment">// Add Steeltoe Dynamic Logging provider</span>
|
||||
loggingBuilder.AddDynamicConsole();
|
||||
})
|
||||
.Build();
|
||||
|
@ -140,7 +140,7 @@
|
|||
|
||||
<pre><code class="xml hljs"><span class="hljs-tag"><<span class="hljs-name">ItemGroup</span>></span>
|
||||
...
|
||||
<span class="hljs-tag"><<span class="hljs-name">PackageReference</span> <span class="hljs-attr">Include</span>=<span class="hljs-string">"Steeltoe.Extensions.Logging.SerilogDynamicLogger"</span> <span class="hljs-attr">Version</span>= <span class="hljs-string">"2.3.0"</span>/></span>
|
||||
<span class="hljs-tag"><<span class="hljs-name">PackageReference</span> <span class="hljs-attr">Include</span>=<span class="hljs-string">"Steeltoe.Extensions.Logging.SerilogDynamicLogger"</span> <span class="hljs-attr">Version</span>= <span class="hljs-string">"2.3.0"</span>/></span>
|
||||
...
|
||||
<span class="hljs-tag"></<span class="hljs-name">ItemGroup</span>></span>
|
||||
</code></pre>
|
||||
|
@ -151,29 +151,29 @@
|
|||
|
||||
<pre><code class="json hljs">...
|
||||
|
||||
<span class="hljs-string">"Serilog"</span>: {
|
||||
<span class="hljs-attr">"IncludeScopes"</span>: <span class="hljs-literal">false</span>,
|
||||
<span class="hljs-attr">"MinimumLevel"</span>: {
|
||||
<span class="hljs-attr">"LogLevel"</span>: {
|
||||
<span class="hljs-attr">"Default"</span>: <span class="hljs-string">"Warning"</span>,
|
||||
<span class="hljs-attr">"Override"</span>: {
|
||||
<span class="hljs-attr">"Pivotal"</span>: <span class="hljs-string">"Information"</span>,
|
||||
<span class="hljs-attr">"Microsoft"</span>: <span class="hljs-string">"Warning"</span>,
|
||||
<span class="hljs-attr">"Steeltoe"</span>: <span class="hljs-string">"Information"</span>,
|
||||
<span class="hljs-attr">"CloudFoundry.Controllers"</span>: <span class="hljs-string">"Verbose"</span>
|
||||
<span class="hljs-string">"Serilog"</span>: {
|
||||
<span class="hljs-attr">"IncludeScopes"</span>: <span class="hljs-literal">false</span>,
|
||||
<span class="hljs-attr">"MinimumLevel"</span>: {
|
||||
<span class="hljs-attr">"LogLevel"</span>: {
|
||||
<span class="hljs-attr">"Default"</span>: <span class="hljs-string">"Warning"</span>,
|
||||
<span class="hljs-attr">"Override"</span>: {
|
||||
<span class="hljs-attr">"Pivotal"</span>: <span class="hljs-string">"Information"</span>,
|
||||
<span class="hljs-attr">"Microsoft"</span>: <span class="hljs-string">"Warning"</span>,
|
||||
<span class="hljs-attr">"Steeltoe"</span>: <span class="hljs-string">"Information"</span>,
|
||||
<span class="hljs-attr">"CloudFoundry.Controllers"</span>: <span class="hljs-string">"Verbose"</span>
|
||||
}
|
||||
},
|
||||
<span class="hljs-attr">"WriteTo"</span>: [
|
||||
{
|
||||
<span class="hljs-attr">"Name"</span>: <span class="hljs-string">"Console"</span>,
|
||||
<span class="hljs-attr">"Args"</span>: {
|
||||
<span class="hljs-attr">"outputTemplate"</span>: <span class="hljs-string">"[{Timestamp:HH:mm:ss} {Level:u3}] {SourceContext}: {Properties} {NewLine} {EventId} {Message:lj}{NewLine}{Exception}"</span>
|
||||
}
|
||||
}
|
||||
],
|
||||
<span class="hljs-attr">"Enrich"</span>: [ <span class="hljs-string">"FromLogContext"</span>, <span class="hljs-string">"WithMachineName"</span>, <span class="hljs-string">"WithThreadId"</span> ]
|
||||
},
|
||||
<span class="hljs-attr">"WriteTo"</span>: [
|
||||
{
|
||||
<span class="hljs-attr">"Name"</span>: <span class="hljs-string">"Console"</span>,
|
||||
<span class="hljs-attr">"Args"</span>: {
|
||||
<span class="hljs-attr">"outputTemplate"</span>: <span class="hljs-string">"[{Timestamp:HH:mm:ss} {Level:u3}] {SourceContext}: {Properties} {NewLine} {EventId} {Message:lj}{NewLine}{Exception}"</span>
|
||||
}
|
||||
}
|
||||
],
|
||||
<span class="hljs-attr">"Enrich"</span>: [ <span class="hljs-string">"FromLogContext"</span>, <span class="hljs-string">"WithMachineName"</span>, <span class="hljs-string">"WithThreadId"</span> ]
|
||||
},
|
||||
},
|
||||
...
|
||||
</code></pre>
|
||||
|
||||
|
@ -184,9 +184,9 @@
|
|||
<pre><code class="csharp hljs"><span class="hljs-keyword">using</span> Steeltoe.Extensions.Logging;
|
||||
<span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title">Program</span>
|
||||
{
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">Main</span>(<span class="hljs-params"><span class="hljs-keyword">string</span>[] args</span>)
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">Main</span>(<span class="hljs-params"><span class="hljs-keyword">string</span>[] args</span>)
|
||||
</span>{
|
||||
<span class="hljs-keyword">var</span> host = <span class="hljs-keyword">new</span> WebHostBuilder()
|
||||
<span class="hljs-keyword">var</span> host = <span class="hljs-keyword">new</span> WebHostBuilder()
|
||||
.UseKestrel()
|
||||
.UseCloudFoundryHosting()
|
||||
.UseContentRoot(Directory.GetCurrentDirectory())
|
||||
|
@ -205,7 +205,7 @@
|
|||
{
|
||||
loggingBuilder.AddConfiguration(builderContext.Configuration.GetSection(<span class="hljs-string">"Logging"</span>));
|
||||
|
||||
<span class="hljs-comment">// Add Serilog Dynamic Logger </span>
|
||||
<span class="hljs-comment">// Add Serilog Dynamic Logger </span>
|
||||
loggingBuilder.AddSerilogDynamicConsole();
|
||||
})
|
||||
.Build();
|
||||
|
|
|
@ -247,12 +247,12 @@
|
|||
|
||||
<pre><code class="xml hljs"><span class="hljs-tag"><<span class="hljs-name">ItemGroup</span>></span>
|
||||
...
|
||||
<span class="hljs-tag"><<span class="hljs-name">PackageReference</span> <span class="hljs-attr">Include</span>=<span class="hljs-string">"Steeltoe.Management.EndpointCore"</span> <span class="hljs-attr">Version</span>= <span class="hljs-string">"2.2.0"</span>/></span>
|
||||
<span class="hljs-tag"><<span class="hljs-name">PackageReference</span> <span class="hljs-attr">Include</span>=<span class="hljs-string">"Steeltoe.Management.EndpointCore"</span> <span class="hljs-attr">Version</span>= <span class="hljs-string">"2.2.0"</span>/></span>
|
||||
...
|
||||
<span class="hljs-tag"></<span class="hljs-name">ItemGroup</span>></span>
|
||||
</code></pre>
|
||||
|
||||
<p>or</p>
|
||||
<p>or</p>
|
||||
|
||||
<pre><code class="powershell hljs css"><span class="hljs-selector-tag">PM</span>><span class="hljs-selector-tag">Install-Package</span> <span class="hljs-selector-tag">Steeltoe</span><span class="hljs-selector-class">.Management</span><span class="hljs-selector-class">.EndpointWeb</span> <span class="hljs-selector-tag">-Version</span> 2<span class="hljs-selector-class">.2</span><span class="hljs-selector-class">.0</span>
|
||||
</code></pre>
|
||||
|
@ -320,14 +320,14 @@
|
|||
</p>
|
||||
|
||||
<pre><code class="json hljs"><span class="hljs-string">"management"</span>: {
|
||||
<span class="hljs-attr">"endpoints"</span>: {
|
||||
<span class="hljs-attr">"actuator"</span>:{
|
||||
<span class="hljs-attr">"exposure"</span>: {
|
||||
<span class="hljs-attr">"include"</span>: [ <span class="hljs-string">"*"</span> ],
|
||||
<span class="hljs-attr">"exclude"</span>: [ <span class="hljs-string">"env"</span>, <span class="hljs-string">"refresh"</span>]
|
||||
}
|
||||
}
|
||||
<span class="hljs-attr">"endpoints"</span>: {
|
||||
<span class="hljs-attr">"actuator"</span>:{
|
||||
<span class="hljs-attr">"exposure"</span>: {
|
||||
<span class="hljs-attr">"include"</span>: [ <span class="hljs-string">"*"</span> ],
|
||||
<span class="hljs-attr">"exclude"</span>: [ <span class="hljs-string">"env"</span>, <span class="hljs-string">"refresh"</span>]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</code></pre>
|
||||
|
||||
|
@ -524,15 +524,15 @@
|
|||
<p>The default value is <code>always</code>. Authorized roles can be configured using <code>management:endpoints:health:claim or management:endpoints:health:role</code>. A user is considered to be authorized when they are in the given role or have the specified claim. For example:</p>
|
||||
|
||||
<pre><code class="json hljs"><span class="hljs-string">"management"</span>: {
|
||||
<span class="hljs-attr">"endpoints"</span>: {
|
||||
<span class="hljs-attr">"health"</span>: {
|
||||
<span class="hljs-attr">"showdetails"</span>: <span class="hljs-string">"whenauthorized"</span>,
|
||||
<span class="hljs-attr">"claim"</span>: {
|
||||
<span class="hljs-attr">"type"</span>: <span class="hljs-string">"health_actuator"</span>,
|
||||
<span class="hljs-attr">"value"</span>: <span class="hljs-string">"see_details"</span>
|
||||
}
|
||||
}
|
||||
<span class="hljs-attr">"endpoints"</span>: {
|
||||
<span class="hljs-attr">"health"</span>: {
|
||||
<span class="hljs-attr">"showdetails"</span>: <span class="hljs-string">"whenauthorized"</span>,
|
||||
<span class="hljs-attr">"claim"</span>: {
|
||||
<span class="hljs-attr">"type"</span>: <span class="hljs-string">"health_actuator"</span>,
|
||||
<span class="hljs-attr">"value"</span>: <span class="hljs-string">"see_details"</span>
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</code></pre>
|
||||
|
||||
|
@ -579,17 +579,17 @@
|
|||
|
||||
<pre><code class="csharp hljs"><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title">CustomHealthContributor</span> : <span class="hljs-title">IHealthContributor</span>
|
||||
{
|
||||
<span class="hljs-keyword">public</span> <span class="hljs-keyword">string</span> Id => <span class="hljs-string">"CustomHealthContributor"</span>;
|
||||
<span class="hljs-keyword">public</span> <span class="hljs-keyword">string</span> Id => <span class="hljs-string">"CustomHealthContributor"</span>;
|
||||
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> HealthCheckResult <span class="hljs-title">Health</span>(<span class="hljs-params"></span>)
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> HealthCheckResult <span class="hljs-title">Health</span>(<span class="hljs-params"></span>)
|
||||
</span>{
|
||||
<span class="hljs-keyword">var</span> result = <span class="hljs-keyword">new</span> HealthCheckResult {
|
||||
<span class="hljs-comment">// this is used as part of the aggregate, it is not directly part of the middleware response</span>
|
||||
<span class="hljs-keyword">var</span> result = <span class="hljs-keyword">new</span> HealthCheckResult {
|
||||
<span class="hljs-comment">// this is used as part of the aggregate, it is not directly part of the middleware response</span>
|
||||
Status = HealthStatus.UP,
|
||||
Description = <span class="hljs-string">"This health check does not check anything"</span>
|
||||
};
|
||||
result.Details.Add(<span class="hljs-string">"status"</span>, HealthStatus.UP.ToString());
|
||||
<span class="hljs-keyword">return</span> result;
|
||||
<span class="hljs-keyword">return</span> result;
|
||||
}
|
||||
}
|
||||
</code></pre>
|
||||
|
@ -651,22 +651,25 @@
|
|||
<pre><code class="csharp hljs"><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title">Startup</span>
|
||||
{
|
||||
...
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">ConfigureServices</span>(<span class="hljs-params">IServiceCollection services</span>)
|
||||
</span>{
|
||||
<span class="hljs-comment">// Add your own IHealthContributor, registered with the interface</span>
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">ConfigureServices</span>(<span class="hljs-params">IServiceCollection services</span>)
|
||||
</span>
|
||||
{
|
||||
<span class="hljs-comment">// Add your own IHealthContributor, registered with the interface</span>
|
||||
services.AddSingleton<IHealthContributor, CustomHealthContributor>();
|
||||
|
||||
<span class="hljs-comment">// Add health actuator</span>
|
||||
<span class="hljs-comment">// Add health actuator</span>
|
||||
services.AddHealthActuator(Configuration);
|
||||
|
||||
<span class="hljs-comment">// Add framework services.</span>
|
||||
<span class="hljs-comment">// Add framework services.</span>
|
||||
services.AddMvc();
|
||||
}
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">Configure</span>(<span class="hljs-params">IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory</span>)
|
||||
</span>{
|
||||
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">Configure</span>(<span class="hljs-params">IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory</span>)
|
||||
</span>
|
||||
{
|
||||
app.UseStaticFiles();
|
||||
|
||||
<span class="hljs-comment">// Add management endpoint into pipeline</span>
|
||||
<span class="hljs-comment">// Add management endpoint into pipeline</span>
|
||||
app.UseHealthActuator();
|
||||
}
|
||||
}
|
||||
|
@ -686,24 +689,26 @@
|
|||
|
||||
<pre><code class="csharp hljs"><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title">ManagementConfig</span>
|
||||
{
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">ConfigureManagementActuators</span>(<span class="hljs-params">IConfiguration configuration, ILoggerFactory loggerFactory = <span class="hljs-literal">null</span></span>)
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">ConfigureManagementActuators</span>(<span class="hljs-params">IConfiguration configuration, ILoggerFactory loggerFactory = <span class="hljs-literal">null</span></span>)
|
||||
</span>{
|
||||
...
|
||||
ActuatorConfigurator.UseHealthActuator(
|
||||
configuration,
|
||||
<span class="hljs-keyword">new</span> DefaultHealthAggregator(),
|
||||
<span class="hljs-keyword">new</span> DefaultHealthAggregator(),
|
||||
GetHealthContributors(configuration),
|
||||
loggerFactory);
|
||||
...
|
||||
}
|
||||
<span class="hljs-function"><span class="hljs-keyword">private</span> <span class="hljs-keyword">static</span> IEnumerable<IHealthContributor> <span class="hljs-title">GetHealthContributors</span>(<span class="hljs-params">IConfiguration configuration</span>)
|
||||
</span>{
|
||||
<span class="hljs-keyword">var</span> healthContributors = <span class="hljs-keyword">new</span> List<IHealthContributor>
|
||||
|
||||
<span class="hljs-function"><span class="hljs-keyword">private</span> <span class="hljs-keyword">static</span> IEnumerable<IHealthContributor> <span class="hljs-title">GetHealthContributors</span>(<span class="hljs-params">IConfiguration configuration</span>)
|
||||
</span>
|
||||
{
|
||||
<span class="hljs-keyword">var</span> healthContributors = <span class="hljs-keyword">new</span> List<IHealthContributor>
|
||||
{
|
||||
<span class="hljs-keyword">new</span> DiskSpaceContributor(),
|
||||
<span class="hljs-keyword">new</span> DiskSpaceContributor(),
|
||||
RelationalHealthContributor.GetMySqlContributor(configuration)
|
||||
};
|
||||
<span class="hljs-keyword">return</span> healthContributors;
|
||||
<span class="hljs-keyword">return</span> healthContributors;
|
||||
}
|
||||
</code></pre>
|
||||
|
||||
|
@ -722,20 +727,22 @@
|
|||
</span>{
|
||||
...
|
||||
app.UseHealthActuator(
|
||||
<span class="hljs-keyword">new</span> HealthOptions(ApplicationConfig.Configuration),
|
||||
<span class="hljs-keyword">new</span> DefaultHealthAggregator(),
|
||||
<span class="hljs-keyword">new</span> HealthOptions(ApplicationConfig.Configuration),
|
||||
<span class="hljs-keyword">new</span> DefaultHealthAggregator(),
|
||||
GetHealthContributors(ApplicationConfig.Configuration),
|
||||
LoggingConfig.LoggerFactory);
|
||||
...
|
||||
}
|
||||
<span class="hljs-function"><span class="hljs-keyword">private</span> <span class="hljs-keyword">static</span> IEnumerable<IHealthContributor> <span class="hljs-title">GetHealthContributors</span>(<span class="hljs-params">IConfiguration configuration</span>)
|
||||
</span>{
|
||||
<span class="hljs-keyword">var</span> healthContributors = <span class="hljs-keyword">new</span> List<IHealthContributor>
|
||||
{
|
||||
<span class="hljs-keyword">new</span> DiskSpaceContributor(),
|
||||
RelationalHealthContributor.GetMySqlContributor(configuration)
|
||||
};
|
||||
<span class="hljs-keyword">return</span> healthContributors;
|
||||
|
||||
<span class="hljs-function"><span class="hljs-keyword">private</span> <span class="hljs-keyword">static</span> IEnumerable<IHealthContributor> <span class="hljs-title">GetHealthContributors</span>(<span class="hljs-params">IConfiguration configuration</span>)
|
||||
</span>
|
||||
{
|
||||
<span class="hljs-keyword">var</span> healthContributors = <span class="hljs-keyword">new</span> List<IHealthContributor>
|
||||
{
|
||||
<span class="hljs-keyword">new</span> DiskSpaceContributor(),
|
||||
RelationalHealthContributor.GetMySqlContributor(configuration)
|
||||
};
|
||||
<span class="hljs-keyword">return</span> healthContributors;
|
||||
}
|
||||
}
|
||||
</code></pre>
|
||||
|
@ -777,9 +784,10 @@
|
|||
|
||||
<pre><code class="csharp hljs"><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title">ArbitraryInfoContributor</span> : <span class="hljs-title">IInfoContributor</span>
|
||||
{
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">Contribute</span>(<span class="hljs-params">IInfoBuilder builder</span>)
|
||||
</span>{
|
||||
<span class="hljs-comment">// pass in the info</span>
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">Contribute</span>(<span class="hljs-params">IInfoBuilder builder</span>)
|
||||
</span>
|
||||
{
|
||||
<span class="hljs-comment">// pass in the info</span>
|
||||
builder.WithInfo(<span class="hljs-string">"arbitraryInfo"</span>, <span class="hljs-keyword">new</span> { someProperty = <span class="hljs-string">"someValue"</span> });
|
||||
}
|
||||
}
|
||||
|
@ -850,22 +858,24 @@
|
|||
<pre><code class="csharp hljs"><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title">Startup</span>
|
||||
{
|
||||
...
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">ConfigureServices</span>(<span class="hljs-params">IServiceCollection services</span>)
|
||||
</span>{
|
||||
<span class="hljs-comment">// Add custom info contributor, specifying the interface type</span>
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">ConfigureServices</span>(<span class="hljs-params">IServiceCollection services</span>)
|
||||
</span>
|
||||
{
|
||||
<span class="hljs-comment">// Add custom info contributor, specifying the interface type</span>
|
||||
services.AddSingleton<IInfoContributor, ArbitraryInfoContributor>();
|
||||
|
||||
<span class="hljs-comment">// Add Info actuator</span>
|
||||
<span class="hljs-comment">// Add Info actuator</span>
|
||||
services.AddInfoActuator(Configuration);
|
||||
|
||||
<span class="hljs-comment">// Add framework services.</span>
|
||||
<span class="hljs-comment">// Add framework services.</span>
|
||||
services.AddMvc();
|
||||
}
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">Configure</span>(<span class="hljs-params">IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory</span>)
|
||||
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">Configure</span>(<span class="hljs-params">IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory</span>)
|
||||
</span>{
|
||||
app.UseStaticFiles();
|
||||
|
||||
<span class="hljs-comment">// Add management endpoint into pipeline</span>
|
||||
<span class="hljs-comment">// Add management endpoint into pipeline</span>
|
||||
app.UseInfoActuator();
|
||||
}
|
||||
}
|
||||
|
@ -881,16 +891,19 @@
|
|||
|
||||
<pre><code class="csharp hljs"><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title">ManagementConfig</span>
|
||||
{
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">ConfigureManagementActuators</span>(<span class="hljs-params">IConfiguration configuration, ILoggerFactory loggerFactory</span>)
|
||||
</span>{
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">ConfigureManagementActuators</span>(<span class="hljs-params">IConfiguration configuration, ILoggerFactory loggerFactory</span>)
|
||||
</span>
|
||||
{
|
||||
...
|
||||
ActuatorConfigurator.UseInfoActuator(configuration, GetInfoContributors(configuration), loggerFactory);
|
||||
...
|
||||
}
|
||||
<span class="hljs-function"><span class="hljs-keyword">private</span> <span class="hljs-keyword">static</span> IEnumerable<IInfoContributor> <span class="hljs-title">GetInfoContributors</span>(<span class="hljs-params">IConfiguration configuration</span>)
|
||||
</span>{
|
||||
<span class="hljs-keyword">var</span> contributors = <span class="hljs-keyword">new</span> List<IInfoContributor>() { <span class="hljs-keyword">new</span> GitInfoContributor(), <span class="hljs-keyword">new</span> AppSettingsInfoContributor(configuration) }
|
||||
<span class="hljs-keyword">return</span> contributors;
|
||||
|
||||
<span class="hljs-function"><span class="hljs-keyword">private</span> <span class="hljs-keyword">static</span> IEnumerable<IInfoContributor> <span class="hljs-title">GetInfoContributors</span>(<span class="hljs-params">IConfiguration configuration</span>)
|
||||
</span>
|
||||
{
|
||||
<span class="hljs-keyword">var</span> contributors = <span class="hljs-keyword">new</span> List<IInfoContributor>() { <span class="hljs-keyword">new</span> GitInfoContributor(), <span class="hljs-keyword">new</span> AppSettingsInfoContributor(configuration) }
|
||||
<span class="hljs-keyword">return</span> contributors;
|
||||
}
|
||||
</code></pre>
|
||||
|
||||
|
@ -905,8 +918,9 @@
|
|||
<pre><code class="csharp hljs"><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title">Startup</span>
|
||||
{
|
||||
...
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">Configuration</span>(<span class="hljs-params">IAppBuilder app</span>)
|
||||
</span>{
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">Configuration</span>(<span class="hljs-params">IAppBuilder app</span>)
|
||||
</span>
|
||||
{
|
||||
...
|
||||
app.UseInfoActuator(
|
||||
ApplicationConfig.Configuration,
|
||||
|
@ -914,10 +928,12 @@
|
|||
LoggingConfig.LoggerFactory);
|
||||
...
|
||||
}
|
||||
<span class="hljs-function"><span class="hljs-keyword">private</span> <span class="hljs-keyword">static</span> IEnumerable<IInfoContributor> <span class="hljs-title">GetInfoContributors</span>(<span class="hljs-params">IConfiguration configuration</span>)
|
||||
</span>{
|
||||
<span class="hljs-keyword">var</span> contributors = <span class="hljs-keyword">new</span> List<IInfoContributor>() { <span class="hljs-keyword">new</span> GitInfoContributor(), <span class="hljs-keyword">new</span> AppSettingsInfoContributor(configuration) }
|
||||
<span class="hljs-keyword">return</span> contributors;
|
||||
|
||||
<span class="hljs-function"><span class="hljs-keyword">private</span> <span class="hljs-keyword">static</span> IEnumerable<IInfoContributor> <span class="hljs-title">GetInfoContributors</span>(<span class="hljs-params">IConfiguration configuration</span>)
|
||||
</span>
|
||||
{
|
||||
<span class="hljs-keyword">var</span> contributors = <span class="hljs-keyword">new</span> List<IInfoContributor>() { <span class="hljs-keyword">new</span> GitInfoContributor(), <span class="hljs-keyword">new</span> AppSettingsInfoContributor(configuration) }
|
||||
<span class="hljs-keyword">return</span> contributors;
|
||||
}
|
||||
}
|
||||
</code></pre>
|
||||
|
@ -989,9 +1005,10 @@
|
|||
<pre><code class="csharp hljs"><span class="hljs-keyword">using</span> Steeltoe.Extensions.Logging;
|
||||
<span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title">Program</span>
|
||||
{
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">Main</span>(<span class="hljs-params"><span class="hljs-keyword">string</span>[] args</span>)
|
||||
</span>{
|
||||
<span class="hljs-keyword">var</span> host = <span class="hljs-keyword">new</span> WebHostBuilder()
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">Main</span>(<span class="hljs-params"><span class="hljs-keyword">string</span>[] args</span>)
|
||||
</span>
|
||||
{
|
||||
<span class="hljs-keyword">var</span> host = <span class="hljs-keyword">new</span> WebHostBuilder()
|
||||
.UseKestrel()
|
||||
.UseContentRoot(Directory.GetCurrentDirectory())
|
||||
.UseStartup<Startup>()
|
||||
|
@ -1006,7 +1023,7 @@
|
|||
{
|
||||
loggingBuilder.AddConfiguration(builderContext.Configuration.GetSection(<span class="hljs-string">"Logging"</span>));
|
||||
|
||||
<span class="hljs-comment">// Add Steeltoe dynamic console logger</span>
|
||||
<span class="hljs-comment">// Add Steeltoe dynamic console logger</span>
|
||||
loggingBuilder.AddDynamicConsole();
|
||||
})
|
||||
.Build();
|
||||
|
@ -1026,7 +1043,7 @@
|
|||
|
||||
<pre><code class="csharp hljs"><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title">ManagementConfig</span>
|
||||
{
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">ConfigureManagementActuators</span>(<span class="hljs-params">IConfiguration configuration</span>)
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">ConfigureManagementActuators</span>(<span class="hljs-params">IConfiguration configuration</span>)
|
||||
</span>{
|
||||
...
|
||||
ActuatorConfigurator.UseLoggerActuator(configuration, LoggingConfig.LoggerProvider, LoggingConfig.LoggerProvider);
|
||||
|
@ -1038,10 +1055,10 @@
|
|||
|
||||
<pre><code class="csharp hljs"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">class</span> <span class="hljs-title">LoggingConfig</span>
|
||||
{
|
||||
<span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> ILoggerFactory LoggerFactory { <span class="hljs-keyword">get</span>; <span class="hljs-keyword">set</span>; }
|
||||
<span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> ILoggerProvider LoggerProvider { <span class="hljs-keyword">get</span>; <span class="hljs-keyword">set</span>; }
|
||||
<span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> ILoggerFactory LoggerFactory { <span class="hljs-keyword">get</span>; <span class="hljs-keyword">set</span>; }
|
||||
<span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> ILoggerProvider LoggerProvider { <span class="hljs-keyword">get</span>; <span class="hljs-keyword">set</span>; }
|
||||
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">Configure</span>(<span class="hljs-params">IConfiguration configuration</span>)
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">Configure</span>(<span class="hljs-params">IConfiguration configuration</span>)
|
||||
</span>{
|
||||
LoggerProvider = <span class="hljs-keyword">new</span> DynamicLoggerProvider(<span class="hljs-keyword">new</span> ConsoleLoggerSettings().FromConfiguration(configuration));
|
||||
LoggerFactory = <span class="hljs-keyword">new</span> LoggerFactory();
|
||||
|
@ -1061,7 +1078,7 @@
|
|||
<pre><code class="csharp hljs"><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title">Startup</span>
|
||||
{
|
||||
...
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">Configuration</span>(<span class="hljs-params">IAppBuilder app</span>)
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">Configuration</span>(<span class="hljs-params">IAppBuilder app</span>)
|
||||
</span>{
|
||||
...
|
||||
app.UseLoggersActuator(
|
||||
|
@ -1077,10 +1094,10 @@
|
|||
|
||||
<pre><code class="csharp hljs"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">class</span> <span class="hljs-title">LoggingConfig</span>
|
||||
{
|
||||
<span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> ILoggerFactory LoggerFactory { <span class="hljs-keyword">get</span>; <span class="hljs-keyword">set</span>; }
|
||||
<span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> ILoggerProvider LoggerProvider { <span class="hljs-keyword">get</span>; <span class="hljs-keyword">set</span>; }
|
||||
<span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> ILoggerFactory LoggerFactory { <span class="hljs-keyword">get</span>; <span class="hljs-keyword">set</span>; }
|
||||
<span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> ILoggerProvider LoggerProvider { <span class="hljs-keyword">get</span>; <span class="hljs-keyword">set</span>; }
|
||||
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">Configure</span>(<span class="hljs-params">IConfiguration configuration</span>)
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">Configure</span>(<span class="hljs-params">IConfiguration configuration</span>)
|
||||
</span>{
|
||||
LoggerProvider = <span class="hljs-keyword">new</span> DynamicLoggerProvider(<span class="hljs-keyword">new</span> ConsoleLoggerSettings().FromConfiguration(configuration));
|
||||
LoggerFactory = <span class="hljs-keyword">new</span> LoggerFactory();
|
||||
|
@ -1096,7 +1113,7 @@
|
|||
<p>Log levels can be changed at namespace or class levels with an HTTP POST request to <code>/{LoggersActuatorPath}/{NamespaceOrClassName}</code> and a JSON request body that defines the minimum level you wish to log:</p>
|
||||
|
||||
<pre><code class="json hljs">{
|
||||
<span class="hljs-attr">"configuredLevel"</span>:<span class="hljs-string">"INFO"</span>
|
||||
<span class="hljs-attr">"configuredLevel"</span>:<span class="hljs-string">"INFO"</span>
|
||||
}
|
||||
</code></pre>
|
||||
|
||||
|
@ -1684,7 +1701,7 @@
|
|||
|
||||
<pre><code class="xml hljs"><span class="hljs-tag"><<span class="hljs-name">ItemGroup</span>></span>
|
||||
...
|
||||
<span class="hljs-tag"><<span class="hljs-name">PackageReference</span> <span class="hljs-attr">Include</span>=<span class="hljs-string">"Steeltoe.Management.ExporterCore"</span> <span class="hljs-attr">Version</span>= <span class="hljs-string">"2.1.0"</span>/></span>
|
||||
<span class="hljs-tag"><<span class="hljs-name">PackageReference</span> <span class="hljs-attr">Include</span>=<span class="hljs-string">"Steeltoe.Management.ExporterCore"</span> <span class="hljs-attr">Version</span>= <span class="hljs-string">"2.1.0"</span>/></span>
|
||||
...
|
||||
<span class="hljs-tag"></<span class="hljs-name">ItemGroup</span>></span>
|
||||
</code></pre>
|
||||
|
@ -1934,7 +1951,7 @@
|
|||
|
||||
<pre><code class="xml hljs"><span class="hljs-tag"><<span class="hljs-name">ItemGroup</span>></span>
|
||||
...
|
||||
<span class="hljs-tag"><<span class="hljs-name">PackageReference</span> <span class="hljs-attr">Include</span>=<span class="hljs-string">"Steeltoe.Management.TracingCore"</span> <span class="hljs-attr">Version</span>= <span class="hljs-string">"2.1.0"</span>/></span>
|
||||
<span class="hljs-tag"><<span class="hljs-name">PackageReference</span> <span class="hljs-attr">Include</span>=<span class="hljs-string">"Steeltoe.Management.TracingCore"</span> <span class="hljs-attr">Version</span>= <span class="hljs-string">"2.1.0"</span>/></span>
|
||||
...
|
||||
<span class="hljs-tag"></<span class="hljs-name">ItemGroup</span>></span>
|
||||
</code></pre>
|
||||
|
@ -2036,23 +2053,23 @@
|
|||
|
||||
<pre><code class="csharp hljs"><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title">Startup</span>
|
||||
{
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">Startup</span>(<span class="hljs-params">IConfiguration configuration</span>)
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">Startup</span>(<span class="hljs-params">IConfiguration configuration</span>)
|
||||
</span>{
|
||||
Configuration = configuration;
|
||||
}
|
||||
|
||||
<span class="hljs-keyword">public</span> IConfiguration Configuration { <span class="hljs-keyword">get</span>; <span class="hljs-keyword">set</span>; }
|
||||
<span class="hljs-keyword">public</span> IConfiguration Configuration { <span class="hljs-keyword">get</span>; <span class="hljs-keyword">set</span>; }
|
||||
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">ConfigureServices</span>(<span class="hljs-params">IServiceCollection services</span>)
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">ConfigureServices</span>(<span class="hljs-params">IServiceCollection services</span>)
|
||||
</span>{
|
||||
...
|
||||
<span class="hljs-comment">// Add Distributed tracing</span>
|
||||
<span class="hljs-comment">// Add Distributed tracing</span>
|
||||
services.AddDistributedTracing(Configuration);
|
||||
|
||||
<span class="hljs-comment">// Add framework services.</span>
|
||||
<span class="hljs-comment">// Add framework services.</span>
|
||||
services.AddMvc();
|
||||
}
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">Configure</span>(<span class="hljs-params">IApplicationBuilder app</span>)
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">Configure</span>(<span class="hljs-params">IApplicationBuilder app</span>)
|
||||
</span>{
|
||||
app.UseStaticFiles();
|
||||
|
||||
|
@ -2081,7 +2098,7 @@
|
|||
|
||||
<pre><code class="xml hljs"><span class="hljs-tag"><<span class="hljs-name">ItemGroup</span>></span>
|
||||
...
|
||||
<span class="hljs-tag"><<span class="hljs-name">PackageReference</span> <span class="hljs-attr">Include</span>=<span class="hljs-string">"Steeltoe.Management.ExporterCore"</span> <span class="hljs-attr">Version</span>= <span class="hljs-string">"2.1.0"</span>/></span>
|
||||
<span class="hljs-tag"><<span class="hljs-name">PackageReference</span> <span class="hljs-attr">Include</span>=<span class="hljs-string">"Steeltoe.Management.ExporterCore"</span> <span class="hljs-attr">Version</span>= <span class="hljs-string">"2.1.0"</span>/></span>
|
||||
...
|
||||
<span class="hljs-tag"></<span class="hljs-name">ItemGroup</span>></span>
|
||||
</code></pre>
|
||||
|
@ -2149,25 +2166,27 @@
|
|||
|
||||
<pre><code class="csharp hljs"><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title">Startup</span>
|
||||
{
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">Startup</span>(<span class="hljs-params">IConfiguration configuration</span>)
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">Startup</span>(<span class="hljs-params">IConfiguration configuration</span>)
|
||||
</span>{
|
||||
Configuration = configuration;
|
||||
}
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">ConfigureServices</span>(<span class="hljs-params">IServiceCollection services</span>)
|
||||
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">ConfigureServices</span>(<span class="hljs-params">IServiceCollection services</span>)
|
||||
</span>{
|
||||
<span class="hljs-comment">// Add Distributed tracing</span>
|
||||
<span class="hljs-comment">// Add Distributed tracing</span>
|
||||
services.AddDistributedTracing(Configuration);
|
||||
|
||||
<span class="hljs-comment">// Export traces to Zipkin</span>
|
||||
<span class="hljs-comment">// Export traces to Zipkin</span>
|
||||
services.AddZipkinExporter(Configuration);
|
||||
...
|
||||
}
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">Configure</span>(<span class="hljs-params">IApplicationBuilder app</span>)
|
||||
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">Configure</span>(<span class="hljs-params">IApplicationBuilder app</span>)
|
||||
</span>{
|
||||
app.UseStaticFiles();
|
||||
app.UseMvc();
|
||||
|
||||
<span class="hljs-comment">// Start up trace exporter</span>
|
||||
<span class="hljs-comment">// Start up trace exporter</span>
|
||||
app.UseTracingExporter();
|
||||
}
|
||||
}
|
||||
|
@ -2187,7 +2206,7 @@
|
|||
|
||||
<pre><code class="xml hljs"><span class="hljs-tag"><<span class="hljs-name">ItemGroup</span>></span>
|
||||
...
|
||||
<span class="hljs-tag"><<span class="hljs-name">PackageReference</span> <span class="hljs-attr">Include</span>=<span class="hljs-string">"Steeltoe.Management.TaskCore"</span> <span class="hljs-attr">Version</span>= <span class="hljs-string">"2.3.0"</span>/></span>
|
||||
<span class="hljs-tag"><<span class="hljs-name">PackageReference</span> <span class="hljs-attr">Include</span>=<span class="hljs-string">"Steeltoe.Management.TaskCore"</span> <span class="hljs-attr">Version</span>= <span class="hljs-string">"2.3.0"</span>/></span>
|
||||
...
|
||||
<span class="hljs-tag"></<span class="hljs-name">ItemGroup</span>></span>
|
||||
</code></pre>
|
||||
|
@ -2213,15 +2232,15 @@
|
|||
<span class="hljs-comment"><span class="hljs-doctag">///</span> <span class="hljs-doctag"></summary></span></span>
|
||||
<span class="hljs-keyword">public</span> <span class="hljs-keyword">interface</span> <span class="hljs-title">IApplicationTask</span>
|
||||
{
|
||||
<span class="hljs-comment"><span class="hljs-doctag">///</span> <span class="hljs-doctag"><summary></span></span>
|
||||
<span class="hljs-comment"><span class="hljs-doctag">///</span> Gets globally unique name for the task</span>
|
||||
<span class="hljs-comment"><span class="hljs-doctag">///</span> <span class="hljs-doctag"></summary></span></span>
|
||||
<span class="hljs-keyword">string</span> Name { <span class="hljs-keyword">get</span>; }
|
||||
<span class="hljs-comment"><span class="hljs-doctag">///</span> <span class="hljs-doctag"><summary></span></span>
|
||||
<span class="hljs-comment"><span class="hljs-doctag">///</span> Gets globally unique name for the task</span>
|
||||
<span class="hljs-comment"><span class="hljs-doctag">///</span> <span class="hljs-doctag"></summary></span></span>
|
||||
<span class="hljs-keyword">string</span> Name { <span class="hljs-keyword">get</span>; }
|
||||
|
||||
<span class="hljs-comment"><span class="hljs-doctag">///</span> <span class="hljs-doctag"><summary></span></span>
|
||||
<span class="hljs-comment"><span class="hljs-doctag">///</span> Action which to run</span>
|
||||
<span class="hljs-comment"><span class="hljs-doctag">///</span> <span class="hljs-doctag"></summary></span></span>
|
||||
<span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">Run</span>(<span class="hljs-params"></span>)</span>;
|
||||
<span class="hljs-comment"><span class="hljs-doctag">///</span> <span class="hljs-doctag"><summary></span></span>
|
||||
<span class="hljs-comment"><span class="hljs-doctag">///</span> Action which to run</span>
|
||||
<span class="hljs-comment"><span class="hljs-doctag">///</span> <span class="hljs-doctag"></summary></span></span>
|
||||
<span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">Run</span>(<span class="hljs-params"></span>)</span>;
|
||||
}
|
||||
</code></pre>
|
||||
|
||||
|
@ -2288,10 +2307,10 @@
|
|||
<pre><code class="bash hljs"><span class="hljs-comment"># Push to Linux cell</span>
|
||||
cf push <span class="hljs-_">-f</span> manifest.yml -p bin/Debug/netcoreapp2.1/ubuntu.14.04-x64/publish
|
||||
|
||||
<span class="hljs-comment"># Push to Windows cell, .NET Core</span>
|
||||
<span class="hljs-comment"># Push to Windows cell, .NET Core</span>
|
||||
cf push <span class="hljs-_">-f</span> manifest-windows.yml -p bin/Debug/netcoreapp2.1/win10-x64/publish
|
||||
|
||||
<span class="hljs-comment"># Push to Windows cell, .NET Framework</span>
|
||||
<span class="hljs-comment"># Push to Windows cell, .NET Framework</span>
|
||||
cf push <span class="hljs-_">-f</span> manifest-windows.yml -p bin/Debug/net461/win10-x64/publish
|
||||
</code></pre>
|
||||
|
||||
|
@ -2315,25 +2334,27 @@ cf push <span class="hljs-_">-f</span> manifest-windows.yml -p bin/Debug/net461/
|
|||
|
||||
<pre><code class="csharp hljs"><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title">Startup</span>
|
||||
{
|
||||
<span class="hljs-keyword">public</span> IConfiguration Configuration { <span class="hljs-keyword">get</span>; }
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">Startup</span>(<span class="hljs-params">IConfiguration configuration</span>)
|
||||
<span class="hljs-keyword">public</span> IConfiguration Configuration { <span class="hljs-keyword">get</span>; }
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">Startup</span>(<span class="hljs-params">IConfiguration configuration</span>)
|
||||
</span>{
|
||||
Configuration = configuration;
|
||||
}
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">ConfigureServices</span>(<span class="hljs-params">IServiceCollection services</span>)
|
||||
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">ConfigureServices</span>(<span class="hljs-params">IServiceCollection services</span>)
|
||||
</span>{
|
||||
...
|
||||
<span class="hljs-comment">// Add all management endpoint services</span>
|
||||
<span class="hljs-comment">// Add all management endpoint services</span>
|
||||
services.AddCloudFoundryActuators(Configuration);
|
||||
...
|
||||
}
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">Configure</span>(<span class="hljs-params">IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory</span>)
|
||||
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">Configure</span>(<span class="hljs-params">IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory</span>)
|
||||
</span>{
|
||||
...
|
||||
<span class="hljs-comment">// Add all management endpoints into pipeline</span>
|
||||
<span class="hljs-comment">// Add all management endpoints into pipeline</span>
|
||||
app.UseCloudFoundryActuators();
|
||||
|
||||
<span class="hljs-comment">// Add ASP.NET Core MVC middleware to pipeline</span>
|
||||
<span class="hljs-comment">// Add ASP.NET Core MVC middleware to pipeline</span>
|
||||
app.UseMvc();
|
||||
...
|
||||
}
|
||||
|
@ -2377,9 +2398,9 @@ cf push <span class="hljs-_">-f</span> manifest-windows.yml -p bin/Debug/net461/
|
|||
|
||||
<pre><code class="csharp hljs"><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title">ManagementConfig</span>
|
||||
{
|
||||
<span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> IMetricsExporter MetricsExporter { <span class="hljs-keyword">get</span>; <span class="hljs-keyword">set</span>; }
|
||||
<span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> IMetricsExporter MetricsExporter { <span class="hljs-keyword">get</span>; <span class="hljs-keyword">set</span>; }
|
||||
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">ConfigureActuators</span>(<span class="hljs-params">
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">ConfigureActuators</span>(<span class="hljs-params">
|
||||
IConfiguration config,
|
||||
ILoggerProvider logger,
|
||||
IEnumerable<IHealthContributor> contrib,
|
||||
|
@ -2389,19 +2410,19 @@ cf push <span class="hljs-_">-f</span> manifest-windows.yml -p bin/Debug/net461/
|
|||
ActuatorConfigurator.UseCloudFoundryActuators(config, logger, contrib, api, factory);
|
||||
}
|
||||
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">Start</span>(<span class="hljs-params"></span>)
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">Start</span>(<span class="hljs-params"></span>)
|
||||
</span>{
|
||||
DiagnosticsManager.Instance.Start();
|
||||
<span class="hljs-keyword">if</span> (MetricsExporter != <span class="hljs-literal">null</span>)
|
||||
<span class="hljs-keyword">if</span> (MetricsExporter != <span class="hljs-literal">null</span>)
|
||||
{
|
||||
MetricsExporter.Start();
|
||||
}
|
||||
}
|
||||
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">Stop</span>(<span class="hljs-params"></span>)
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title">Stop</span>(<span class="hljs-params"></span>)
|
||||
</span>{
|
||||
DiagnosticsManager.Instance.Stop();
|
||||
<span class="hljs-keyword">if</span> (MetricsExporter != <span class="hljs-literal">null</span>)
|
||||
<span class="hljs-keyword">if</span> (MetricsExporter != <span class="hljs-literal">null</span>)
|
||||
{
|
||||
MetricsExporter.Stop();
|
||||
}
|
||||
|
@ -2447,11 +2468,11 @@ cf push <span class="hljs-_">-f</span> manifest-windows.yml -p bin/Debug/net461/
|
|||
|
||||
<pre><code class="csharp hljs"><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title">Startup</span>
|
||||
{
|
||||
<span class="hljs-keyword">private</span> IMetricsExporter MetricsExporter { <span class="hljs-keyword">get</span>; <span class="hljs-keyword">set</span>; }
|
||||
<span class="hljs-keyword">private</span> IMetricsExporter MetricsExporter { <span class="hljs-keyword">get</span>; <span class="hljs-keyword">set</span>; }
|
||||
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">Configuration</span>(<span class="hljs-params">IAppBuilder app</span>)
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">Configuration</span>(<span class="hljs-params">IAppBuilder app</span>)
|
||||
</span>{
|
||||
<span class="hljs-keyword">var</span> config = GlobalConfiguration.Configuration;
|
||||
<span class="hljs-keyword">var</span> config = GlobalConfiguration.Configuration;
|
||||
|
||||
app.UseCloudFoundryActuators(
|
||||
ApplicationConfig.Configuration,
|
||||
|
@ -2463,19 +2484,19 @@ cf push <span class="hljs-_">-f</span> manifest-windows.yml -p bin/Debug/net461/
|
|||
Start();
|
||||
}
|
||||
|
||||
<span class="hljs-function"><span class="hljs-keyword">private</span> <span class="hljs-keyword">void</span> <span class="hljs-title">Start</span>(<span class="hljs-params"></span>)
|
||||
<span class="hljs-function"><span class="hljs-keyword">private</span> <span class="hljs-keyword">void</span> <span class="hljs-title">Start</span>(<span class="hljs-params"></span>)
|
||||
</span>{
|
||||
DiagnosticsManager.Instance.Start();
|
||||
<span class="hljs-keyword">if</span> (MetricsExporter != <span class="hljs-literal">null</span>)
|
||||
<span class="hljs-keyword">if</span> (MetricsExporter != <span class="hljs-literal">null</span>)
|
||||
{
|
||||
MetricsExporter.Start();
|
||||
}
|
||||
}
|
||||
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">Stop</span>(<span class="hljs-params"></span>)
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">Stop</span>(<span class="hljs-params"></span>)
|
||||
</span>{
|
||||
DiagnosticsManager.Instance.Stop();
|
||||
<span class="hljs-keyword">if</span> (MetricsExporter != <span class="hljs-literal">null</span>)
|
||||
<span class="hljs-keyword">if</span> (MetricsExporter != <span class="hljs-literal">null</span>)
|
||||
{
|
||||
MetricsExporter.Stop();
|
||||
}
|
||||
|
|
|
@ -73,7 +73,7 @@
|
|||
|
||||
<pre><code class="xml hljs"><span class="hljs-tag"><<span class="hljs-name">ItemGroup</span>></span>
|
||||
...
|
||||
<span class="hljs-tag"><<span class="hljs-name">PackageReference</span> <span class="hljs-attr">Include</span>=<span class="hljs-string">"Steeltoe.Security.Authentication.CloudFoundryCore"</span> <span class="hljs-attr">Version</span>= <span class="hljs-string">"2.3.0"</span>/></span>
|
||||
<span class="hljs-tag"><<span class="hljs-name">PackageReference</span> <span class="hljs-attr">Include</span>=<span class="hljs-string">"Steeltoe.Security.Authentication.CloudFoundryCore"</span> <span class="hljs-attr">Version</span>= <span class="hljs-string">"2.3.0"</span>/></span>
|
||||
...
|
||||
<span class="hljs-tag"></<span class="hljs-name">ItemGroup</span>></span>
|
||||
</code></pre>
|
||||
|
@ -83,13 +83,13 @@
|
|||
<p>Configuring settings for the provider beyond what is provided in a service binding is not typically required, but when Cloud Foundry is using self-signed certificates, you might need to disable certificate validation, as shown in the following example:</p>
|
||||
|
||||
<pre><code class="json hljs">{
|
||||
<span class="hljs-attr">"security"</span>: {
|
||||
<span class="hljs-attr">"oauth2"</span>: {
|
||||
<span class="hljs-attr">"client"</span>: {
|
||||
<span class="hljs-attr">"validateCertificates"</span>: <span class="hljs-literal">false</span>
|
||||
}
|
||||
<span class="hljs-attr">"security"</span>: {
|
||||
<span class="hljs-attr">"oauth2"</span>: {
|
||||
<span class="hljs-attr">"client"</span>: {
|
||||
<span class="hljs-attr">"validateCertificates"</span>: <span class="hljs-literal">false</span>
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</code></pre>
|
||||
|
||||
|
@ -140,12 +140,12 @@
|
|||
|
||||
<span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title">Startup</span> {
|
||||
...
|
||||
<span class="hljs-keyword">public</span> IConfiguration Configuration { <span class="hljs-keyword">get</span>; <span class="hljs-keyword">private</span> <span class="hljs-keyword">set</span>; }
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">Startup</span>(<span class="hljs-params">IConfiguration configuration</span>)
|
||||
<span class="hljs-keyword">public</span> IConfiguration Configuration { <span class="hljs-keyword">get</span>; <span class="hljs-keyword">private</span> <span class="hljs-keyword">set</span>; }
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">Startup</span>(<span class="hljs-params">IConfiguration configuration</span>)
|
||||
</span>{
|
||||
Configuration = configuration;
|
||||
}
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">ConfigureServices</span>(<span class="hljs-params">IServiceCollection services</span>)
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">ConfigureServices</span>(<span class="hljs-params">IServiceCollection services</span>)
|
||||
</span>{
|
||||
...
|
||||
services.AddAuthentication(options =>
|
||||
|
@ -155,23 +155,23 @@
|
|||
})
|
||||
.AddCookie((options) =>
|
||||
{
|
||||
<span class="hljs-comment">// set values like login url, access denied path, etc here</span>
|
||||
<span class="hljs-comment">// set values like login url, access denied path, etc here</span>
|
||||
options.AccessDeniedPath = <span class="hljs-keyword">new</span> PathString(<span class="hljs-string">"/Home/AccessDenied"</span>);
|
||||
})
|
||||
.AddCloudFoundryOAuth(Configuration); <span class="hljs-comment">// Add Cloud Foundry authentication service</span>
|
||||
...
|
||||
}
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">Configure</span>(<span class="hljs-params">IApplicationBuilder app, ...</span>)
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">Configure</span>(<span class="hljs-params">IApplicationBuilder app, ...</span>)
|
||||
</span>{
|
||||
...
|
||||
<span class="hljs-comment">// Use the protocol from the original request when generating redirect uris</span>
|
||||
<span class="hljs-comment">// (eg: when TLS termination is handled by an appliance in front of the app)</span>
|
||||
<span class="hljs-comment">// Use the protocol from the original request when generating redirect uris</span>
|
||||
<span class="hljs-comment">// (eg: when TLS termination is handled by an appliance in front of the app)</span>
|
||||
app.UseForwardedHeaders(<span class="hljs-keyword">new</span> ForwardedHeadersOptions
|
||||
{
|
||||
ForwardedHeaders = ForwardedHeaders.XForwardedProto
|
||||
});
|
||||
|
||||
<span class="hljs-comment">// Add authentication middleware to pipeline</span>
|
||||
<span class="hljs-comment">// Add authentication middleware to pipeline</span>
|
||||
app.UseAuthentication();
|
||||
}
|
||||
...
|
||||
|
@ -191,24 +191,23 @@
|
|||
...
|
||||
<span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title">HomeController</span> : <span class="hljs-title">Controller</span>
|
||||
{
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> IActionResult <span class="hljs-title">Index</span>(<span class="hljs-params"></span>)
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> IActionResult <span class="hljs-title">Index</span>(<span class="hljs-params"></span>)
|
||||
</span>{
|
||||
<span class="hljs-keyword">return</span> View();
|
||||
<span class="hljs-keyword">return</span> View();
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> IActionResult <span class="hljs-title">About</span>(<span class="hljs-params"></span>)
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> IActionResult <span class="hljs-title">About</span>(<span class="hljs-params"></span>)
|
||||
</span>{
|
||||
ViewData[<span class="hljs-string">"Message"</span>] = <span class="hljs-string">"Your About page."</span>;
|
||||
<span class="hljs-keyword">return</span> View();
|
||||
<span class="hljs-keyword">return</span> View();
|
||||
}
|
||||
|
||||
[Authorize(Policy = <span class="hljs-string">"testgroup1"</span>)]
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> IActionResult <span class="hljs-title">Contact</span>(<span class="hljs-params"></span>)
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> IActionResult <span class="hljs-title">Contact</span>(<span class="hljs-params"></span>)
|
||||
</span>{
|
||||
ViewData[<span class="hljs-string">"Message"</span>] = <span class="hljs-string">"Your contact page."</span>;
|
||||
|
||||
<span class="hljs-keyword">return</span> View();
|
||||
<span class="hljs-keyword">return</span> View();
|
||||
}
|
||||
...
|
||||
}
|
||||
|
@ -294,13 +293,13 @@
|
|||
<p>Configuring settings for the provider beyond what is provided in a service binding is not typically required, but when Cloud Foundry is using self-signed certificates, you might need to disable certificate validation, as shown in the following example:</p>
|
||||
|
||||
<pre><code class="json hljs">{
|
||||
<span class="hljs-attr">"security"</span>: {
|
||||
<span class="hljs-attr">"oauth2"</span>: {
|
||||
<span class="hljs-attr">"client"</span>: {
|
||||
<span class="hljs-attr">"validateCertificates"</span>: <span class="hljs-literal">false</span>
|
||||
}
|
||||
<span class="hljs-attr">"security"</span>: {
|
||||
<span class="hljs-attr">"oauth2"</span>: {
|
||||
<span class="hljs-attr">"client"</span>: {
|
||||
<span class="hljs-attr">"validateCertificates"</span>: <span class="hljs-literal">false</span>
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</code></pre>
|
||||
|
||||
|
@ -381,9 +380,9 @@
|
|||
|
||||
<span class="hljs-keyword">namespace</span> <span class="hljs-title">CloudFoundrySingleSignon</span>
|
||||
{
|
||||
<span class="hljs-keyword">public</span> <span class="hljs-keyword">partial</span> <span class="hljs-keyword">class</span> <span class="hljs-title">Startup</span>
|
||||
<span class="hljs-keyword">public</span> <span class="hljs-keyword">partial</span> <span class="hljs-keyword">class</span> <span class="hljs-title">Startup</span>
|
||||
{
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">Configuration</span>(<span class="hljs-params">IAppBuilder app</span>)
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">Configuration</span>(<span class="hljs-params">IAppBuilder app</span>)
|
||||
</span>{
|
||||
app.SetDefaultSignInAsAuthenticationType(<span class="hljs-string">"ExternalCookie"</span>);
|
||||
app.UseCookieAuthentication(<span class="hljs-keyword">new</span> CookieAuthenticationOptions
|
||||
|
@ -417,7 +416,7 @@
|
|||
|
||||
<pre><code class="csharp hljs"><span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">AuthorizeSSO</span>(<span class="hljs-params"><span class="hljs-keyword">string</span> returnUrl</span>)
|
||||
</span>{
|
||||
<span class="hljs-keyword">var</span> properties = <span class="hljs-keyword">new</span> AuthenticationProperties { RedirectUri = returnUrl ?? Url.Action(<span class="hljs-string">"Secure"</span>, <span class="hljs-string">"Home"</span>) };
|
||||
<span class="hljs-keyword">var</span> properties = <span class="hljs-keyword">new</span> AuthenticationProperties { RedirectUri = returnUrl ?? Url.Action(<span class="hljs-string">"Secure"</span>, <span class="hljs-string">"Home"</span>) };
|
||||
HttpContext.GetOwinContext().Authentication.Challenge(properties, CloudFoundryDefaults.DisplayName);
|
||||
}
|
||||
</code></pre>
|
||||
|
@ -430,19 +429,19 @@
|
|||
|
||||
<pre><code class="csharp hljs"><span class="hljs-keyword">internal</span> <span class="hljs-keyword">class</span> <span class="hljs-title">ChallengeResult</span> : <span class="hljs-title">HttpUnauthorizedResult</span>
|
||||
{
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">ChallengeResult</span>(<span class="hljs-params"><span class="hljs-keyword">string</span> authType, <span class="hljs-keyword">string</span> redirectUri</span>)
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">ChallengeResult</span>(<span class="hljs-params"><span class="hljs-keyword">string</span> authType, <span class="hljs-keyword">string</span> redirectUri</span>)
|
||||
</span>{
|
||||
AuthenticationType = authType;
|
||||
RedirectUri = redirectUri;
|
||||
}
|
||||
|
||||
<span class="hljs-keyword">public</span> <span class="hljs-keyword">string</span> AuthenticationType { <span class="hljs-keyword">get</span>; <span class="hljs-keyword">set</span>; }
|
||||
<span class="hljs-keyword">public</span> <span class="hljs-keyword">string</span> AuthenticationType { <span class="hljs-keyword">get</span>; <span class="hljs-keyword">set</span>; }
|
||||
|
||||
<span class="hljs-keyword">public</span> <span class="hljs-keyword">string</span> RedirectUri { <span class="hljs-keyword">get</span>; <span class="hljs-keyword">set</span>; }
|
||||
<span class="hljs-keyword">public</span> <span class="hljs-keyword">string</span> RedirectUri { <span class="hljs-keyword">get</span>; <span class="hljs-keyword">set</span>; }
|
||||
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">override</span> <span class="hljs-keyword">void</span> <span class="hljs-title">ExecuteResult</span>(<span class="hljs-params">ControllerContext context</span>)
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">override</span> <span class="hljs-keyword">void</span> <span class="hljs-title">ExecuteResult</span>(<span class="hljs-params">ControllerContext context</span>)
|
||||
</span>{
|
||||
<span class="hljs-keyword">var</span> properties = <span class="hljs-keyword">new</span> AuthenticationProperties { RedirectUri = RedirectUri };
|
||||
<span class="hljs-keyword">var</span> properties = <span class="hljs-keyword">new</span> AuthenticationProperties { RedirectUri = RedirectUri };
|
||||
context.HttpContext.GetOwinContext().Authentication.Challenge(properties, AuthenticationType);
|
||||
}
|
||||
}
|
||||
|
@ -452,7 +451,7 @@
|
|||
|
||||
<pre><code class="csharp hljs"><span class="hljs-function"><span class="hljs-keyword">public</span> ActionResult <span class="hljs-title">AuthorizeSSO</span>(<span class="hljs-params"><span class="hljs-keyword">string</span> returnUrl</span>)
|
||||
</span>{
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> ChallengeResult(CloudFoundryDefaults.DisplayName, returnUrl ?? Url.Action(<span class="hljs-string">"Secure"</span>, <span class="hljs-string">"Home"</span>));
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> ChallengeResult(CloudFoundryDefaults.DisplayName, returnUrl ?? Url.Action(<span class="hljs-string">"Secure"</span>, <span class="hljs-string">"Home"</span>));
|
||||
}
|
||||
</code></pre>
|
||||
|
||||
|
@ -464,16 +463,16 @@
|
|||
...
|
||||
<span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title">HomeController</span> : <span class="hljs-title">Controller</span>
|
||||
{
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> ActionResult <span class="hljs-title">Index</span>(<span class="hljs-params"></span>)
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> ActionResult <span class="hljs-title">Index</span>(<span class="hljs-params"></span>)
|
||||
</span>{
|
||||
<span class="hljs-keyword">return</span> View();
|
||||
<span class="hljs-keyword">return</span> View();
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> ActionResult <span class="hljs-title">Secure</span>(<span class="hljs-params"></span>)
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> ActionResult <span class="hljs-title">Secure</span>(<span class="hljs-params"></span>)
|
||||
</span>{
|
||||
ViewData[<span class="hljs-string">"Message"</span>] = <span class="hljs-string">"This page requires authentication"</span>;
|
||||
<span class="hljs-keyword">return</span> View();
|
||||
<span class="hljs-keyword">return</span> View();
|
||||
}
|
||||
...
|
||||
}
|
||||
|
@ -486,14 +485,14 @@
|
|||
<span class="hljs-function"><span class="hljs-keyword">public</span> ActionResult <span class="hljs-title">TestGroupV1</span>(<span class="hljs-params"></span>)
|
||||
</span>{
|
||||
ViewBag.Message = <span class="hljs-string">"Congratulations, you have access to 'testgroup'"</span>;
|
||||
<span class="hljs-keyword">return</span> View(<span class="hljs-string">"Index"</span>);
|
||||
<span class="hljs-keyword">return</span> View(<span class="hljs-string">"Index"</span>);
|
||||
}
|
||||
|
||||
[CustomClaimsAuthorize(<span class="hljs-string">"testgroup"</span>)]
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> ActionResult <span class="hljs-title">TestGroupV2</span>(<span class="hljs-params"></span>)
|
||||
</span>{
|
||||
ViewBag.Message = <span class="hljs-string">"Congratulations, you have access to 'testgroup'"</span>;
|
||||
<span class="hljs-keyword">return</span> View(<span class="hljs-string">"Index"</span>);
|
||||
<span class="hljs-keyword">return</span> View(<span class="hljs-string">"Index"</span>);
|
||||
}
|
||||
</code></pre>
|
||||
|
||||
|
@ -537,7 +536,7 @@
|
|||
|
||||
<pre><code class="xml hljs"><span class="hljs-tag"><<span class="hljs-name">ItemGroup</span>></span>
|
||||
...
|
||||
<span class="hljs-tag"><<span class="hljs-name">PackageReference</span> <span class="hljs-attr">Include</span>=<span class="hljs-string">"Steeltoe.Security.Authentication.CloudFoundryCore"</span> <span class="hljs-attr">Version</span>= <span class="hljs-string">"2.3.0"</span>/></span>
|
||||
<span class="hljs-tag"><<span class="hljs-name">PackageReference</span> <span class="hljs-attr">Include</span>=<span class="hljs-string">"Steeltoe.Security.Authentication.CloudFoundryCore"</span> <span class="hljs-attr">Version</span>= <span class="hljs-string">"2.3.0"</span>/></span>
|
||||
...
|
||||
<span class="hljs-tag"></<span class="hljs-name">ItemGroup</span>></span>
|
||||
</code></pre>
|
||||
|
@ -547,13 +546,13 @@
|
|||
<p>Configuring additional settings for the provider is not typically required, but, when Cloud Foundry uses self-signed certificates, you might need to disable certificate validation, as shown in the following example:</p>
|
||||
|
||||
<pre><code class="json hljs">{
|
||||
<span class="hljs-attr">"security"</span>: {
|
||||
<span class="hljs-attr">"oauth2"</span>: {
|
||||
<span class="hljs-attr">"client"</span>: {
|
||||
<span class="hljs-attr">"validateCertificates"</span>: <span class="hljs-literal">false</span>
|
||||
}
|
||||
<span class="hljs-attr">"security"</span>: {
|
||||
<span class="hljs-attr">"oauth2"</span>: {
|
||||
<span class="hljs-attr">"client"</span>: {
|
||||
<span class="hljs-attr">"validateCertificates"</span>: <span class="hljs-literal">false</span>
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</code></pre>
|
||||
|
||||
|
@ -594,17 +593,17 @@
|
|||
|
||||
<span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title">Startup</span> {
|
||||
...
|
||||
<span class="hljs-keyword">public</span> IConfiguration Configuration { <span class="hljs-keyword">get</span>; <span class="hljs-keyword">private</span> <span class="hljs-keyword">set</span>; }
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">Startup</span>(<span class="hljs-params">IConfiguration configuration</span>)
|
||||
<span class="hljs-keyword">public</span> IConfiguration Configuration { <span class="hljs-keyword">get</span>; <span class="hljs-keyword">private</span> <span class="hljs-keyword">set</span>; }
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">Startup</span>(<span class="hljs-params">IConfiguration configuration</span>)
|
||||
</span>{
|
||||
Configuration = configuration;
|
||||
}
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">ConfigureServices</span>(<span class="hljs-params">IServiceCollection services</span>)
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">ConfigureServices</span>(<span class="hljs-params">IServiceCollection services</span>)
|
||||
</span>{
|
||||
<span class="hljs-comment">// Add Cloud Foundry JWT Authentication service as the default</span>
|
||||
<span class="hljs-comment">// Add Cloud Foundry JWT Authentication service as the default</span>
|
||||
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
|
||||
.AddCloudFoundryJwtBearer(Configuration);
|
||||
<span class="hljs-comment">// Add authorization policies</span>
|
||||
<span class="hljs-comment">// Add authorization policies</span>
|
||||
services.AddAuthorization(options =>
|
||||
{
|
||||
options.AddPolicy(<span class="hljs-string">"Orders"</span>, policy => policy.RequireClaim(<span class="hljs-string">"scope"</span>, <span class="hljs-string">"order.me"</span>));
|
||||
|
@ -612,10 +611,10 @@
|
|||
});
|
||||
...
|
||||
}
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">Configure</span>(<span class="hljs-params">IApplicationBuilder app, ...</span>)
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">Configure</span>(<span class="hljs-params">IApplicationBuilder app, ...</span>)
|
||||
</span>{
|
||||
...
|
||||
<span class="hljs-comment">// Add the authentication middleware to the pipeline</span>
|
||||
<span class="hljs-comment">// Add the authentication middleware to the pipeline</span>
|
||||
app.UseAuthentication();
|
||||
}
|
||||
...
|
||||
|
@ -637,12 +636,12 @@
|
|||
[Route(<span class="hljs-string">"api/[controller]"</span>)]
|
||||
<span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title">ValuesController</span> : <span class="hljs-title">Controller</span>
|
||||
{
|
||||
<span class="hljs-comment">// GET api/values</span>
|
||||
<span class="hljs-comment">// GET api/values</span>
|
||||
[HttpGet]
|
||||
[Authorize(Policy = <span class="hljs-string">"testgroup"</span>)]
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> IEnumerable<<span class="hljs-keyword">string</span>> <span class="hljs-title">Get</span>(<span class="hljs-params"></span>)
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> IEnumerable<<span class="hljs-keyword">string</span>> <span class="hljs-title">Get</span>(<span class="hljs-params"></span>)
|
||||
</span>{
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> <span class="hljs-keyword">string</span>[] { <span class="hljs-string">"value1"</span>, <span class="hljs-string">"value2"</span> };
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> <span class="hljs-keyword">string</span>[] { <span class="hljs-string">"value1"</span>, <span class="hljs-string">"value2"</span> };
|
||||
}
|
||||
}
|
||||
</code></pre>
|
||||
|
@ -680,13 +679,13 @@
|
|||
<p>Configuring additional settings for the provider is not typically required, but, when Cloud Foundry uses self-signed certificates, you might need to disable certificate validation, as shown in the following example:</p>
|
||||
|
||||
<pre><code class="json hljs">{
|
||||
<span class="hljs-attr">"security"</span>: {
|
||||
<span class="hljs-attr">"oauth2"</span>: {
|
||||
<span class="hljs-attr">"client"</span>: {
|
||||
<span class="hljs-attr">"validateCertificates"</span>: <span class="hljs-literal">false</span>
|
||||
}
|
||||
<span class="hljs-attr">"security"</span>: {
|
||||
<span class="hljs-attr">"oauth2"</span>: {
|
||||
<span class="hljs-attr">"client"</span>: {
|
||||
<span class="hljs-attr">"validateCertificates"</span>: <span class="hljs-literal">false</span>
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</code></pre>
|
||||
|
||||
|
@ -737,9 +736,9 @@
|
|||
|
||||
<span class="hljs-keyword">namespace</span> <span class="hljs-title">CloudFoundryJwtAuthentication</span>
|
||||
{
|
||||
<span class="hljs-keyword">public</span> <span class="hljs-keyword">partial</span> <span class="hljs-keyword">class</span> <span class="hljs-title">Startup</span>
|
||||
<span class="hljs-keyword">public</span> <span class="hljs-keyword">partial</span> <span class="hljs-keyword">class</span> <span class="hljs-title">Startup</span>
|
||||
{
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">ConfigureAuth</span>(<span class="hljs-params">IAppBuilder app</span>)
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">ConfigureAuth</span>(<span class="hljs-params">IAppBuilder app</span>)
|
||||
</span>{
|
||||
app.UseCloudFoundryJwtBearerAuthentication(ApplicationConfig.Configuration);
|
||||
}
|
||||
|
@ -761,12 +760,12 @@
|
|||
|
||||
<span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title">ValuesController</span> : <span class="hljs-title">ApiController</span>
|
||||
{
|
||||
<span class="hljs-comment">// GET: api/Values</span>
|
||||
<span class="hljs-comment">// GET: api/Values</span>
|
||||
[CustomClaimsAuthorize(<span class="hljs-string">"testgroup"</span>)]
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> IEnumerable<<span class="hljs-keyword">string</span>> <span class="hljs-title">Get</span>(<span class="hljs-params"></span>)
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> IEnumerable<<span class="hljs-keyword">string</span>> <span class="hljs-title">Get</span>(<span class="hljs-params"></span>)
|
||||
</span>{
|
||||
Console.WriteLine(<span class="hljs-string">"Received GET Request"</span>);
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> <span class="hljs-keyword">string</span>[] { <span class="hljs-string">"value1"</span>, <span class="hljs-string">"value2"</span> };
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> <span class="hljs-keyword">string</span>[] { <span class="hljs-string">"value1"</span>, <span class="hljs-string">"value2"</span> };
|
||||
}
|
||||
}
|
||||
</code></pre>
|
||||
|
@ -803,13 +802,13 @@
|
|||
<p>Configuring additional settings for the provider is not typically required, but, when Cloud Foundry uses self-signed certificates, you might need to disable certificate validation, as shown in the following example:</p>
|
||||
|
||||
<pre><code class="json hljs">{
|
||||
<span class="hljs-attr">"security"</span>: {
|
||||
<span class="hljs-attr">"oauth2"</span>: {
|
||||
<span class="hljs-attr">"client"</span>: {
|
||||
<span class="hljs-attr">"validateCertificates"</span>: <span class="hljs-literal">false</span>
|
||||
}
|
||||
<span class="hljs-attr">"security"</span>: {
|
||||
<span class="hljs-attr">"oauth2"</span>: {
|
||||
<span class="hljs-attr">"client"</span>: {
|
||||
<span class="hljs-attr">"validateCertificates"</span>: <span class="hljs-literal">false</span>
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</code></pre>
|
||||
|
||||
|
@ -868,10 +867,10 @@
|
|||
|
||||
<span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title">Global</span> : <span class="hljs-title">System</span>.<span class="hljs-title">Web</span>.<span class="hljs-title">HttpApplication</span>
|
||||
{
|
||||
<span class="hljs-function"><span class="hljs-keyword">protected</span> <span class="hljs-keyword">void</span> <span class="hljs-title">Application_Start</span>(<span class="hljs-params"><span class="hljs-keyword">object</span> sender, EventArgs e</span>)
|
||||
<span class="hljs-function"><span class="hljs-keyword">protected</span> <span class="hljs-keyword">void</span> <span class="hljs-title">Application_Start</span>(<span class="hljs-params"><span class="hljs-keyword">object</span> sender, EventArgs e</span>)
|
||||
</span>{
|
||||
ApplicationConfig.RegisterConfig(<span class="hljs-string">"development"</span>);
|
||||
<span class="hljs-keyword">var</span> serviceHost = <span class="hljs-keyword">new</span> ServiceHost(<span class="hljs-keyword">typeof</span>(ValueService));
|
||||
<span class="hljs-keyword">var</span> serviceHost = <span class="hljs-keyword">new</span> ServiceHost(<span class="hljs-keyword">typeof</span>(ValueService));
|
||||
serviceHost.AddJwtAuthorization(ApplicationConfig.Configuration);
|
||||
}
|
||||
}
|
||||
|
@ -890,12 +889,12 @@
|
|||
|
||||
<span class="hljs-keyword">namespace</span> <span class="hljs-title">CloudFoundryWcf</span>
|
||||
{
|
||||
<span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title">ValueService</span> : <span class="hljs-title">IValueService</span>
|
||||
<span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title">ValueService</span> : <span class="hljs-title">IValueService</span>
|
||||
{
|
||||
[ScopePermission(SecurityAction.Demand, Scope = <span class="hljs-string">"testgroup"</span>)]
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">string</span> <span class="hljs-title">GetData</span>(<span class="hljs-params"></span>)
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">string</span> <span class="hljs-title">GetData</span>(<span class="hljs-params"></span>)
|
||||
</span>{
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-string">"Hello from the WCF Sample!"</span>;
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-string">"Hello from the WCF Sample!"</span>;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -945,25 +944,27 @@
|
|||
|
||||
<p>Regardless of the method chosen for instantiating the <code>CloudFoundryOptions</code>, the code to apply the behavior should look something like this:</p>
|
||||
|
||||
<pre><code class="csharp hljs"> <span class="hljs-comment">// create an instance of the WCF client</span>
|
||||
<span class="hljs-keyword">var</span> sRef = <span class="hljs-keyword">new</span> ValueService.ValueServiceClient();
|
||||
<pre><code class="csharp hljs">
|
||||
<span class="hljs-comment">// create an instance of the WCF client</span>
|
||||
<span class="hljs-keyword">var</span> sRef = <span class="hljs-keyword">new</span> ValueService.ValueServiceClient();
|
||||
|
||||
<span class="hljs-comment">// apply the behavior, expecting it to manage and pass the token for the application</span>
|
||||
<span class="hljs-comment">// apply the behavior, expecting it to manage and pass the token for the application</span>
|
||||
sRef.Endpoint.EndpointBehaviors.Add(<span class="hljs-keyword">new</span> JwtHeaderEndpointBehavior(<span class="hljs-keyword">new</span> CloudFoundryOptions(configuration)));
|
||||
<span class="hljs-keyword">string</span> serviceResponse = <span class="hljs-keyword">await</span> sRef.GetDataAsync();
|
||||
<span class="hljs-keyword">string</span> serviceResponse = <span class="hljs-keyword">await</span> sRef.GetDataAsync();
|
||||
</code></pre>
|
||||
|
||||
<p>To pass a user’s token (instead of the application’s) to the backing service, first set <code>security:oauth2:client:forwardUserCredentials</code> to <code>true</code> in your configuration. You will also need to retrieve the user’s token and pass that into the <code>JwtHeaderEndpointBehavior</code> when making requests, as seen in this example:</p>
|
||||
|
||||
<pre><code class="csharp hljs"> <span class="hljs-comment">// retrieve the user's token</span>
|
||||
<span class="hljs-keyword">var</span> token = Request.GetOwinContext().Authentication.User.Claims.First(c => c.Type == ClaimTypes.Authentication)?.Value;
|
||||
<pre><code class="csharp hljs">
|
||||
<span class="hljs-comment">// retrieve the user's token</span>
|
||||
<span class="hljs-keyword">var</span> token = Request.GetOwinContext().Authentication.User.Claims.First(c => c.Type == ClaimTypes.Authentication)?.Value;
|
||||
|
||||
<span class="hljs-comment">// create an instance of the WCF client</span>
|
||||
<span class="hljs-keyword">var</span> sRef = <span class="hljs-keyword">new</span> ValueService.ValueServiceClient(binding, address);
|
||||
<span class="hljs-comment">// create an instance of the WCF client</span>
|
||||
<span class="hljs-keyword">var</span> sRef = <span class="hljs-keyword">new</span> ValueService.ValueServiceClient(binding, address);
|
||||
|
||||
<span class="hljs-comment">// apply the behavior, including the user's token</span>
|
||||
<span class="hljs-comment">// apply the behavior, including the user's token</span>
|
||||
sRef.Endpoint.EndpointBehaviors.Add(<span class="hljs-keyword">new</span> JwtHeaderEndpointBehavior(<span class="hljs-keyword">new</span> CloudFoundryOptions(ApplicationConfig.Configuration), token));
|
||||
<span class="hljs-keyword">string</span> serviceResponse = <span class="hljs-keyword">await</span> sRef.GetDataAsync();
|
||||
<span class="hljs-keyword">string</span> serviceResponse = <span class="hljs-keyword">await</span> sRef.GetDataAsync();
|
||||
</code></pre>
|
||||
|
||||
<h1 id="4-0-redis-key-storage-provider">4.0 Redis Key Storage Provider</h1>
|
||||
|
@ -991,7 +992,7 @@
|
|||
|
||||
<pre><code class="xml hljs"><span class="hljs-tag"><<span class="hljs-name">ItemGroup</span>></span>
|
||||
...
|
||||
<span class="hljs-tag"><<span class="hljs-name">PackageReference</span> <span class="hljs-attr">Include</span>=<span class="hljs-string">"Steeltoe.Security.DataProtection.RedisCore"</span> <span class="hljs-attr">Version</span>= <span class="hljs-string">"2.3.0"</span>/></span>
|
||||
<span class="hljs-tag"><<span class="hljs-name">PackageReference</span> <span class="hljs-attr">Include</span>=<span class="hljs-string">"Steeltoe.Security.DataProtection.RedisCore"</span> <span class="hljs-attr">Version</span>= <span class="hljs-string">"2.3.0"</span>/></span>
|
||||
...
|
||||
<span class="hljs-tag"></<span class="hljs-name">ItemGroup</span>></span>
|
||||
</code></pre>
|
||||
|
@ -1002,7 +1003,7 @@
|
|||
|
||||
<pre><code class="xml hljs"><span class="hljs-tag"><<span class="hljs-name">ItemGroup</span>></span>
|
||||
...
|
||||
<span class="hljs-tag"><<span class="hljs-name">PackageReference</span> <span class="hljs-attr">Include</span>=<span class="hljs-string">"Steeltoe.CloudFoundry.ConnectorCore"</span> <span class="hljs-attr">Version</span>= <span class="hljs-string">"2.3.0"</span>/></span>
|
||||
<span class="hljs-tag"><<span class="hljs-name">PackageReference</span> <span class="hljs-attr">Include</span>=<span class="hljs-string">"Steeltoe.CloudFoundry.ConnectorCore"</span> <span class="hljs-attr">Version</span>= <span class="hljs-string">"2.3.0"</span>/></span>
|
||||
...
|
||||
<span class="hljs-tag"></<span class="hljs-name">ItemGroup</span>></span>
|
||||
</code></pre>
|
||||
|
@ -1037,17 +1038,17 @@ cf restage myApp
|
|||
|
||||
<span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title">Startup</span> {
|
||||
...
|
||||
<span class="hljs-keyword">public</span> IConfiguration Configuration { <span class="hljs-keyword">get</span>; <span class="hljs-keyword">private</span> <span class="hljs-keyword">set</span>; }
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">Startup</span>(<span class="hljs-params">IConfiguration configuration</span>)
|
||||
<span class="hljs-keyword">public</span> IConfiguration Configuration { <span class="hljs-keyword">get</span>; <span class="hljs-keyword">private</span> <span class="hljs-keyword">set</span>; }
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">Startup</span>(<span class="hljs-params">IConfiguration configuration</span>)
|
||||
</span>{
|
||||
Configuration = configuration;
|
||||
}
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">ConfigureServices</span>(<span class="hljs-params">IServiceCollection services</span>)
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">ConfigureServices</span>(<span class="hljs-params">IServiceCollection services</span>)
|
||||
</span>{
|
||||
<span class="hljs-comment">// Add StackExchange ConnectionMultiplexer configured from Cloud Foundry</span>
|
||||
<span class="hljs-comment">// Add StackExchange ConnectionMultiplexer configured from Cloud Foundry</span>
|
||||
services.AddRedisConnectionMultiplexer(Configuration);
|
||||
|
||||
<span class="hljs-comment">// Add framework services.</span>
|
||||
<span class="hljs-comment">// Add framework services.</span>
|
||||
services.AddMvc();
|
||||
...
|
||||
}
|
||||
|
@ -1066,22 +1067,22 @@ cf restage myApp
|
|||
|
||||
<span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title">Startup</span> {
|
||||
...
|
||||
<span class="hljs-keyword">public</span> IConfiguration Configuration { <span class="hljs-keyword">get</span>; <span class="hljs-keyword">private</span> <span class="hljs-keyword">set</span>; }
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">Startup</span>(<span class="hljs-params">IConfiguration configuration</span>)
|
||||
<span class="hljs-keyword">public</span> IConfiguration Configuration { <span class="hljs-keyword">get</span>; <span class="hljs-keyword">private</span> <span class="hljs-keyword">set</span>; }
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">Startup</span>(<span class="hljs-params">IConfiguration configuration</span>)
|
||||
</span>{
|
||||
Configuration = configuration;
|
||||
}
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">ConfigureServices</span>(<span class="hljs-params">IServiceCollection services</span>)
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">ConfigureServices</span>(<span class="hljs-params">IServiceCollection services</span>)
|
||||
</span>{
|
||||
<span class="hljs-comment">// Add StackExchange ConnectionMultiplexer configured from Cloud Foundry</span>
|
||||
<span class="hljs-comment">// Add StackExchange ConnectionMultiplexer configured from Cloud Foundry</span>
|
||||
services.AddRedisConnectionMultiplexer(Configuration);
|
||||
|
||||
<span class="hljs-comment">// Add DataProtection and persist keys to Cloud Foundry Redis service</span>
|
||||
<span class="hljs-comment">// Add DataProtection and persist keys to Cloud Foundry Redis service</span>
|
||||
services.AddDataProtection()
|
||||
.PersistKeysToRedis()
|
||||
.SetApplicationName(<span class="hljs-string">"Some Name"</span>);
|
||||
|
||||
<span class="hljs-comment">// Add framework services.</span>
|
||||
<span class="hljs-comment">// Add framework services.</span>
|
||||
services.AddMvc();
|
||||
...
|
||||
}
|
||||
|
@ -1122,7 +1123,7 @@ cf restage myApp
|
|||
|
||||
<pre><code class="xml hljs"><span class="hljs-tag"><<span class="hljs-name">ItemGroup</span>></span>
|
||||
...
|
||||
<span class="hljs-tag"><<span class="hljs-name">PackageReference</span> <span class="hljs-attr">Include</span>=<span class="hljs-string">"Steeltoe.Security.DataProtection.CredHubCore"</span> <span class="hljs-attr">Version</span>= <span class="hljs-string">"2.3.0"</span>/></span>
|
||||
<span class="hljs-tag"><<span class="hljs-name">PackageReference</span> <span class="hljs-attr">Include</span>=<span class="hljs-string">"Steeltoe.Security.DataProtection.CredHubCore"</span> <span class="hljs-attr">Version</span>= <span class="hljs-string">"2.3.0"</span>/></span>
|
||||
...
|
||||
<span class="hljs-tag"></<span class="hljs-name">ItemGroup</span>></span>
|
||||
</code></pre>
|
||||
|
@ -1131,10 +1132,11 @@ cf restage myApp
|
|||
|
||||
<p>Settings for this library are expected to have a prefix of <code>CredHubClient</code>. The following example shows what that looks like in JSON:</p>
|
||||
|
||||
<pre><code class="json hljs">{
|
||||
<pre><code class="json hljs">
|
||||
{
|
||||
...
|
||||
<span class="hljs-attr">"credHubClient"</span>: {
|
||||
<span class="hljs-attr">"validateCertificates"</span>: <span class="hljs-string">"false"</span>
|
||||
<span class="hljs-attr">"credHubClient"</span>: {
|
||||
<span class="hljs-attr">"validateCertificates"</span>: <span class="hljs-string">"false"</span>
|
||||
}
|
||||
...
|
||||
}
|
||||
|
@ -1193,13 +1195,13 @@ cf restage myApp
|
|||
<span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title">Startup</span>
|
||||
{
|
||||
ILoggerFactory logFactory;
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">Startup</span>(<span class="hljs-params">IConfiguration configuration, ILoggerFactory logFactory</span>)
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">Startup</span>(<span class="hljs-params">IConfiguration configuration, ILoggerFactory logFactory</span>)
|
||||
</span>{
|
||||
Configuration = configuration;
|
||||
<span class="hljs-keyword">this</span>.logFactory = logFactory;
|
||||
<span class="hljs-keyword">this</span>.logFactory = logFactory;
|
||||
}
|
||||
<span class="hljs-keyword">public</span> IConfiguration Configuration { <span class="hljs-keyword">get</span>; }
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">ConfigureServices</span>(<span class="hljs-params">IServiceCollection services</span>)
|
||||
<span class="hljs-keyword">public</span> IConfiguration Configuration { <span class="hljs-keyword">get</span>; }
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title">ConfigureServices</span>(<span class="hljs-params">IServiceCollection services</span>)
|
||||
</span>{
|
||||
services.AddMvc();
|
||||
services.AddCredHubClient(Configuration, logFactory);
|
||||
|
@ -1341,21 +1343,21 @@ cf restage myApp
|
|||
<p>The following example shows a typical request object for the <code>Interpolate</code> endpoint:</p>
|
||||
|
||||
<pre><code class="json hljs">{
|
||||
<span class="hljs-attr">"p-demo-resource"</span>: [
|
||||
<span class="hljs-attr">"p-demo-resource"</span>: [
|
||||
{
|
||||
<span class="hljs-attr">"credentials"</span>: {
|
||||
<span class="hljs-attr">"credhub-ref"</span>: <span class="hljs-string">"((/config-server/credentials))"</span>
|
||||
},
|
||||
<span class="hljs-attr">"label"</span>: <span class="hljs-string">"p-config-server"</span>,
|
||||
<span class="hljs-attr">"name"</span>: <span class="hljs-string">"config-server"</span>,
|
||||
<span class="hljs-attr">"plan"</span>: <span class="hljs-string">"standard"</span>,
|
||||
<span class="hljs-attr">"provider"</span>: <span class="hljs-literal">null</span>,
|
||||
<span class="hljs-attr">"syslog_drain_url"</span>: <span class="hljs-literal">null</span>,
|
||||
<span class="hljs-attr">"tags"</span>: [
|
||||
<span class="hljs-string">"configuration"</span>,
|
||||
<span class="hljs-string">"spring-cloud"</span>
|
||||
],
|
||||
<span class="hljs-attr">"volume_mounts"</span>: []
|
||||
<span class="hljs-attr">"credentials"</span>: {
|
||||
<span class="hljs-attr">"credhub-ref"</span>: <span class="hljs-string">"((/config-server/credentials))"</span>
|
||||
},
|
||||
<span class="hljs-attr">"label"</span>: <span class="hljs-string">"p-config-server"</span>,
|
||||
<span class="hljs-attr">"name"</span>: <span class="hljs-string">"config-server"</span>,
|
||||
<span class="hljs-attr">"plan"</span>: <span class="hljs-string">"standard"</span>,
|
||||
<span class="hljs-attr">"provider"</span>: <span class="hljs-literal">null</span>,
|
||||
<span class="hljs-attr">"syslog_drain_url"</span>: <span class="hljs-literal">null</span>,
|
||||
<span class="hljs-attr">"tags"</span>: [
|
||||
<span class="hljs-string">"configuration"</span>,
|
||||
<span class="hljs-string">"spring-cloud"</span>
|
||||
],
|
||||
<span class="hljs-attr">"volume_mounts"</span>: []
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@ -1364,28 +1366,28 @@ cf restage myApp
|
|||
<p>The following example shows a typical response object from the <code>Interpolate</code> endpoint:</p>
|
||||
|
||||
<pre><code class="json hljs">{
|
||||
<span class="hljs-attr">"p-demo-resource"</span>: [
|
||||
{
|
||||
<span class="hljs-attr">"credentials"</span>: {
|
||||
<span class="hljs-attr">"key"</span>: <span class="hljs-number">123</span>,
|
||||
<span class="hljs-attr">"key_list"</span>: [
|
||||
<span class="hljs-string">"val1"</span>,
|
||||
<span class="hljs-string">"val2"</span>
|
||||
],
|
||||
<span class="hljs-attr">"is_true"</span>: <span class="hljs-literal">true</span>
|
||||
},
|
||||
<span class="hljs-attr">"label"</span>: <span class="hljs-string">"p-config-server"</span>,
|
||||
<span class="hljs-attr">"name"</span>: <span class="hljs-string">"config-server"</span>,
|
||||
<span class="hljs-attr">"plan"</span>: <span class="hljs-string">"standard"</span>,
|
||||
<span class="hljs-attr">"provider"</span>: <span class="hljs-literal">null</span>,
|
||||
<span class="hljs-attr">"syslog_drain_url"</span>: <span class="hljs-literal">null</span>,
|
||||
<span class="hljs-attr">"tags"</span>: [
|
||||
<span class="hljs-string">"configuration"</span>,
|
||||
<span class="hljs-string">"spring-cloud"</span>
|
||||
],
|
||||
<span class="hljs-attr">"volume_mounts"</span>: []
|
||||
}
|
||||
]
|
||||
<span class="hljs-attr">"p-demo-resource"</span>: [
|
||||
{
|
||||
<span class="hljs-attr">"credentials"</span>: {
|
||||
<span class="hljs-attr">"key"</span>: <span class="hljs-number">123</span>,
|
||||
<span class="hljs-attr">"key_list"</span>: [
|
||||
<span class="hljs-string">"val1"</span>,
|
||||
<span class="hljs-string">"val2"</span>
|
||||
],
|
||||
<span class="hljs-attr">"is_true"</span>: <span class="hljs-literal">true</span>
|
||||
},
|
||||
<span class="hljs-attr">"label"</span>: <span class="hljs-string">"p-config-server"</span>,
|
||||
<span class="hljs-attr">"name"</span>: <span class="hljs-string">"config-server"</span>,
|
||||
<span class="hljs-attr">"plan"</span>: <span class="hljs-string">"standard"</span>,
|
||||
<span class="hljs-attr">"provider"</span>: <span class="hljs-literal">null</span>,
|
||||
<span class="hljs-attr">"syslog_drain_url"</span>: <span class="hljs-literal">null</span>,
|
||||
<span class="hljs-attr">"tags"</span>: [
|
||||
<span class="hljs-string">"configuration"</span>,
|
||||
<span class="hljs-string">"spring-cloud"</span>
|
||||
],
|
||||
<span class="hljs-attr">"volume_mounts"</span>: []
|
||||
}
|
||||
]
|
||||
}
|
||||
</code></pre>
|
||||
|
||||
|
@ -1655,20 +1657,20 @@ cf push <span class="hljs-_">-f</span> manifest-windows.yml -p bin/Debug/net461/
|
|||
|
||||
<pre><code class="csharp hljs"><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title">Program</span> {
|
||||
...
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> IWebHost <span class="hljs-title">BuildWebHost</span>(<span class="hljs-params"><span class="hljs-keyword">string</span>[] args</span>)
|
||||
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> IWebHost <span class="hljs-title">BuildWebHost</span>(<span class="hljs-params"><span class="hljs-keyword">string</span>[] args</span>)
|
||||
</span>{
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> WebHostBuilder()
|
||||
<span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> WebHostBuilder()
|
||||
...
|
||||
.UseCloudFoundryHosting()
|
||||
...
|
||||
.ConfigureAppConfiguration((builderContext, configBuilder) =>
|
||||
{
|
||||
<span class="hljs-keyword">var</span> env = builderContext.HostingEnvironment;
|
||||
<span class="hljs-keyword">var</span> env = builderContext.HostingEnvironment;
|
||||
configBuilder.SetBasePath(env.ContentRootPath)
|
||||
.AddJsonFile(<span class="hljs-string">"appsettings.json"</span>, optional: <span class="hljs-literal">true</span>, reloadOnChange: <span class="hljs-literal">true</span>)
|
||||
.AddJsonFile(<span class="hljs-string">$"appsettings.<span class="hljs-subst">{env.EnvironmentName}</span>.json"</span>, optional: <span class="hljs-literal">true</span>)
|
||||
.AddEnvironmentVariables()
|
||||
<span class="hljs-comment">// Add the Cloudfoundry VCAP settings to configuration</span>
|
||||
<span class="hljs-comment">// Add the Cloudfoundry VCAP settings to configuration</span>
|
||||
.AddCloudFoundry();
|
||||
})
|
||||
.Build();
|
||||
|
|
|
@ -97,7 +97,7 @@
|
|||
|
||||
<pre><code class="csharp hljs"><span class="hljs-keyword">using</span> (<span class="hljs-keyword">new</span> WindowsNetworkFileShare(<span class="hljs-string">@"\\server\path"</span>, <span class="hljs-keyword">new</span> System.Net.NetworkCredential(<span class="hljs-string">"username"</span>, <span class="hljs-string">"password"</span>)))
|
||||
{
|
||||
<span class="hljs-comment">// Interact with an attached network share here</span>
|
||||
<span class="hljs-comment">// Interact with an attached network share here</span>
|
||||
}
|
||||
</code></pre>
|
||||
|
||||
|
@ -113,15 +113,15 @@
|
|||
|
||||
<pre><code class="csharp hljs"><span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">SomeClassConstructor</span>(<span class="hljs-params">IOptions<CloudFoundryServicesOptions> serviceOptions</span>)
|
||||
</span>{
|
||||
<span class="hljs-keyword">var</span> userName = serviceOptions.Services[<span class="hljs-string">"credhub"</span>]
|
||||
<span class="hljs-keyword">var</span> userName = serviceOptions.Services[<span class="hljs-string">"credhub"</span>]
|
||||
.First(q => q.Name.Equals(<span class="hljs-string">"my-network-share"</span>))
|
||||
.Credentials[<span class="hljs-string">"share-username"</span>].Value;
|
||||
<span class="hljs-keyword">var</span> password = serviceOptions.Services[<span class="hljs-string">"credhub"</span>]
|
||||
<span class="hljs-keyword">var</span> password = serviceOptions.Services[<span class="hljs-string">"credhub"</span>]
|
||||
.First(q => q.Name.Equals(<span class="hljs-string">"my-network-share"</span>))
|
||||
.Credentials[<span class="hljs-string">"share-password"</span>].Value;
|
||||
|
||||
<span class="hljs-comment">// create credential object to pass to WindowsNetworkFileShare</span>
|
||||
<span class="hljs-keyword">var</span> _shareCredential = <span class="hljs-keyword">new</span> NetworkCredential(userName, password);
|
||||
<span class="hljs-comment">// create credential object to pass to WindowsNetworkFileShare</span>
|
||||
<span class="hljs-keyword">var</span> _shareCredential = <span class="hljs-keyword">new</span> NetworkCredential(userName, password);
|
||||
}
|
||||
</code></pre>
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче