I have an java vertx server and a JavaScript client. I want to create an event bus under twice but vertx respond : Error received on connection: access_denied
Javascript code:
var eventBus = new vertx.EventBus("http://localhost:8989/eventbus");
eventBus.onopen = function () {
console.log("Event bus connected !");
console.log(eventBus);
eventBus.registerHandler("http://localhost:8989/eventbus/news-feed", function (message) {
console.log("registred" + message.body());
});
Java code:
SockJSHandler bridge = SockJSHandler.create(vertx).bridge(new BridgeOptions());
router.route("/eventbus/*").handler(bridge);
router.route().handler(StaticHandler.create());// otherwise serve static pages
HttpServer httpServer = vertx.createHttpServer();
httpServer.requestHandler(router::accept);
httpServer.listen(Servers.SERVER_PORT);
vertx.setPeriodic(1000, event -> {
vertx.eventBus().publish("news-feed", "{\"c\":\"df\"}");
Have you an idea?
Regards
You need to set Permissions in the BridgeOptions:
BridgeOptions options = new BridgeOptions()
.addInboundPermitted(new PermittedOptions().setAddress("news-feed"))
.addOutboundPermitted(new PermittedOptions().setAddress("news-feed"));
Also, your Javascript code can't sign up for the whole address:
eventBus.registerHandler("news-feed", ...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With