活跃客户/渠道的grpc数量 [英] grpc number of active clients/channels

查看:81
本文介绍了活跃客户/渠道的grpc数量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在实现一个简单的grpc服务发现.我想做的一件事是跟踪当前有多少客户端正在使用该服务,并且该服务会将其报告给服务注册表. grpc服务器api是否提供此类信息?我在这里遇到了一个类似的问题. https://github.com/grpc/grpc-java/issues/779.

I am implementing a simple grpc service discovery. One of the thing I would like to do is to keep track of how many clients are currently to the service and the service will report that to the service registry. Does grpc server api provide such information? I have come across a somewhat similar question here. https://github.com/grpc/grpc-java/issues/779.

在响应的第1点中,提到要通过流式api跟踪所有传入的rpc.我到底该怎么做?

In point 1 of the response, it was mentioned to keep track of all incoming rpc via streaming api. How exactly do I do that?

这是我要实现的一个示例rpc,RegisterInstance将充当"pinger",服务器将使用etcd的ttl检查服务的活跃性.当注册表中注册了多个相同服务类型时,注册表将使用connected_client确定要发送回客户端的服务IP.我的问题是如何从服务端获取connected_clients?

Here's an example rpc I want to implement, RegisterInstance will act as a "pinger" and server will use etcd's ttl to check liveness of service. And the registry will use the connected_client to determine which service ip to send back to client when there are more than one of the same service type registered on the registry. My issue is how can I obtain connected_clients from the service side?

syntax = "proto3";

package registry_grpc;

service ServiceRegistry{
    rpc GetInstance(ServiceRequest) returns(ServiceInstance) {}
    rpc RegisterInstance(ServiceInstance) returns(ServiceInstance) {}
}


message ServiceRequest{
    string service_type = 1;
}

message ServiceInstance{
    int32 id = 1;
    int32 connected_clients = 2;
    string service_type = 3;
    string host_address = 4;
    int32 port = 5;
}

编辑

我发现可以拦截每个传入的rpc调用.这样,我可以报告例如最后一秒的传入连接数.我猜它可以作为工作量的代理.

edit

I have found that it's possible to intercept every incoming rpc calls. This way I can report for example number of incoming connections in the last second. I guess it can serve as a proxy for workload.

推荐答案

ServerBuilder有一个addTransportFilter(),它允许您安装ServerTransportFilter,在其中创建连接(即传输)时会收到通知,并且终止.

ServerBuilder has a addTransportFilter(), which allows you to install a ServerTransportFilter, where you get notifications when a connection (i.e. transport) is created and terminated.

这篇关于活跃客户/渠道的grpc数量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆