我想在我的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());
}
});
我的server.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()
}
});
}
当然,我的server.js更大,这需要一些时间来启动。在我的群集Vertx中,我在启动过程中得到一些阻止我的总线的消息。
我该如何解决这个问题?
由于 烫发
答案 0 :(得分:1)
好的,我们找到了解决方案(alexvetter - 感谢您的耐心等待)。
问题是我用webpack构建我的server.js文件,在构建之后,exports块在一个函数内。
这是可行的解决方案:
webpack.config.js
var WrapperPlugin = require('wrapper-webpack-plugin');
...
plugins: [
new WrapperPlugin({
header: 'exports.vertxStartAsync = function(startFuture) {\n',
footer: '}\n'
}),
...
]
...
server.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()
}
});
由于