如何将 c# dotnet core 3.1 微服务流绑定到涡轮服务器流

How to bind c# dotnet core 3.1 microservice stream to turbine server stream

我在 openshift 3 上有一个涡轮服务器 运行,并使用 steeltoe 3.0.2 断路器库部署了一个 donet core 3.1 c# 微服务。我可以通过服务流 url (/hystrix/hystrix.stream) 监控 hystrix dashboard 上的微服务流。我要做的是将微服务hystrix事件流注册到涡轮服务器事件流中。有谁知道如何做到这一点?任何参考资料 link 也会有很大帮助。

更新:项目参考和设置文件配置

myproject.csproj:

<ItemGroup>
  <PackageReference Include="Steeltoe.CircuitBreaker.Hystrix.MetricsEventsCore" Version="3.0.2" />
  <PackageReference Include="Steeltoe.CircuitBreaker.HystrixCore" Version="3.0.2" />
<ItemGroup>

startup.cs:配置服务部分

services.AddMvc(options => options.EnableEndpointRouting = false);
services.AddHystrixCommand<MyCircuitBreakerCommand>("MyCircuitBreakerGroup", Configuration);
services.AddHystrixMetricsStream(Configuration);

startup.cs -> 配置部分

app.UseHystrixRequestContext();
app.UseHystrixMetricsStream();
app.UseMvc();

我也没有修改 program.cs 或任何 .json 设置文件。

最近尝试访问这些微服务资源:/hystrix/config.stream、/hystrix/request.stream 和 /hystrix/utilization.stream,但收到此内部服务器错误:

Connection id "0HM90GL5F64RK", Request id "0HM90GL5F64RK:00000003": An unhandled exception was thrown by the application. System.InvalidOperationException: Unable to resolve service for type 'Steeltoe.CircuitBreaker.Hystrix.Config.HystrixConfigurationStream' while attempting to activate 'Steeltoe.CircuitBreaker.Hystrix.MetricsEvents.Controllers.HystrixConfigStreamController'. at Microsoft.Extensions.DependencyInjection.ActivatorUtilities.GetService(IServiceProvider sp, Type type, Type requiredBy, Boolean isDefaultParameterRequired) at lambda_method(Closure , IServiceProvider , Object[] ) at Microsoft.AspNetCore.Mvc.Controllers.ControllerActivatorProvider.<>c__DisplayClass4_0.b__0(ControllerContext controllerContext) at Microsoft.AspNetCore.Mvc.Controllers.ControllerFactoryProvider.<>c__DisplayClass5_0.g__CreateController|0(ControllerContext controllerContext) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync() --- End of stack trace from previous location where exception was thrown --- at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Awaited|24_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context) at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeFilterPipelineAsync() --- End of stack trace from previous location where exception was thrown --- at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Logged|17_1(ResourceInvoker invoker) at Microsoft.AspNetCore.Builder.RouterMiddleware.Invoke(HttpContext httpContext) at Steeltoe.CircuitBreaker.Hystrix.HystrixRequestContextMiddleware.Invoke(HttpContext context) at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequests[TContext](IHttpApplication`1 application) fail: Microsoft.AspNetCore.Server.Kestrel[13]

此错误消息告诉我们 HystrixConfigurationStream 尚未注册到服务容器。可以在 startup.cs:

中使用此代码添加
services.AddHystrixConfigStream(Configuration);

但我认为更好的选择是将 AddHystrixMetricsStream 复数化为 AddHystrixMonitoringStreams,这也注册了 a couple other things

我个人并没有花很多时间在这段代码上,所以我不知道到底发生了什么,但我已经 filed an issue 了文档,如果有错误,我们应该能够跟进修复。