4.12.11. Sockjs ソケットイベントバスが、デフォルトでクラスターイベントを登録しない
SockJSSocket は、デフォルトでクラスター化されたイベントバスコンシューマーを登録しなくなりました。イベントバスを使用してソケットに書き込む場合は、Sonck JSHandlerOptions で writeHandler を有効にする必要があります。WriteHandler を有効にすると、イベントバスコンシューマーはデフォルトでローカルに設定されます。
Router router = Router.router(vertx);
SockJSHandlerOptions options = new SockJSHandlerOptions()
.setRegisterWriteHandler(true); // enable the event bus consumer registration
SockJSHandler sockJSHandler = SockJSHandler.create(vertx, options);
router.mountSubRouter("/myapp", sockJSHandler.socketHandler(sockJSSocket -> {
// Retrieve the writeHandlerID and store it (For example, in a local map)
String writeHandlerID = sockJSSocket.writeHandlerID();
}));
イベントバスコンシューマーをクラスターに設定できます。
SockJSHandlerOptions options = new SockJSHandlerOptions()
.setRegisterWriteHandler(true) // enable the event bus consumer registration
.setLocalWriteHandler(false) // register a clustered event bus consumer