Search in sources :

Example 6 with SockJSHandler

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);
}
Also used : BridgeOptions(io.vertx.ext.web.handler.sockjs.BridgeOptions) SockJSHandler(io.vertx.ext.web.handler.sockjs.SockJSHandler)

Example 7 with 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);
}
Also used : ProcessorServiceImpl(io.vertx.examples.service.impl.ProcessorServiceImpl) Router(io.vertx.ext.web.Router) BridgeOptions(io.vertx.ext.web.handler.sockjs.BridgeOptions) PermittedOptions(io.vertx.ext.web.handler.sockjs.PermittedOptions) SockJSHandler(io.vertx.ext.web.handler.sockjs.SockJSHandler)

Example 8 with SockJSHandler

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));
    });
}
Also used : Router(io.vertx.ext.web.Router) JsonObject(io.vertx.core.json.JsonObject) BridgeOptions(io.vertx.ext.web.handler.sockjs.BridgeOptions) PermittedOptions(io.vertx.ext.web.handler.sockjs.PermittedOptions) EventBus(io.vertx.core.eventbus.EventBus) SockJSHandler(io.vertx.ext.web.handler.sockjs.SockJSHandler)

Example 9 with SockJSHandler

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));
    });
}
Also used : Router(io.vertx.ext.web.Router) JsonObject(io.vertx.core.json.JsonObject) BridgeOptions(io.vertx.ext.web.handler.sockjs.BridgeOptions) PermittedOptions(io.vertx.ext.web.handler.sockjs.PermittedOptions) EventBus(io.vertx.core.eventbus.EventBus) SockJSHandler(io.vertx.ext.web.handler.sockjs.SockJSHandler)

Example 10 with SockJSHandler

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));
    });
}
Also used : Router(io.vertx.ext.web.Router) JsonObject(io.vertx.core.json.JsonObject) BridgeOptions(io.vertx.ext.web.handler.sockjs.BridgeOptions) PermittedOptions(io.vertx.ext.web.handler.sockjs.PermittedOptions) EventBus(io.vertx.core.eventbus.EventBus) SockJSHandler(io.vertx.ext.web.handler.sockjs.SockJSHandler)

Aggregations

SockJSHandler (io.vertx.ext.web.handler.sockjs.SockJSHandler)15 BridgeOptions (io.vertx.ext.web.handler.sockjs.BridgeOptions)13 Router (io.vertx.ext.web.Router)7 PermittedOptions (io.vertx.ext.web.handler.sockjs.PermittedOptions)7 JsonObject (io.vertx.core.json.JsonObject)6 EventBus (io.vertx.core.eventbus.EventBus)5 PermittedOptions (io.vertx.ext.bridge.PermittedOptions)4 SockJSHandlerOptions (io.vertx.ext.web.handler.sockjs.SockJSHandlerOptions)2 ProcessorServiceImpl (io.vertx.examples.service.impl.ProcessorServiceImpl)1