You're on the right track with regard to the first question. A unary RPC has to have a response, but the response can be empty (which you can check with the appropriate has_ methods) or you can do a oneof. An alternative is to use a server-side streaming return value which allows 0 or more responses
rpc GetPage(PageRequest) returns (stream PageResponse) And that ties in to the 2nd question re Push - that's exactly what streaming is for. You can send your updates back as subsequent responses on the return stream. Hope that helps! @vjpai On Tue, Jun 6, 2017 at 10:48 AM John Coffey <[email protected]> wrote: > I am creating an RPC service and I want to know how I would declare an RPC > method that returns (in my case) an optional response. The way the rpc is > defined below means that it always returns a PageResponse. I suppose I > could check to see if the page_title in the response has not been set but I > am sure that there is a more elegant solution to this (probably a > combination of 'empty' and 'oneof'? > > Also in a somewhat related question, Is it possible to change the rpc to > support some sort of push data? I have a cache managed by a GWService and > I would like the grpc client to act like a listener for updates to this > cache - other than polling for changes, I am not sure how I would do this. > Is that what streaming is for? > > Thanks in advance > > John > > //! Request a page object from the cache > message PageRequest { > string page_title = 1; > } > > //! cache page wrapper > message PageResponse { > // embed the page title in case we decide to stream > // many of these back to back using the streaming API > string page_title = 1; > Page page_data = 2; > } > > > //! Gateway Service. > service GWService { > > . . . > > > // request a specific > rpc GetPage(PageRequest) returns (PageResponse) {} > } > > > -- > 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/4e8ac2d7-2811-4098-af3a-c8ea34cb04bc%40googlegroups.com > <https://groups.google.com/d/msgid/grpc-io/4e8ac2d7-2811-4098-af3a-c8ea34cb04bc%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- 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/CADEy0h3XzKYfj6s%3D0gKzYxAiv4t0CkZ8yqio1moL7X7jHqKL%3DA%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
smime.p7s
Description: S/MIME Cryptographic Signature
