提问人:Valery Yegorov 提问时间:5/15/2021 最后编辑:jpsValery Yegorov 更新时间:5/15/2021 访问量:825
Grpc 服务器端流式处理 keepalive 配置
Grpc Server-side streaming keepalive configuring
问:
我们在 c# .net 5.0 环境上实现了一个 Grpc 服务器
public void ConfigureServices(IServiceCollection services)
{
...
services.AddGrpc(o =>
{
o.EnableDetailedErrors = true;
// Small performance benefit to not add catch-all routes to handle UNIMPLEMENTED for unknown services
o.IgnoreUnknownServices = true;
o.Interceptors.Add<CustomInterceptor>();
});
...
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IServiceProvider container, IHostApplicationLifetime lifetime)
{
...
app.UseEndpoints(endpoints =>
{
endpoints.MapGrpcService<GreeterService>();
endpoints.MapGet("/", async context =>
{
await context.Response.WriteAsync("Communication with gRPC endpoints must be made through a gRPC client. To learn how to create a client, visit: https://go.microsoft.com/fwlink/?linkid=2086909");
});
});
...
}
我们使用服务器端流连接来发送客户端通知
public override async Task Start(ConnectorRequest request, IServerStreamWriter<ClientNotification> clientStream,
ServerCallContext serverCallContext)
{
WaitHandle.WaitAny(new[] { context.CancellationToken.WaitHandle });
}
在移动平台上实现的客户端。 经过测试,我们发现当客户端失去连接(例如关闭wifi)时,我们没有任何异常或通知。
如何配置服务器以在客户端失去连接时断开流连接。可能类似于keep_alive设置。 我找到了 https://github.com/grpc/grpc/blob/master/doc/keepalive.md 但我不知道我应该在哪里设置它。
答: 暂无答案
评论