nfultz / grpc

gRPC clients and servers in R
72 stars 24 forks source link

add R hooks, error handling and stuff #20

Closed daroczig closed 5 years ago

daroczig commented 6 years ago

Example run with starting the demo server + 1 run of the demo client:

> library(futile.logger);flog.threshold(TRACE);demo("helloserver", "grpc")
NULL

    demo(helloserver)
    ---- ~~~~~~~~~~~

> #' Example gRPC service
> #'
> #' Reads a message with a name and returns a message greeting the name.
> #' @references \url{https://github.com/grpc/grpc/tree/master/examples/cpp/helloworld}
> 
> library(grpc)

> ## reading the service definitions
> spec <- system.file('examples/helloworld.proto', package = 'grpc')

> impl <- read_services(spec)

> impl$SayHello$f <- function(request){
+   newResponse(message = paste('Hello,', request$name))
+ }

> ## actually running the service handlers
> start_server(impl, "0.0.0.0:50051")
TRACE [2018-08-22 13:30:08] gRPC server created
TRACE [2018-08-22 13:30:08] Completion queue created and registered
DEBUG [2018-08-22 13:30:08] gRPC service will listen on port 50051
TRACE [2018-08-22 13:30:08] gRPC service started on port 50051
INFO [2018-08-22 13:30:08] gRPC service is now listening on port 50051

TRACE [2018-08-22 13:30:13] event received /helloworld.Greeter/SayHello
TRACE [2018-08-22 13:30:13] event processed
TRACE [2018-08-22 13:30:13] event received /helloworld.Greeter/SayHello
TRACE [2018-08-22 13:30:13] event processed
^C
INFO [2018-08-22 13:30:17] gRPC service is going to shut down
DEBUG [2018-08-22 13:30:17] gRPC service stopped

PS the motivation behind this was to be able to run the server with port set to 0 so that gRPC will pick an available port instead of hard-coding it.

daroczig commented 6 years ago

Thanks, @nfultz!

If you need this ASAP you can merge it in, otherwise there's a couple parts I'd like to refactor

No rush with the merge, I'm using my fork/branch.

But I'm a bit worried about the above mentioned error in the client -- probably I'll spend some more time with extra error handling, but could really use some help there if you get a chance.

daroczig commented 6 years ago

^^ hey @nfultz , the above added demo on health check + combining services is not highly related, but I hope you don't mind including it here

nfultz commented 6 years ago

Yeah that looks good too - I probably wouldn't have thought of c()ing two services together, I like that.

nfultz commented 6 years ago

Sorry for the slow turn around, plan is to get this merged on sunday craft day.

daroczig commented 5 years ago

@nfultz this PR is getting our of control a bit :) OK to merge so that I can open actual feature/fix branches from now on? Or should I rather maintain my own dev branch.

nfultz commented 5 years ago

Good call.