问题描述
我需要部署到仅支持Tomcat容器并且还想将Vert.x作为异步框架运行的PaaS(HANA云平台).
I need to deploy to a PaaS (HANA Cloud Platform) that only supports a Tomcat container and also want to run Vert.x as an async framework.
到目前为止,我所做的是通过servlet引导Vert.x:
What I did so far is to bootstrap Vert.x through a servlet:
public class VertxServlet extends HttpServlet {
...
@Override
public void init(ServletConfig cfg) {
Vertx vertx = Vertx.vertx();
vertx.createHttpServer().requestHandler(new Handler<HttpServerRequest>() {
public void handle(HttpServerRequest req) {
System.out.println("Got request: " + req.uri());
System.out.println("Headers are: ");
for (Map.Entry<String, String> entry : req.headers()) {
System.out.println(entry.getKey() + ":" + entry.getValue());
}
req.response().headers().set("Content-Type", "text/html; charset=UTF-8");
req.response().end("<html><body><h1>Hello from vert.x!</h1></body></html>");
}
}).listen(8888);
}
...
}
然后在我的web.xml中输入:
And in my web.xml I put this:
<servlet>
<servlet-name>VertxServlet</servlet-name>
<display-name>VertxServlet</display-name>
<description></description>
<servlet-class>com.mypackage.VertxServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
效果很好.问题是PaaS无法配置端口映射.包括反向代理在内的整个Tomcat是一个准备好的解决方案.
It works quite well. The problem is that the PaaS is not able to configure the port mapping. The whole Tomcat including the reverse proxy is a prepared solution.
问题:
-
将Vert.x作为
.war
文件运行是否可行?有什么局限性和以后可能会遇到的困难?
Is it a viable approach to run Vert.x as a
.war
file or does ithave any limitations and difficulties that may occur later?
是否可以将我的小型Vert.x服务器绑定到默认的Tomcat端口,而不会发生端口冲突?
Is there a way of binding my little Vert.x server to the default Tomcat port without running into a port conflict?
谢谢
推荐答案
我找到了解决方案.有一个HTTP代理Servlet,您可以在其中轻松地将HTTP请求转发到Vert.x套接字: https://github.com/mitre/HTTP-Proxy-Servlet 对于HTTP来说效果很好.
I have found a solution. There's a HTTP Proxy Servlet where you can easily forward HTTP requests to the Vert.x socket: https://github.com/mitre/HTTP-Proxy-Servlet It works well for HTTP.
不幸的是,此解决方案不支持Web套接字.
But this solution does not support web sockets, unfortunately.
这篇关于在Tomcat上部署Vert.x的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!