use of com.szmirren.vxApi.core.options.VxApiApplicationOptions in project VX-API-Gateway by EliMirren.
the class VxApiApplication method start.
@Override
public void start(Future<Void> startFuture) throws Exception {
try {
if (LOG.isDebugEnabled()) {
LOG.debug("加载应用配置信息...");
}
thisVertxName = System.getProperty("thisVertxName", "VX-API");
VxApiApplicationDTO app = VxApiApplicationDTO.fromJson(config().getJsonObject("appConfig"));
this.appOption = new VxApiApplicationOptions(app);
appName = appOption.getAppName();
this.serverOptions = appOption.getServerOptions();
if (LOG.isDebugEnabled()) {
LOG.debug("加载全局黑名单");
}
config().getJsonArray("blackIpSet").forEach(ip -> {
if (ip instanceof String) {
blackIpSet.add(ip.toString());
}
});
if (LOG.isDebugEnabled()) {
LOG.debug("加载跨域处理信息");
}
this.corsOptions = appOption.getCorsOptions();
if (appOption == null) {
LOG.error("创建应用程序-->失败:配置信息为空");
startFuture.fail("创建应用程序失败:配置信息为空");
return;
} else {
this.httpClient = vertx.createHttpClient(appOption);
Future<Void> httpFuture = Future.future(future -> {
createHttpServer(res -> {
if (res.succeeded()) {
if (LOG.isDebugEnabled()) {
LOG.debug("实例化应用程序->创建HTTP服务器-->成功!");
}
future.complete();
} else {
LOG.error("实例化应用程序->创建HTTP服务器-->失败:" + res.cause());
future.fail(res.cause());
}
});
});
Future<Void> httpsFuture = Future.future(futrue -> {
createHttpsServer(res -> {
if (res.succeeded()) {
if (LOG.isDebugEnabled()) {
LOG.debug("实例化应用程序->创建HTTPS服务器-->成功!");
}
futrue.complete();
} else {
LOG.error("实例化应用程序->创建HTTPS服务器-->失败:" + res.cause());
futrue.fail(res.cause());
}
});
});
Future<Void> eventFutrue = Future.future(future -> {
// 注册操作地址
vertx.eventBus().consumer(thisVertxName + appOption.getAppName() + VxApiEventBusAddressConstant.APPLICATION_ADD_API_SUFFIX, this::addRoute);
vertx.eventBus().consumer(thisVertxName + appOption.getAppName() + VxApiEventBusAddressConstant.APPLICATION_DEL_API_SUFFIX, this::delRoute);
vertx.eventBus().consumer(VxApiEventBusAddressConstant.SYSTEM_PUBLISH_BLACK_IP_LIST, this::updateIpBlackList);
future.complete();
});
CompositeFuture.all(httpFuture, httpsFuture, eventFutrue).setHandler(res -> {
if (res.succeeded()) {
LOG.info("实例化应用程序-->成功");
startFuture.complete();
} else {
LOG.error("实例化应用程序-->失败:", res.cause());
startFuture.fail(res.cause());
}
});
}
} catch (Exception e) {
LOG.error("实例化应用程序-->失败:", e);
startFuture.fail(e);
}
}
Aggregations