Hi there!
We have a project built in Dropwizard, and we are switching from using REST with Jersey to use GRPC instead. Dropwizard uses Jetty, so if I could attach GRPC would be great.
In Dropwizards initialize-method, I wrote like this:
@Override
public void initialize(final Bootstrap<QueryServConfiguration> bootstrap) {
ServerBuilder sb = Server.builder();
sb.service(
GrpcService.builder()
.addService(new HelloService())
.build()
);
sb.serviceUnder("/", new JettyServiceBuilder().build());
}
It builds but I cannot make any requests towards it. Do I have to attach it with a handler, something like this?
Hi @Cronnay!
I'm not a Dropwizard expert, but I guess there are two options here:
Server instance? If so, you could create a JettyService using JettyService.forServer(Server jettyServer).Server instance? If so, please let us know so we can add a Server-getter method to JettyService, so you can configure a JettyService with a handler and provide the Jetty Server to Dropwizard via a method like JettyService.getServer().By the way, please don't forget to build an Armeria server by calling ServerBuilder.build() and to start it by calling Server.start().join(). :wink: (You didn't in the above snippet.)
For example,
// If you are given with a Jetty Server:
Server server = Server.builder()
.http(8080)
.service(GrpcService.builder()...build())
.serviceUnder("/", JettyService.forServer(jettyServer))
.build();
server.start().join();
or
// If you can provide a Jetty Server to Dropwizard:
JettyService jettyService = new JettyServiceBuilder()
...
.build();
Server server = Server.builder()
.http(8080)
.service(GrpcService.builder()...build())
.serviceUnder("/", jettyService)
.build();
server.start().join();
// Pass jettyServer to Dropwizard somehow here.
// Note that getServer() does not exist yet. We can add it if it's needed.
org.eclipse.jetty.server.Server jettyServer = jettyService.getServer();
Not sure this is what you want, but if you are fine with running Jetty and gRPC on different ports, you can just run them separately, i.e. Let Dropwizard run Jetty and Armeria run gRPC:
Server server = Server.builder()
.http(8080)
.service(GrpcService.builder()...build())
.build();
server.start().join();
Thanks for your response, @trustin. I will try to see if I can implement this somehow.
We are currently using REST endpoints - and we are considering if we are able to take some parts of Armeria to complement what we already built. We are no longer in need of REST-server that Dropwizard provides, so we wish to use 1 port. However, if it is too much work to implement this, we might as well change to Armeria and use it entirely.
Great! Please keep us posted about your progress here and let us know if there's anything we can help you. :bow:
Thank you for your help @trustin. it's working now, but I would like to polish it a bit.
I managed to retrieve the instance of Jetty with Dropwizards environemnt and their lifecycles.
Scroll down to bottom for Lifecycles
However, it seems to be using a new port anyway. This is my implementation:
// variable server is of type org.eclipse.jetty.server.Server
environment.lifecycle().addServerLifecycleListener(new ServerLifecycleListener() {
@Override
public void serverStarted(Server server) {
com.linecorp.armeria.server.Server serverBuilder = com.linecorp.armeria.server.Server.builder()
.serviceUnder("/", JettyService.forServer(server))
.service(
GrpcService.builder()
.addService(new HelloService())
.build()
)
.build();
serverBuilder.start().join();
}
});
When I start the server, it creates a new endpoint with a random port, usually something port 40000+. Any clue what this is about?
When you are building Armeria Server, you have to specify the port number using ServerBuilder.http(int) or ServerBuilder.https(int):
Server server = Server.builder()
.http(8080)
...
.build();
I didn't try it by myself, but I guess you'll have two ports open at this point - one that serves only Jetty requests and the other one that's serves both gRPC and Jetty requests. If that's the case, you might want to:
Server before Jetty Server is started.Server by Dropwizard, so that the TCP/IP port opened by Dropwizard is closed, i.e. there's only one port left.Do you know any simplistic Dropwizard server example? If so, I could play with it a little bit and give you better information.
simplistic Dropwizard server example
Here's an archetype generator that starts a minimal project
https://github.com/dropwizard/dropwizard/blob/master/dropwizard-archetypes/README.md
I made a working example at https://github.com/cricket007/dropwizard-armeria#usage
The code is still in the develop branch until I fix and cleanup a few things.
Edit - all code moved to #2236
That is awesome, @cricket007! Would you be interested in sending a pull request here? We keep the examples under /examples and it would be a great addition.
.. and I guess there has to be an armeria-dropwizard module which provides the ArmeriaBundle.
interested in sending a pull request here?
Sure!
module which provides the ArmeriaBundle
It's in the develop branch for now. I copied the module layout based on the GraphQL bundle
Awesome! Looking forward to your pull request, then. :+1:
@Cronnay You can now use Armeria with Dropwizard, thanks to @cricket007 's awesome work. :wink:
This is honestly amazing.
We decided to use something else, but it's great to see that you have implemented it! Will look out Armeria in future. Well done to both of you!
Happy holidays!
We decided to use something else, but it's great to see that you have implemented it! Will look out Armeria in future. Well done to both of you!
Thanks! Would you mind letting us know about which you chose and what made you made that decision, so we know more about our competitors?
Bump? @Cronnay
Hello @cricket007!
I haven't tried this at all. Due to the deadline of our project, we had to change and use something else
Right - the question was around what you had changed to