vertx初体验之使用vertx3.8.2压缩运行内存及发布包大小

星期四, 2019-10-17 | Author: Lee | JAVA-and-J2EE | 3,631 views

当前vertx版本3.8.2

0.起因,做了一个简单的数据监控收集,要求嘛 当然是快速返回,异步处理收集的数据
用spring boot 是很快做了出来,打包后35M,部署到机器上运行内存占用175M,实际上也不多,奈何我的机器才1C1G,又装了mysql等

1.使用vertx实现功能,降低内存运行时(60M),发布包大小7M

2.可以到 https://start.vertx.io/ 自动创建一个应用很方便

更多官方的示例见 vertx-examples

3.直接main启动应用

public class MainLauncher extends Launcher {
 
	public static void main(String[] args) {
		new MainLauncher().dispatch(new String[] { "run", MainVerticle.class.getName() });
		// startVertx();
	}
 
	public static void startVertx() {
		try {
			Vertx.vertx()
					.deployVerticle(new MainVerticle(),
							new DeploymentOptions().setConfig(new JsonObject(new String(Files.readAllBytes(Paths.get(
									"conf/conf.json"))))));
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}

4.主程序如下

@Override
	public void start(Promise<Void> startPromise) throws Exception {
 
		JsonObject jo = config();
		Router router = Router.router(vertx);
		router.get("/").handler(this::indexHandler);
 
		vertx.createHttpServer().requestHandler(router).listen(jo.getInteger("http.port", 8080), http -> {
			if (http.succeeded()) {
				startPromise.complete();
			} else {
				startPromise.fail(http.cause());
			}
		});
		//aiService = new AiServiceImpl(vertx, jo);
		//aiService.loadDataCache();
	}
 
	private void indexHandler(RoutingContext context) {
		context.response().putHeader("Content-Type", "text/html");
		context.response().end("Hello vip.");
	}

5.打包完成后启动脚本

java -jar AI-1.0.0-fat.jar -conf /config/AI/conf.json &

Tags:

文章作者: Lee

本文地址: https://www.pomelolee.com/1938.html

除非注明,Pomelo Lee文章均为原创,转载请以链接形式标明本文地址

No comments yet.

Leave a comment

Search

相关文章

文章分类

Links

Meta