Is hosting a Netty Server inside Tomcat feasible/desirable?

10,772

Solution 1

The dynamic WAR deploying and undeploying that Tomcat provides are designed for web applications. The Netty application you are trying to deploy into Tomcat is not a web application but just a separate server that only shares the VM memory. It means Tomcat has been repurposed into a generic microkernel such as OSGi.

However, I don't think it's a big problem. Since your company uses WAR as the standard deployment mechanism, it might be a good idea to reuse it. You don't even need to write some management functions like remote shutdown because Tomcat already provides them. All you need to do is to make sure all resources are freed up when undeployed.

Some people might not like this approach though. Ideally, there should be a common infrastructure for deploying and managing whatever application (aka microkernel), where even Tomcat is deployed as a module and the microkernel manages WAR directly instead Tomcat does. But that's a long way to go.

Solution 2

It makes terrific sense. We in fact run a Java email server in Tomcat.

Tomcat has some huge advantages for housing an application:

  1. The daemon scripts are already written for you
  2. Tomcat allows hot deployment (so long as you're not using hibernate :) )
  3. At some point you may need either an Admin UI or Admin API
  4. Lots and lots of tools to monitor Tomcat which means free monitoring of your app.

Now with Netty, Mina, or any event driven network technology you will not be able to use most MVC frameworks. In fact you will not be able to use most Java enterprise frameworks because many things rely on a thread per request (transactions, security, etc...).

Solution 3

Do not start anything in Tomcat, it is very inconvenient, and this has a lot of pain issues. Just embed Tomcat (or Jetty) inside your application and run your application as plain java process.

Share:
10,772
ripper234
Author by

ripper234

See blog or LinkedIn Profile

Updated on June 07, 2022

Comments

  • ripper234
    ripper234 almost 2 years

    We building a Netty/NIO based service, and I'm considering the deployment of this service to our production environment. Our standard way of deploying services is as WARs, to be deployed inside Tomcats.

    When I suggested the same approach here, I got shouts and complaints that "it shouldn't be done", because both Netty and Tomcat are servers, and "it doesn't make sense to host one server in another".

    To me it makes perfect sense because it completely solves my deployment issue, as well as saves me from writing some other code. Why is it such a big "no no" ?