use of io.vertx.ext.web.handler.sockjs.SockJSHandler in project vertx-web by vert-x3.
the class WebExamples method example45.
public void example45(Vertx vertx) {
Router router = Router.router(vertx);
SockJSHandler sockJSHandler = SockJSHandler.create(vertx);
BridgeOptions options = new BridgeOptions();
sockJSHandler.bridge(options);
router.route("/eventbus/*").handler(sockJSHandler);
}
use of io.vertx.ext.web.handler.sockjs.SockJSHandler in project vertx-examples by vert-x3.
the class ProcessorServiceVerticle method start.
@Override
public void start() throws Exception {
// Create the client object
service = new ProcessorServiceImpl();
// Register the handler
ProxyHelper.registerService(ProcessorService.class, vertx, service, "vertx.processor");
//
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::accept).listen(8080);
}
use of io.vertx.ext.web.handler.sockjs.SockJSHandler in project vertx-examples by vert-x3.
the class Server method start.
@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::accept).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));
});
}
use of io.vertx.ext.web.handler.sockjs.SockJSHandler in project vertx-examples by vert-x3.
the class Server method start.
@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::accept).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));
});
}
use of io.vertx.ext.web.handler.sockjs.SockJSHandler in project vertx-examples by vert-x3.
the class Server method start.
@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::accept).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));
});
}
Aggregations