Not sure if this is still a question... i had a similar requirement and here's how a solution that am planning to use..
https://github.com/itisbsg/grpc-push-notif On Friday, July 29, 2016 at 10:02:49 AM UTC-7, Mosca, Federico wrote: > > What is not so clear is if after the client call stub.message the server > only 'reply' to that using the stream response and nothing else, is it > correct? > Sever can not start a new exchanges of request/response to the client, > right? > What we would like to do is: > -client invoke the rpc (there is no other way I understood) > -server ask something to the client > -client do something somewhere else and return result to the server > Is it doable? > > Thanks > > Sorry for brevity and typos > Sent from iPhone > > Il giorno 29 lug 2016, alle ore 18:31, Nathaniel Manista < > [email protected] <javascript:>> ha scritto: > > On Fri, Jul 29, 2016 at 5:24 AM, Mosca, Federico <[email protected] > <javascript:>> wrote: > >> Hi, so do you suggest to do this: >> >> client.py >> >> *import *grpc >> *import *generated.bidirectional_pb2 *as *bid >> >> >> >> *def *run(): >> channel = grpc.insecure_channel(*'localhost:50051'*) >> stub = bid.SpeakStub(channel) >> >> > Constructing a channel and a stub aren't enough to exchange messages; you > must also invoke an RPC. From your .proto like the way to do that will be > to add "my_response_iterator = stub.Message(<your iterator of request > messages>)" to this client-side code (and then additional code doing > whatever it is that you want to do with the responses that you receive). If > you don't need to ever send any request messages, something like "iter(())" > would be fine for <your iterator of request messages>. > > *if *__name__ == *'__main__'*: >> run() >> >> >> >> server.py >> >> *def *serve(): >> server = grpc.server(futures.ThreadPoolExecutor(max_workers=10)) >> bid.add_SpeakServicer_to_server(bid.SpeakServicer(),server) >> server.add_insecure_port(*'[::]:50051'*) >> server.start() >> *print * >> *"[SERVER] start at 50051" **try*: >> *while *True: >> time.sleep(_ONE_DAY_IN_SECONDS) >> *except *KeyboardInterrupt: >> server.stop(0) >> >> *if *__name__ == *'__main__'*: >> serve() >> >> >> >> but I don’t get where I should implement the servicer >> SpeakServicer(bid.BetaSpeakServicer) and how to invoke it for be that the >> server send the message to the client. >> >> bidirectional_pb2.SpeakServicer is a do-nothing class that has an > implementation of the Message method that raises NotImplementedError > (right?). What we intend is for you to subclass > bidirectional_pb2.SpeakServicer and override its implementation of the > Message method with an implementation that does whatever you wish it to do. > Then rather than instantiating bidirectional_pb2.SpeakServicer and passing > that object to add_SpeakServicer_to_server, pass an instance of your > subclass to add_SpeakServicer_to_server. > >> Where the proto file is >> >> service Speak { >> >> rpc Message(stream Request) returns (stream Response){} >> >> } >> >> Can you help me? >> >> I hope I have; please feel welcome to ask more! > -Nathaniel > > -- 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 [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/grpc-io. To view this discussion on the web visit https://groups.google.com/d/msgid/grpc-io/059234b4-0ee5-4999-81ee-42db68885845%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
