2

We have a project made in Dropwizard version 2.0.0-RC, where we use REST-endpoints. After some issues we decided to use gRPC instead of using REST. There is a couple of 3rd party libraries to connect gRPC to Dropwizard, but we believe they are a bit outdated and not useable. So we are thinking about implementing Armeria and their GRPC solution.

To implement this, I need the Jetty instance to attach the GRPC.

This is how I can solve it (Mix between GRPC and Armeria):

Server server = Server.builder()
  .http(8080)
  .service(GrpcService.builder()...build())
  .serviceUnder("/", JettyService.forServer(jettyServer))
  .build();
server.start().join();

So I need the jettyServer to be the instance of Jetty with the type of org.eclipse.jetty.server. The rest of the code is Armerias way of embedding Jetty. Link to embedding jetty.

How can I retrieve the instance of Jetty?

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
Sebastian Berglönn
  • 3,920
  • 2
  • 17
  • 33

2 Answers2

2

I was able to solve this by using Dropwizard lifecycles to get the server.

// variable server is of type org.eclipse.jetty.server.Server
environment.lifecycle().addServerLifecycleListener(new ServerLifecycleListener() {
    @Override
    public void serverStarted(Server server) {
      // ....
    }
});

With the instance, you can use Armeria to attach gRPC

Sebastian Berglönn
  • 3,920
  • 2
  • 17
  • 33
  • 1
    If anyone is having similar objective/goal - check the Dropwizard's User Manual and the last topic "Dropwizard Internals". The particular question is covered at the end: https://www.dropwizard.io/en/release-1.3.x/manual/internals.html#jetty-lifecycle – zloster Oct 08 '19 at 09:08
  • Also from architecture/code structure point of view it is better to use extend/replace the ServerFactory implementations. The provided ones are here: https://github.com/dropwizard/dropwizard/tree/master/dropwizard-core/src/main/java/io/dropwizard/server. Here is how another project is achieving the same goal: https://github.com/msteinhoff/dropwizard-grpc/tree/master/src/main/java/io/dropwizard/grpc/server – zloster Oct 08 '19 at 09:08
  • Do you know how that is handled at 2.0.0, @zloster? – Sebastian Berglönn Oct 08 '19 at 10:39
  • 2
    Here is how I've made a quick check. The master branch is the 2.0.x release, the 1.3.x release has it own branch. Compare the two branches about changes in the bootstrap interfaces: https://github.com/dropwizard/dropwizard/commits/master/dropwizard-core/src/main/java/io/dropwizard/server You will see very few and subtle changes there. Also take a look at the wiki: https://github.com/dropwizard/dropwizard/wiki/Upgrade-guide-1.3.x-to-2.0.x I guess the changes there will be reflected also in the docs source at some point: https://github.com/dropwizard/dropwizard/tree/master/docs/source/manual – zloster Oct 09 '19 at 07:53
  • 2
    Also note this: https://github.com/dropwizard/dropwizard/wiki/Upgrade-guide-1.3.x-to-2.0.x#dropwizard-bill-of-materials-bom This will be one of the most visible changes (from a developer perspective). – zloster Oct 09 '19 at 07:55
  • 1
    @zloster Thanks for all the links. I was able to implement this by overriding the ServerFactory – OneCricketeer Oct 31 '19 at 04:29
0

I was able to use the links provided in the comments of the other answer and put this PR together in Armeria project for adding a dropwizard module.

https://github.com/line/armeria/pull/2236

It currently targets 1.3.x rather than 2.0, but once a stable release exists, it'll need upgraded

Edit: PR was accepted and merged

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245