Hi Stephan,

1: It is indeed very much possible to have multiple methods, you just need
to arrange for your own CallData object that will
handle different methods. Depending on your style you could:
  - Have a enum in the CallData constructor that describe which method is
handled, and switch on that.
  - Use inheritance (have a CallData subclass for each GRPC method).
  - Takes functors that perform the work as arguments.

Then when your server starts you will need to instantiate the first
CallData object for each method.

2: The example is indeed synchronous in its process phase. In real life you
will be offloading work to some thread pool,
or calling async services of your own, and then you can call
responder_->Finish() once that is done.








On Fri, Oct 12, 2018 at 11:40 AM Stephan Menzel <stephan.men...@gmail.com>
wrote:

> Hello group,
>
> I have been using grpc since 0.14, so far with a number of services that
> used C++ as client and server impls. Now I am in the process of
> transitioning those services from sync to async. I am quite familiar with
> async services, mostly using boost asio.
>
> With this in mind, I have looked at the example implementation here:
> https://github.com/grpc/grpc/blob/v1.15.1/examples/cpp/helloworld/greeter_async_server.cc
>
> I have two questions that I would like to get some hints on.
>
> 1) This is my most important issue now. All examples I have seen only use
> one method for their service. I suppose this is a bit of a theoretical
> scenario as most real world use cases would have many. Mine have between 10
> and 30 methods per service.
>
> The way the example does its HandleRrpcs() method it always creates one
> CallData object of fixed type. How can I have more than one? I have tried
> to do a CRTP template base for such calls which then calls an overloaded
> work method but I don't know how I can translate this to the Next() call.
> Also, the way I understand it, each call to service->RequestMyMethod() with
> another method would override the last, right? Or am I supposed to
> call  service->RequestFoo() and service->RequestBar() back to back and let
> the system figure it out? So, is it possible at all to have multiple
> methods?
>
> 2) asio based servers have some kind of mechanism that allows for
> dispatching an async operation and hand in some callback when it's
> completed. For example an asio::io_context object. Looking at your example
> code I can see no equivalent. The example really seems to be synchronous.
> Suppose instead of saying response.set_answer("hello world") my call would
> really involve some blocking operations that I would like to async 'away'.
> Like, in a trivial example, I spawn a thread or something to do the work
> and then wait for a future or some kind of callback. How would that
> translate to grpc?
> Again, looking at the examples the only thing that would come to mind is
> having an actual asio io_context running next to the grpc AsyncService and
> post operations in there, referring to grpc mostly for when the call is
> done. Is that a reasonable approach or am I missing something here?
>
> Thanks for any suggestions,
>
> Stephan
>
> --
> 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+unsubscr...@googlegroups.com.
> To post to this group, send email to grpc-io@googlegroups.com.
> 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/5fab2267-860f-4903-9a13-203d096e531a%40googlegroups.com
> <https://groups.google.com/d/msgid/grpc-io/5fab2267-860f-4903-9a13-203d096e531a%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>


-- 
Christian Rivasseau
Co-founder and CTO @ Lefty <http://www.lefty.io>
+33 6 67 35 26 74

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to grpc-io@googlegroups.com.
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/CAJ6g4%3Da09q4CfsobJ_8mAT8w-tat_fKLuf9iwY_QrxQsAj%2BYmg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to