我想在我的Java VertX中部署一个JavaScript Verticle。当然,这不是问题。问题是,我怎样才能给他们回电?
我的Java代码:
Vertx.clusteredVertx(vertxOptions, res ->
{
if (res.succeeded()) {
logger.info("Cluster ready, starting verticle deploy");
/*
* React JS Server Deploy
*/
Future< String > reactVerticleFuture = Future.future();
vertx.executeBlocking(future ->
{
vertx.deployVerticle("dist/server.js", options, deployResult ->
{
if (deployResult.succeeded()) {
future.complete();
} else {
future.fail(deployResult.cause());
}
});
} , reactVerticleFuture.completer());
CompositeFuture.all(..., reactVerticleFuture).setHandler(ar ->
{
/*
* deploy http listener and health endpoint
*/
});
} else {
logger.error(res.cause().getMessage(), res.cause());
}
});
我的服务器.js:
exports.vertxStartAsync = function(startFuture) {
console.log('vertxStartAsync')
var eb = vertx.eventBus()
var consumer = eb.consumer('httpGetWebChannel', function (message) {
})
consumer.completionHandler(function (res, res_err) {
if (res_err == null) {
console.log("The handler registration has reached all nodes");
startFuture.complete()
} else {
console.log("Registration failed!");
startFuture.fail()
}
});
}
当然,我的服务器.js更大,这需要一些时间来启动。在我的集群 Vertx 中,我在启动期间收到一些消息,说有什么东西阻止了我的总线。
我该如何解决这个问题?
谢谢马赛尔
好的,我们找到了一个解决方案(亚历克斯维特 - 感谢您的耐心等待)。
问题是我用 webpack 构建我的服务器.js文件,构建后,导出块位于函数内。
这是有效的解决方案:
webpack.config.js
var WrapperPlugin = require('wrapper-webpack-plugin');
...
plugins: [
new WrapperPlugin({
header: 'exports.vertxStartAsync = function(startFuture) {n',
footer: '}n'
}),
...
]
...
服务器.js
var eb = vertx.eventBus()
var consumer = eb.consumer('httpGetWebChannel', function (message) {
...
})
consumer.completionHandler(function (res, res_err) {
if (res_err == null) {
console.log("The handler registration has reached all nodes");
startFuture.complete()
} else {
console.log("Registration failed!");
startFuture.fail()
}
});
谢谢