Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Grpc support #413

Closed
paualarco opened this issue Nov 5, 2020 · 5 comments
Closed

Grpc support #413

paualarco opened this issue Nov 5, 2020 · 5 comments

Comments

@paualarco
Copy link

Hello,

Thanks for creating this project, is great!

Wanted to know if the plugin also supports grpc.

And in case it does, would additional configuration be needed? (I can not see any references on the docs)

@earldouglas
Copy link
Owner

gRPC support is outside the scope of xsbt-web-plugin, and would depend on the choice of servlet container. Out of the box, xsbt-web-plugin has support for Jetty 9 and Tomcat 9. Neither of these support gRPC as far as I know.

Do you know if any servlet containers currently support gRPC? If so, you can find instructions for using a different servlet container here.

@paualarco
Copy link
Author

It seems like gRPC should be supported on tomcat, see grpc/grpc-java#6933 and grpc/grpc-java#4738.
They are using java/spring, not sure if that would apply scala too :S

@paualarco
Copy link
Author

paualarco commented Nov 6, 2020

Good news! Made it to deploy the grpc server in tomcat.

The way I have done it is by starting it asyncronously under the main class:

class MyServlet extends HttpServlet {
  Future(GrpcServer.start())
  override def doGet(req: HttpServletRequest, res: HttpServletResponse) {
    val responseBody: String =
      """|<html>
         |  <body>
         |    <h1>Hello, world!</h1>
         |  </body>
         |</html>""".stripMargin
    res.getWriter.write(responseBody)
  }
}

However, the grpc server only starts after the first http call (when the httpserverlet is created), but ideally it would initialise at the same time as the tomcat server does.

Do you know if there is a good way of achieving that?

@earldouglas
Copy link
Owner

Oh cool! Nice work getting this going. Are you using the bundled container, or a custom/later one?

To get the gRPC server to start, you need the container to eagerly instantiate your MyServlet, so that the Future(GrpcServer.start()) line will run during its construction. To do this, just add a <load-on-startup> element to the <servlet> element in web.xml:

<servlet>
  <servlet-name>MyServlet</servlet-name>
  <servlet-class>com.example.MyServlet</servlet-class>
  <load-on-startup>1</load-on-startup>
</servlet>

@paualarco
Copy link
Author

Awesome! Thanks :D
I am using the Tomcat one

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

No branches or pull requests

2 participants