我有一个垂直:
class GatewayVerticle extends GroovyVerticle {
@Override
void start() throws Exception {
EventBus eb = vertx.eventBus()
eb.consumer( 'inbound' ){ Message<String> msg ->
eb.send 'log', "${msg.address()}: ${msg.body()}"
eb.send msg.address(), "echo: ${msg.body()}"
}
def opts = [ ... ] as Map<String,Object>
SockJSHandler sockJSHandler = SockJSHandler.create( vertx ).bridge( opts ){ BridgeEvent event ->
println "event: ${event.type()} -> ${event.rawMessage}"
event.complete true
}
Router router = Router.router vertx
router.route( '/eventbus/*' ).handler sockJSHandler
vertx.createHttpServer().requestHandler( router.&accept ).listen 8811
}
}
我可以在HTML-JS-client中与事件总线通信,所以:
eb = new EventBus( 'http://localhost:8811/eventbus' );
eb.registerHandler(address, function(error, msg) {
console.info( "Address:" + address + " Message:" + msg.body + "<br>");
});
现在,我想使用一个propper ws://localhost:8811/eventbus
,但它失败了......
直接Websocket的技巧只有在我引入另一个处理程序时才有效:
vertx.createHttpServer().websocketHandler( wsHandler ).listen 8822
并且JS工作得很好:
var ws8822 = new WebSocket( 'ws://localhost:8822' );
ws8822.send( JSON.stringify( { text:'KKKKKKK' } ) );
但在这种情况下,我错过了整个事件总线的东西。
是否可以使用本机ws-protocol访问sockJSHandler事件总线上的桥接?