gpt4 book ai didi

javascript - Vertx 事件总线 access_denied

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:16:40 26 4
gpt4 key购买 nike

我有一个 java vertx 服务器和一个 JavaScript 客户端。我想在两次下创建一个事件总线,但 vertx 响应:连接时收到错误:access_denied

Javascript 代码:

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代码:

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\"}");

你有想法吗?

问候

最佳答案

您需要在 BridgeOptions 中设置权限:

BridgeOptions options = new BridgeOptions()
.addInboundPermitted(new PermittedOptions().setAddress("news-feed"))
.addOutboundPermitted(new PermittedOptions().setAddress("news-feed"));

还有,你的Javascript代码不能注册整个地址:

eventBus.registerHandler("news-feed", ...

关于javascript - Vertx 事件总线 access_denied,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34392620/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com