Search in sources :

Example 11 with PermittedOptions

use of io.vertx.ext.web.handler.sockjs.PermittedOptions 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)

Example 12 with PermittedOptions

use of io.vertx.ext.web.handler.sockjs.PermittedOptions in project vertx-openshift-it by cescoffier.

the class GreetingServiceVerticle method getSockJsHandler.

private Handler<RoutingContext> getSockJsHandler() {
    SockJSHandler sockJSHandler = SockJSHandler.create(vertx);
    BridgeOptions options = new BridgeOptions();
    options.addInboundPermitted(new PermittedOptions().setAddress("circuit-breaker"));
    options.addOutboundPermitted(new PermittedOptions().setAddress("circuit-breaker"));
    return sockJSHandler.bridge(options);
}
Also used : BridgeOptions(io.vertx.ext.web.handler.sockjs.BridgeOptions) PermittedOptions(io.vertx.ext.web.handler.sockjs.PermittedOptions) SockJSHandler(io.vertx.rxjava.ext.web.handler.sockjs.SockJSHandler)

Aggregations

BridgeOptions (io.vertx.ext.web.handler.sockjs.BridgeOptions)12 PermittedOptions (io.vertx.ext.web.handler.sockjs.PermittedOptions)12 Router (io.vertx.ext.web.Router)11 SockJSHandler (io.vertx.ext.web.handler.sockjs.SockJSHandler)8 JsonObject (io.vertx.core.json.JsonObject)7 EventBus (io.vertx.core.eventbus.EventBus)5 HttpServer (io.vertx.core.http.HttpServer)2 AbstractVerticle (io.vertx.core.AbstractVerticle)1 Runner (io.vertx.example.util.Runner)1 ProcessorServiceImpl (io.vertx.examples.service.impl.ProcessorServiceImpl)1 AuthProvider (io.vertx.ext.auth.AuthProvider)1 BridgeEventType (io.vertx.ext.bridge.BridgeEventType)1 MetricsService (io.vertx.ext.dropwizard.MetricsService)1 StaticHandler (io.vertx.ext.web.handler.StaticHandler)1 SockJSHandler (io.vertx.rxjava.ext.web.handler.sockjs.SockJSHandler)1 Random (java.util.Random)1