We are looking at ways to pass trace IDs across RPC calls for Dapper-style tracing. Of course we could add a field to every request proto, but it seems more appropriate to use metadata to avoid cluttering the API. Is that possible?
Many thanks, Alex
Have you tried retrieving metadata from client side?
On Mon, Apr 4, 2016 at 2:59 PM, Tang Weiyu <weiyu...@gmail.com> wrote:Basically I am now setting up a bi-directional stream grpc.This is important - response-streaming RPC methods don't accept a "with_call" keyword argument.What will be the acceptable call format for carrying "call" obj?or if I only pass "True" to the third arg, it errors only 2 args expected.When I pass in the parameters with_call = True, i.e. for data,call in stub.Subscribe(sub_req, _TIMEOUT_SECONDS, with_call=True),
it complains:
Exception: <lambda>() got an unexpected keyword argument 'with_call'
Is the iterator of responses that you got back from the RPC invocation not already a Call object? Does it have "initial_metadata" and "terminal_metadata" methods on it?-N
Definition of rpc:rpc telemetrySubscribe(SubscriptionRequest) returns (stream OpenConfigData) {}
How to get metadata from client side for streaming type of rpc call?
On Mon, Apr 4, 2016 at 5:15 PM, Tang Weiyu <weiyu...@gmail.com> wrote:Thanks Nathaniel, unfortunately the returned response don't have those 2 methods, though I did get the returned response in the form of stream Type defined in proto file RCP.Anything missing here?
for data,call in stub.Subscribe(sub_req, _TIMEOUT_SECONDS):
metadata = data.initial_metadata()
Exception: '_CancellableIterator' object has no attribute 'initial_metadata'
Thanks Nathaniel for help, the version looks like 0.13.0, does that version support metadata?
I just re-ran generated code lib some 5 mins ago, but same failure with latest _pb2.
No diff, I checked. Actually the previous one was generated just about 1 week ago on the same docker machine.
I used below func to generate stub:
def early_adopter_create_Agent_stub(host, port, metadata_transformer=None, secure=False, root_certificates=None, private_key=None, certificate_chain=None, server_host_override=None):
Then I changed the code to use beta func:agent_pb2.beta_create_Agent_stub(grpc_server["ip"], grpc_server["port"]) as stub:But it seems incorrect args passed in, beta_create_stub takes "channel" as first arg.How do I define the channel in this case?
for feature in stub.ListFeatures(rectangle, timeout_in_seconds):How do I understand the streaming concept? does it mean the stream will always up, and in a waiting-data status?stub.ListFeatures(rectangle, timeout_in_seconds) twice seems not right from server perspective. I found out in the cpp version client, it creates a Reader object and you can continuously poll this reader to see if there is new data.
e.g.while (reader->Read(&feature)) { std::cout << "Found feature called " << feature.name() << " at " << feature.location().latitude()/kCoordFactor_ << ", " << feature.location().longitude()/kCoordFactor_ << std::endl; }
So, for python, it seems not the case, how do I do the similar for streaming type RPC?
i.e. call streaming RPC once, get the metadata, then keep checking data buffer and read.
Thanks,
Weiyu
And if I assume the stream is already up and the server sends the data after some time, say 1 second, how do I get the second data?The reason I am asking is, in order to get metadata, I have to first assign RPC call to an iterator varialble, then loop thru this iterator for each data it has.in the example code, it saysAnother question regarding response-streaming RPC:How do I understand the streaming concept? does it mean the stream will always up, and in a waiting-data status?for feature in stub.ListFeatures(rectangle, timeout_in_seconds):
Callingstub.ListFeatures(rectangle, timeout_in_seconds) twice seems not right from server perspective.I found out in the cpp version client, it creates a Reader object and you can continuously poll this reader to see if there is new data.e.g.while (reader->Read(&feature)) { std::cout << "Found feature called " << feature.name() << " at " << feature.location().latitude()/kCoordFactor_ << ", " << feature.location().longitude()/kCoordFactor_ << std::endl; }So, for python, it seems not the case, how do I do the similar for streaming type RPC?
i.e. call streaming RPC once, get the metadata, then keep checking data buffer and read.
so, will the stream be always up between server and client in this case? for example, if the server wants to send data to the client after 5 seconds of sending 5 messages, can the server still use that "stream" to send another 5 msgs and can the same iterator on client still emit those 5 new msgs?
Or, the client has to call the RPC func the second time to get the data?
e.g.My concern is that if I code "for data in itr:" in this example, will the client be able to get the data from server continously, if the server keeps sending data.In order to get the metadata, I have to call itr = stub.Subscribe(request, __TIMEOUT) first, do itr.initial_metadata(), then loop thru the itr for the real data.Basically I am developing a client to "subscribe" a service on a grpc server, when the subscription successes, the server will keep sending data to the client.
data_itr = stub.Subscribe(sub_req, _TIMEOUT_SECONDS) <<<<< does this mean "the client cancelled the RPC"
metadata = data_itr.initial_metadata()
for data in data_itr : <<<<<< will this loop always continues as long as server keeps sending data?
yes, it is possible.client side:metadata = [(b'client', b'foo'), (b'version', b'bar')]response = stub.YourGRPCMessage(request, _TIMEOUT_SECONDS, metadata=metadata)server side:metadata = context.invocation_metadata()metadata_dict = {}for c in metadata:metadata_dict[c.key] = c.value
On Thursday, 3 March 2016 07:30:26 UTC+8, Alex Lamaison wrote:How do you set the request metadata in the client and retrieve it in the server when using Python gRPC?We are looking at ways to pass trace IDs across RPC calls for Dapper-style tracing. Of course we could add a field to every request proto, but it seems more appropriate to use metadata to avoid cluttering the API. Is that possible?
Many thanks, Alex
On Thursday, March 3, 2016 at 3:11:15 PM UTC+11, Angus Ma wrote:yes, it is possible.client side:metadata = [(b'client', b'foo'), (b'version', b'bar')]response = stub.YourGRPCMessage(request, _TIMEOUT_SECONDS, metadata=metadata)server side:metadata = context.invocation_metadata()metadata_dict = {}for c in metadata:metadata_dict[c.key] = c.valueThis seems to have now changed. The metadata now is now simply a list of of tuples.
Is there a reason why this was changed?
-Nathaniel
def wrapper(iterator):
for entry in iterator:
yield entry
class MyInterceptor(grpc.StreamStreamClientInterceptor):
def intercept_stream_stream(self, continuation, client_call_details, request_iterator):
return wrapper(continuation(client_call_details, request_iterator))
On Tue, Apr 5, 2016 at 9:58 AM, Tang Weiyu <weiy...@gmail.com> wrote:Definition of rpc:rpc telemetrySubscribe(SubscriptionRequest) returns (stream OpenConfigData) {}What's important here is that the RPC is response-streaming: it will return zero, or one, or many more responses.
How to get metadata from client side for streaming type of rpc call?
On Mon, Apr 4, 2016 at 5:15 PM, Tang Weiyu <weiy...@gmail.com> wrote:Thanks Nathaniel, unfortunately the returned response don't have those 2 methods, though I did get the returned response in the form of stream Type defined in proto file RCP.Anything missing here?
for data,call in stub.Subscribe(sub_req, _TIMEOUT_SECONDS):
metadata = data.initial_metadata()
--
You received this message because you are subscribed to the Google Groups "grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email to grpc-io+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/grpc-io/e93d5c60-693c-4790-b107-8a851f42df9fo%40googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to grp...@googlegroups.com.