如何解决Grpc 服务器端流式keepalive配置
我们有一个在 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,但我不知道应该在哪里设置它。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。