Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vertx event bus access_denied

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

like image 395
Damien Chesneau Avatar asked Sep 06 '25 11:09

Damien Chesneau


1 Answers

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", ...
like image 105
Michael Hopfner Avatar answered Sep 08 '25 01:09

Michael Hopfner