Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

grpcRuntime abstraction and Scala.Js interop #451

Closed
andreaTP opened this issue May 30, 2018 · 15 comments
Closed

grpcRuntime abstraction and Scala.Js interop #451

andreaTP opened this issue May 30, 2018 · 15 comments

Comments

@andreaTP
Copy link
Contributor

I'm opening this issue to have early feedback and keep in sync.
The basic idea is to have a common ground for seamless interoperability between Scala/Scala.Js GRPC services.
What I wish to work on in the future is a port of https://github.com/akka/akka-grpc to Akka.Js.

Today I've played around this:
https://github.com/andreaTP/grpc-interop-poc
The repo simply shows that it's feasible to work on a SJS implementation of the runtime.

I've used the official implementation for Node, but possibly one would like to have one based on https://github.com/improbable-eng/grpc-web

Now, I would like to understand how can we proceed and if this is a contribution that can be considered.

I think steps are:

  • idiomatic SJS facade for GRPC (external library)
  • code refactoring and generalization
  • integration in the code generator

One missing bit is the handling of streams, actually I haven't dig to understand if it's supported or not and what are the plans in case of "no"....

cc. @raboof

@thesamet
Copy link
Contributor

@andreaTP yes, it's definitely something that we can consider adding. As you start hacking on this it would be helpful if you add more details on top of what you provided above: what refactoring/generalizations would be needed on the runtime, and what type of changes would be needed for the code generator?

@raboof
Copy link
Contributor

raboof commented May 30, 2018

To give a bit of background akka-grpc uses scalapb for code generation of the Scala 'model' classes, but not for the gRPC service API's, because there we want to use akka-stream-specific data types (Sources, mainly).

Obviously it would be cool to have this available for Scala.JS users as well, but I'm not too familiar with what that would entail.

@andreaTP
Copy link
Contributor Author

andreaTP commented Jun 1, 2018

@thesamet sure, sorry for the delay, basically what I did is simply providing manually an implementation of the code that needs to be generated: https://github.com/andreaTP/grpc-interop-poc/blob/master/server-js/src/main/scala/com/example/protos/hello/GreeterGrpc.scala#L23

The implementation is now really poor, we would need proper marshalling/unmarshalling at first.
I will try to go ahead on this topic.

@thesamet what's the current status of streaming support?

@thesamet
Copy link
Contributor

thesamet commented Jun 1, 2018

Thanks for the explanation. scalapb-grpc supports streaming.

@thesamet
Copy link
Contributor

thesamet commented Jun 1, 2018

BTW, if you need a way to convert your message to json in ScalaJS, check the various projects under https://github.com/scalapb-json

@andreaTP
Copy link
Contributor Author

andreaTP commented Jun 1, 2018

thanks for pointing it out! 👍 I'll have a look soon.

@andreaTP
Copy link
Contributor Author

andreaTP commented Jun 7, 2018

ok, now I have a more clear idea of what needs to be done, I should provide an alternative implementation of:
https://github.com/scalapb/ScalaPB/blob/master/compiler-plugin/src/main/scala/scalapb/compiler/GrpcServicePrinter.scala

that rely on something like: https://github.com/andreaTP/grpc-sjs/blob/master/src/test/scala/GrpcTest.scala#L20

and at least at first will rely on Proto/Json converter as you suggested.

Any guidance on how to provide an alternative implementation that is platform specific? Is there already a mechanism or it should be implemented?

thanks @thesamet

@thesamet
Copy link
Contributor

thesamet commented Jun 7, 2018

Any guidance on how to provide an alternative implementation that is platform specific? Is there already a mechanism or it should be implemented?

If you want the code generator to produce different code for ScalaJS grpc servers, I would suggest adding a new generator. Maybe this would involve refactoring the existing code so it is reusable.

If you want to have a JS runtime with a different implementation than the JVM runtime, take a look at how it's done to the runtime project in this repository.

Also, I wonder if the new generator and runtime functions can be shipped in a separate library (even if it's hosted in this repo)?

@thesamet
Copy link
Contributor

thesamet commented Sep 7, 2018

@andreaTP Is this issue still being worked on? Let me know if this is not a priority anymore and in that case, we can just close this ticket.

@andreaTP
Copy link
Contributor Author

andreaTP commented Sep 7, 2018

@thesamet I'm still busy for a couple of weeks, but I'm interested into going ahead on this later on, as per the issue itself, feel free to keep it open or close it as you prefer.

@thesamet
Copy link
Contributor

thesamet commented Sep 7, 2018

Thanks for the update, @andreaTP . I'll close for now, and I would be happy to reopen this once you are able to continue to work on this. Feel free to reach out any time here or over gitter.

@thesamet thesamet closed this as completed Sep 7, 2018
@thesamet thesamet reopened this Sep 21, 2018
@thesamet
Copy link
Contributor

Update, I was intrigued enough to play with grpc-web a little bit, and got a POC of this working. I might be able to publish some experimental support for this soon.

@thesamet
Copy link
Contributor

Check out https://github.com/scalapb/scalapb-grpcweb

If you add scalapb-grpcweb to your Scala.js project you should be able to make web-grpc code using the client that is generated by ScalaPB's default gRPC code generator.

@andreaTP
Copy link
Contributor Author

Wow, I will give it a spin soon!

@thesamet
Copy link
Contributor

Now that we've got scalapb-grpcweb working, I'm considering this issue resolved.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants