@Override public void start() throws Exception { Router router = Router.router(vertx); // Allow events for the designated addresses in/out of the event bus bridge BridgeOptions opts = new BridgeOptions() .addInboundPermitted(new PermittedOptions().setAddress("chat.message")) .addOutboundPermitted(new PermittedOptions().setAddress("chat.message")); // Create the event bus bridge and add it to the router. SockJSHandler ebHandler = SockJSHandler.create(vertx).bridge(opts); router.route("/eventbus/*").handler(ebHandler); // Create a router endpoint for the static content. router.route().handler(StaticHandler.create()); // Start the web server and tell it to use the router to handle requests. vertx.createHttpServer().requestHandler(router).listen(8080); } }
BridgeOptions options = new BridgeOptions().addOutboundPermitted(new PermittedOptions().setAddress("news-feed")); router.route("/eventbus/*").handler(SockJSHandler.create(vertx).bridge(options, event -> { if (event.type() == BridgeEventType.SOCKET_CREATED) { System.out.println("A socket was created"); event.complete(true);
@Override public void start() throws Exception { // Create the client object MyService service = new MyServiceImpl(); // Register the handler new ServiceBinder(vertx) .setAddress("proxy.example") .register(MyService.class, service); Router router = Router.router(vertx); BridgeOptions options = new BridgeOptions().addInboundPermitted(new PermittedOptions().setAddress("proxy.example")); router.route("/eventbus/*").handler(SockJSHandler.create(vertx).bridge(options)); // Serve the static resources router.route().handler(StaticHandler.create()); vertx.createHttpServer().requestHandler(router).listen(8080); } }
BridgeOptions options = new BridgeOptions(); options.setOutboundPermitted(Collections.singletonList(new PermittedOptions().setAddress("dashboard"))); router.route("/eventbus/*").handler(SockJSHandler.create(vertx).bridge(options));
private void setupSockJsServer(String serverPath, BiConsumer<SockJSSocket, Buffer> serverBufferHandler) { String path = serverPath + "/*"; router.route(path).handler(SockJSHandler.create(vertx) .socketHandler(sock -> { sock.handler(buffer -> serverBufferHandler.accept(sock, buffer)); sock.exceptionHandler(this::fail); })); }
/** * Create a SockJS handler * * @param vertx the Vert.x instance * @return the handler */ static SockJSHandler create(Vertx vertx) { return new SockJSHandlerImpl(vertx, new SockJSHandlerOptions()); }
/** * Close it giving a status code and reason. Only Applicable to RawWebSocket will downgrade to plain close for * other transports. */ default void close(int statusCode, String reason) { close(); }
@Test public void testNotFound() { waitFor(7); testNotFound("/echo/a"); testNotFound("/echo/a.html"); testNotFound("/echo/a/a"); testNotFound("/echo/a/a/"); testNotFound("/echo/a/"); testNotFound("/echo//"); testNotFound("/echo///"); await(); }
@Override public void setUp() throws Exception { numServers = 2; super.setUp(); }
@Override public void start() throws Exception { Router router = Router.router(vertx); // Allow events for the designated addresses in/out of the event bus bridge BridgeOptions opts = new BridgeOptions() .addOutboundPermitted(new PermittedOptions().setAddress("feed")); // Create the event bus bridge and add it to the router. SockJSHandler ebHandler = SockJSHandler.create(vertx).bridge(opts); router.route("/eventbus/*").handler(ebHandler); // Start the web server and tell it to use the router to handle requests. vertx.createHttpServer().requestHandler(router).listen(8080); EventBus eb = vertx.eventBus(); vertx.setPeriodic(1000l, t -> { // Create a timestamp string String timestamp = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM).format(Date.from(Instant.now())); eb.send("feed", new JsonObject().put("now", timestamp)); }); } }
@Override public void start() throws Exception { // Create the client object ProcessorService service = new ProcessorServiceImpl(); // Register the handler new ServiceBinder(vertx) .setAddress("vertx.processor") .register(ProcessorService.class, service); Router router = Router.router(vertx); // Allow events for the designated addresses in/out of the event bus bridge BridgeOptions opts = new BridgeOptions() .addInboundPermitted(new PermittedOptions().setAddress("vertx.processor")) .addOutboundPermitted(new PermittedOptions().setAddress("vertx.processor")); // Create the event bus bridge and add it to the router. SockJSHandler ebHandler = SockJSHandler.create(vertx).bridge(opts); router.route("/eventbus/*").handler(ebHandler); router.route().handler(StaticHandler.create()); // vertx.createHttpServer().requestHandler(router).listen(8080); }
@Override public void setUp() throws Exception { numServers = 2; super.setUp(); }
@Override public void start() throws Exception { Router router = Router.router(vertx); // Allow events for the designated addresses in/out of the event bus bridge BridgeOptions opts = new BridgeOptions() .addInboundPermitted(new PermittedOptions().setAddress("com.example:cmd:poke-server")) .addOutboundPermitted(new PermittedOptions().setAddress("com.example:stat:server-info")); // Create the event bus bridge and add it to the router. SockJSHandler ebHandler = SockJSHandler.create(vertx).bridge(opts); router.route("/eventbus/*").handler(ebHandler); // Create a router endpoint for the static content. router.route().handler(StaticHandler.create()); // Start the web server and tell it to use the router to handle requests. vertx.createHttpServer().requestHandler(router).listen(8080); EventBus eb = vertx.eventBus(); vertx.setPeriodic(1000l, t -> { // Create a timestamp string String timestamp = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM).format(Date.from(Instant.now())); eb.send("com.example:stat:server-info", new JsonObject().put("systemTime", timestamp)); }); } }
@Override public void start() throws Exception { Router router = Router.router(vertx); // Allow events for the designated addresses in/out of the event bus bridge BridgeOptions opts = new BridgeOptions() .addOutboundPermitted(new PermittedOptions().setAddress("feed")); // Create the event bus bridge and add it to the router. SockJSHandler ebHandler = SockJSHandler.create(vertx).bridge(opts); router.route("/eventbus/*").handler(ebHandler); // Create a router endpoint for the static content. router.route().handler(StaticHandler.create()); // Start the web server and tell it to use the router to handle requests. vertx.createHttpServer().requestHandler(router).listen(8080); EventBus eb = vertx.eventBus(); vertx.setPeriodic(1000l, t -> { // Create a timestamp string String timestamp = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM).format(Date.from(Instant.now())); eb.send("feed", new JsonObject().put("now", timestamp)); }); } }
@Override public void start() throws Exception { Router router = Router.router(vertx); // Allow events for the designated addresses in/out of the event bus bridge BridgeOptions opts = new BridgeOptions() .addOutboundPermitted(new PermittedOptions().setAddress("feed")); // Create the event bus bridge and add it to the router. SockJSHandler ebHandler = SockJSHandler.create(vertx).bridge(opts); router.route("/eventbus/*").handler(ebHandler); // Create a router endpoint for the static content. router.route().handler(StaticHandler.create()); // Start the web server and tell it to use the router to handle requests. vertx.createHttpServer().requestHandler(router).listen(8080); EventBus eb = vertx.eventBus(); vertx.setPeriodic(1000l, t -> { // Create a timestamp string String timestamp = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM).format(Date.from(Instant.now())); eb.send("feed", new JsonObject().put("now", timestamp)); }); } }
BridgeOptions opts = new BridgeOptions() .addInboundPermitted(new PermittedOptions().setAddress("chat.to.server")) .addOutboundPermitted(new PermittedOptions().setAddress("chat.to.client")); SockJSHandler ebHandler = SockJSHandler.create(vertx).bridge(opts); router.route("/eventbus/*").handler(ebHandler);
BridgeOptions options = new BridgeOptions(). addOutboundPermitted( new PermittedOptions(). setAddress("metrics") ); router.route("/eventbus/*").handler(SockJSHandler.create(vertx).bridge(options));
BridgeOptions options = new BridgeOptions() .addInboundPermitted(new PermittedOptions() .setAddress("vtoons.listAlbums")) .addInboundPermitted(new PermittedOptions() .setAddress("vtoons.login")) .addInboundPermitted(new PermittedOptions() .setAddress("vtoons.placeOrder") .setRequiredAuthority("place_order")) .addOutboundPermitted(new PermittedOptions()); router.route("/eventbus/*").handler(SockJSHandler.create(vertx).bridge(options));