square / wire

gRPC and protocol buffers for Android, Kotlin, Swift and Java.
https://square.github.io/wire/
Apache License 2.0
4.26k stars 571 forks source link

grpc: use ServiceServer generated stubs out of cashapp/misk #1814

Open mgenov opened 4 years ago

mgenov commented 4 years ago

Is it possible ServiceServer generated stubs to be used out of cashapp/misk?

As I looked into examples, they are using cashapp/misk which is using internally WebActionsServlet to dispatch gRPC calls to the proper method of the service stub.

oldergod commented 4 years ago

We added a few helper methods to help building fakes in 3.4.

See https://github.com/square/wire/blob/master/wire-library/wire-grpc-client/src/jvmMain/kotlin/com/squareup/wire/GrpcCalls.kt

swankjesse commented 4 years ago

Yep. Here's help:

https://github.com/square/wire/blob/master/wire-library/docs/wire_grpc.md#implementing-client-interfaces

swankjesse commented 4 years ago

Or is this request about using Wire on a different server framework?

mgenov commented 4 years ago

Yes, using wire with different server framework.

My current issue is that I have a kotlin backend that is using sparkjava for REST and I'm trying to expose some of it's existing REST services as gRPC ones.

Other ideas for similar transition are also welcome.

swankjesse commented 4 years ago

@mgenov can you fork the gRPC servlet code from Misk in your application? It's almost a standard servlet with one exception; we need to configure this in Jetty:

https://github.com/cashapp/misk/blob/c7e51cbb1ff6947f17839b6cb21c797c8d397593/misk/src/main/kotlin/misk/web/jetty/JettyService.kt#L335

Unfortunately it's likely necessary to configure this into each Java web framework independently, or to build a single servlet that doesn't hook into those frameworks’ authentication, management, and observability systems.

mgenov commented 4 years ago

Thanks @swankjesse . I'll look into it.

In grpc-java the API is really simple and the gRPC services could be served directly using usePlainText without any complexity. I know that it's a security issue, but envoy could do the SSL offloading which could simplify the application code. What I saw in misk is that WebConfig.ssl is used when starting jetty and I suppose jetty is doing the SSL stuff on it's own but I'll take a deeper look into it.

Here is an example API with grpc-java

  val gRpcServer = ServerBuilder.forPort(50051)
            .addService(MyService())
            .intercept(InternalServerSecurityInterceptor())
            .build()
  gRpcServer.start()

with grpc-java client code is able to pass service implementations and interceptors (security checks and etc).

iTanChi commented 3 years ago

is it possible to have an adapter to map wire Service to io.grpc BindableService?

swava29 commented 3 years ago

So did it go thru

On Mon, Nov 30, 2020, 9:54 PM iTanChi notifications@github.com wrote:

is it possible to have an adapter to map wire Service to io.grpc BindableService?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/square/wire/issues/1814#issuecomment-736183571, or unsubscribe https://github.com/notifications/unsubscribe-auth/AR26MFDNOBEQQGONS3HDYU3SSRLGHANCNFSM4SAAVCUQ .

swankjesse commented 3 years ago

@iTanChi nothing built in but you could create one.

iTanChi commented 3 years ago

@mgenov @swankjesse with the latest version, can it resolve this issue:

Code generation for plain gRPC server. The Kotlin target now has a new grpcServerCompatible option which if set to true will generate gRPC server-compatible classes.

RdeWilde commented 3 years ago

@iTanChi Thank you for referencing this, I was looking for exactly that.

Only thing is that the output has an error for me:

  public abstract class GreeterImplBase : BindableService {
    public open fun sayHello(request: HelloRequest, response: StreamObserver<HelloReply>) = throw
        UnsupportedOperationException()

Producing this error:

'Nothing' return type needs to be specified explicitly

Any clue how to solve this?

Also seems to lack a class like GreetersayHelloBlockingServer

Edit; I decided to open another issue for this #1903 I'll leave this for reference.