2015-12-21 101 views
3

我有一個Java vertx服務器和一個JavaScript客戶端。我想下兩次,但vertx響應創建事件總線:連接上收到的錯誤:ACCESS_DENIEDVertx事件總線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\"}"); 

你有一個想法?

問候

回答

1

你需要設置在BridgeOptions權限:

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

而且,你的JavaScript代碼不能註冊爲整個地址:

eventBus.registerHandler("news-feed", ... 
0
.addOutboundPermitted(new PermittedOptions().setAddress("news-feed")); 

是必需的,並且

eb.registerHandler('news-feed', function(error, message) { 
     console.log('received a message: ' + JSON.stringify(message));}); 

回調函數有兩個參數是必需的