@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 { 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)); }); } }
@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); } }
.addInboundPermitted(new PermittedOptions().setAddress("chat.to.server")) .addOutboundPermitted(new PermittedOptions().setAddress("chat.to.client"));
options.setOutboundPermitted(Collections.singletonList(new PermittedOptions().setAddress("dashboard"))); router.route("/eventbus/*").handler(SockJSHandler.create(vertx).bridge(options));
BridgeOptions options = new BridgeOptions().addOutboundPermitted(new PermittedOptions().setAddress("news-feed"));
new PermittedOptions(). setAddress("metrics") );
.addInboundPermitted(new PermittedOptions() .setAddress("vtoons.listAlbums")) .addInboundPermitted(new PermittedOptions() .setAddress("vtoons.login")) .addInboundPermitted(new PermittedOptions() .setAddress("vtoons.placeOrder") .setRequiredAuthority("place_order")) .addOutboundPermitted(new PermittedOptions());
BridgeOptions options = new BridgeOptions() .addInboundPermitted(new PermittedOptions().setAddress("news-feed")) .addOutboundPermitted(new PermittedOptions().setAddress("news-feed"));
@Override public void start() throws Exception { /* test service */ final TestService testService = new TestService(); /* address */ final String address = "testservice"; /* service builder */ final ServiceBuilder serviceBuilder = ServiceBuilder.serviceBuilder(); serviceBuilder.setServiceObject(testService); final ServiceQueue serviceQueue = serviceBuilder.build(); /* vertx event bus bridge to qbit. */ final VertxEventBusBridgeBuilder vertxEventBusBridgeBuilder = VertxEventBusBridgeBuilder .vertxEventBusBridgeBuilder() .setVertx(vertx); vertxEventBusBridgeBuilder.addBridgeAddress(address, TestService.class); final Router router = Router.router(vertx); router.route("/health/").handler(routingContext -> routingContext.response().end("\"ok\"")); /* Configure bridge at this HTTP/WebSocket URI. */ router.route("/eventbus/*").handler(SockJSHandler.create(vertx).bridge( new BridgeOptions() .addInboundPermitted(new PermittedOptions().setAddress(address)) .addOutboundPermitted(new PermittedOptions().setAddress(address)) )); vertxEventBusBridgeBuilder.setServiceQueue(serviceQueue); serviceQueue.startAll(); //startall not supported yet for bridge. vertxEventBusBridgeBuilder.build(); vertx.createHttpServer().requestHandler(router::accept).listen(8080); System.out.println("Bound to 8080"); }
private void addInboundPermitted(BridgeOptions bridgeOptions, JsonObject inbound) { PermittedOptions permittedOptions=new PermittedOptions(); permittedOptions.setAddress(inbound.getString(ADDRESS)); String authority=inbound.getString(REQUIRED_AUTHORITY, EMPTY_CSRF_SECRET); if(!authority.isEmpty()) permittedOptions.setRequiredAuthority(authority); bridgeOptions.addInboundPermitted(permittedOptions); }
private void addOutboundPermitted(BridgeOptions bridgeOptions, JsonObject outbound) { PermittedOptions permittedOptions=new PermittedOptions(); permittedOptions.setAddress(outbound.getString(ADDRESS)); String authority=outbound.getString(REQUIRED_AUTHORITY, EMPTY_CSRF_SECRET); if(!authority.isEmpty()) permittedOptions.setRequiredAuthority(authority); bridgeOptions.addOutboundPermitted(permittedOptions); }
Router router = Router.router(vertx); vertx.createHttpServer().requestHandler(router::accept).listen(8080); BridgeOptions options = new BridgeOptions(); options.addInboundPermitted(new PermittedOptions().setAddress("client-to-server")); options.addOutboundPermitted(new PermittedOptions().setAddress("server-to-client")); SockJSHandler sockJSHandler = SockJSHandler.create(vertx).bridge(options); router.route("/loginUrl/*").handler(sockJSHandler); EventBus eb = vertx.eventBus(); eb.consumer("client-to-server").handler( sockJSHand -> { System.out.println("Sending Message "+ sockJSHand.body());//It prints the message from client eb.publish("server-to-client", "Message"); } );
/** * Configures and binds the SockJS bridge to an HttpServer. * * @param router router */ public void install(Router router) { BridgeOptions bridgeOptions = new BridgeOptions() .addOutboundPermitted(new PermittedOptions().setAddressRegex(addressPrefix + "(.*)")); if (eventbusBridgePingInterval != null) { bridgeOptions = bridgeOptions.setPingTimeout(eventbusBridgePingInterval); } router.route(sockPath).handler(SockJSHandler.create(vertx).bridge(bridgeOptions)); log.info("Installed SockJS endpoint on " + sockPath); log.info("Listening to requests on " + adressPathPattern.pattern()); log.info("Using address prefix " + addressPrefix); }
private void initWebSocket() { Router router = Router.router(vertx); SockJSHandlerOptions options = new SockJSHandlerOptions() .setHeartbeatInterval(1000 * 60); SockJSHandler sockJSHandler = SockJSHandler.create(vertx, options); PermittedOptions inboundPermitted = new PermittedOptions().setAddressRegex("server/.*"); PermittedOptions outboundPermitted = new PermittedOptions().setAddressRegex("client/.*"); BridgeOptions ops = new BridgeOptions() .addInboundPermitted(inboundPermitted) .addOutboundPermitted(outboundPermitted); sockJSHandler.bridge(ops); router.route("/eb/*").handler(sockJSHandler); mainRouter.mountSubRouter("/ws", router); }
@Override public Completable preRoute() { return Completable.defer(() -> { AppGlobals globals = AppGlobals.get(); SockJSHandler sockJSHandler = SockJSHandler.create(globals.getVertx()); BridgeOptions bridgeOptions = new BridgeOptions() .addInboundPermitted(new PermittedOptions().setAddress("app.markdown")) .addOutboundPermitted(new PermittedOptions().setAddress("page.saved")); sockJSHandler.bridge(bridgeOptions); globals.getRouter().route("/eventbus/*").handler(sockJSHandler); return super.preRoute(); }); } });
@Override public Completable preRoute() { return Completable.defer(() -> { AppGlobals globals = AppGlobals.get(); SockJSHandler sockJSHandler = SockJSHandler.create(globals.getVertx()); BridgeOptions bridgeOptions = new BridgeOptions() .addInboundPermitted(new PermittedOptions().setAddress("app.markdown")) .addOutboundPermitted(new PermittedOptions().setAddress("page.saved")); sockJSHandler.bridge(bridgeOptions); globals.getRouter().route("/eventbus/*").handler(sockJSHandler); return super.preRoute(); }); } });
@Override public SockJSHandler configure(VertxContext vertxContext, ServerConfiguration<JsonObject, JsonObject[]> config) { BridgeOptions bridgeOptions=new BridgeOptions(); bridgeOptions.addOutboundPermitted(new PermittedOptions().setAddress(VertxBusContext.DEFAULT_SOCKJS_ADDRESS)); SockJSHandler sockJSHandler = SockJSHandler.create(vertxContext.vertx()); sockJSHandler.bridge(bridgeOptions, event -> event.complete(true)); sockJSHandler.socketHandler(event -> event.headers().set(ACCESS_CONTROL_ALLOW_ORIGIN, ALLOW_ALL)); return sockJSHandler; } }