Search in sources :

Example 1 with Router

use of io.vertx.reactivex.ext.web.Router in project vertx-examples by vert-x3.

the class Server method start.

@Override
public void start() throws Exception {
    Router router = Router.router(vertx);
    router.route().handler(routingContext -> {
        routingContext.response().putHeader("content-type", "text/html").end("Hello World!");
    });
    vertx.createHttpServer().requestHandler(router::accept).listen(8080);
}
Also used : Router(io.vertx.reactivex.ext.web.Router)

Example 2 with Router

use of io.vertx.reactivex.ext.web.Router in project vertx-examples by vert-x3.

the class Server method start.

@Override
public void start() throws Exception {
    Router router = Router.router(vertx);
    router.route("/news-feed/*").handler(SockJSHandler.create(vertx).socketHandler(sockJSSocket -> {
        // Consumer the event bus address as an Flowable
        Flowable<String> msg = vertx.eventBus().<String>consumer("news-feed").bodyStream().toFlowable();
        // Send the event to the client
        Disposable subscription = msg.subscribe(sockJSSocket::write);
        // Unsubscribe (dispose) when the socket closes
        sockJSSocket.endHandler(v -> {
            subscription.dispose();
        });
    }));
    // Serve the static resources
    router.route().handler(StaticHandler.create());
    vertx.createHttpServer().requestHandler(router::accept).listen(8080);
    // Publish a message to the address "news-feed" every second
    vertx.setPeriodic(1000, t -> vertx.eventBus().publish("news-feed", "news from the server!"));
}
Also used : Disposable(io.reactivex.disposables.Disposable) Flowable(io.reactivex.Flowable) Router(io.vertx.reactivex.ext.web.Router) AbstractVerticle(io.vertx.reactivex.core.AbstractVerticle) Runner(io.vertx.example.util.Runner) StaticHandler(io.vertx.reactivex.ext.web.handler.StaticHandler) SockJSHandler(io.vertx.reactivex.ext.web.handler.sockjs.SockJSHandler) Disposable(io.reactivex.disposables.Disposable) Router(io.vertx.reactivex.ext.web.Router) Flowable(io.reactivex.Flowable)

Example 3 with Router

use of io.vertx.reactivex.ext.web.Router in project vertx-zero by silentbalanceyh.

the class ZeroRxAgent method start.

@Override
public void start() {
    /**
     * 1.Call router hub to mount commont *
     */
    final Axis<Router> routerAxiser = Fn.poolThread(Pool.ROUTERS, () -> Instance.instance(RouterAxis.class));
    /**
     * 2.Call route hub to mount defined *
     */
    final Axis<Router> axiser = Fn.poolThread(Pool.EVENTS, () -> Instance.instance(EventAxis.class));
    /**
     * 3.Get the default HttpServer Options *
     */
    ZeroAtomic.RX_OPTS.forEach((port, option) -> {
        /**
         * 3.1.Single server processing *
         */
        final HttpServer server = this.vertx.createHttpServer(option);
        /**
         * 3.2. Build router with current option *
         */
        final Router router = Router.router(this.vertx);
        routerAxiser.mount(router);
        axiser.mount(router);
        /**
         * 3.3. Listen for router on the server *
         */
        final Single<HttpServer> result = server.requestHandler(router::accept).rxListen();
        /**
         * 3.4. Log output *
         */
        {
            result.subscribe((rxServer) -> {
                recordServer(option, router);
            });
        }
    });
}
Also used : ZeroAtomic(io.vertx.up.micro.ZeroAtomic) HttpServer(io.vertx.reactivex.core.http.HttpServer) Fn(io.vertx.up.func.Fn) Router(io.vertx.reactivex.ext.web.Router) ServerType(io.vertx.up.eon.em.ServerType) RouterAxis(io.vertx.rx.rs.router.RouterAxis) Route(io.vertx.reactivex.ext.web.Route) Single(io.reactivex.Single) Instance(io.vertx.up.tool.mirror.Instance) MessageFormat(java.text.MessageFormat) List(java.util.List) Axis(io.vertx.up.rs.Axis) Values(io.vertx.zero.eon.Values) TreeMap(java.util.TreeMap) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) Annal(io.vertx.up.log.Annal) HttpServerOptions(io.vertx.core.http.HttpServerOptions) AbstractVerticle(io.vertx.reactivex.core.AbstractVerticle) EventAxis(io.vertx.rx.rs.router.EventAxis) Agent(io.vertx.up.annotations.Agent) EventAxis(io.vertx.rx.rs.router.EventAxis) RouterAxis(io.vertx.rx.rs.router.RouterAxis) HttpServer(io.vertx.reactivex.core.http.HttpServer) Router(io.vertx.reactivex.ext.web.Router)

Example 4 with Router

use of io.vertx.reactivex.ext.web.Router in project vertx-examples by vert-x3.

the class Server method start.

@Override
public void start() throws Exception {
    Router router = Router.router(vertx);
    router.route().handler(BodyHandler.create());
    router.route().handler(req -> req.response().putHeader("content-type", "text/html").end("<html><body><h1>Hello from vert.x!</h1></body></html>"));
    HttpServer server = vertx.createHttpServer();
    server.requestStream().toFlowable().map(HttpServerRequest::pause).onBackpressureDrop(req -> req.response().setStatusCode(503).end()).observeOn(RxHelper.scheduler(vertx.getDelegate())).subscribe(req -> {
        req.resume();
        router.accept(req);
    });
    server.rxListen(PORT).subscribe(res -> generateRequests());
}
Also used : HttpServer(io.vertx.reactivex.core.http.HttpServer) Router(io.vertx.reactivex.ext.web.Router)

Example 5 with Router

use of io.vertx.reactivex.ext.web.Router in project api-framework by vinscom.

the class Server method start.

@StartService
public void start() {
    HttpServer server = getVertx().createHttpServer(new HttpServerOptions().setPort(getPort()).setHost(getHost()));
    Router router = Router.router(getVertx());
    // Logging
    if (getLog().isDebugEnabled()) {
        router.route("/*").handler(LoggerHandler.create());
    }
    if (getSockJSHandler() != null) {
        router.route("/eventbus/*").handler(getSockJSHandler());
    }
    for (int i = 0; i < mMountPath.length; i++) {
        router.mountSubRouter(mMountPath[i], mRouter[i]);
    }
    server.requestHandler(router::accept).rxListen().blockingGet();
    getLog().debug(() -> String.format("---------------Server[%s:%s] is ready-----------------", getHost(), getPort()));
}
Also used : HttpServer(io.vertx.reactivex.core.http.HttpServer) HttpServerOptions(io.vertx.core.http.HttpServerOptions) Router(io.vertx.reactivex.ext.web.Router) StartService(in.erail.glue.annotation.StartService)

Aggregations

Router (io.vertx.reactivex.ext.web.Router)6 HttpServer (io.vertx.reactivex.core.http.HttpServer)3 HttpServerOptions (io.vertx.core.http.HttpServerOptions)2 AbstractVerticle (io.vertx.reactivex.core.AbstractVerticle)2 StartService (in.erail.glue.annotation.StartService)1 KnotxCSRFConfig (io.knotx.server.configuration.KnotxCSRFConfig)1 Flowable (io.reactivex.Flowable)1 Single (io.reactivex.Single)1 Disposable (io.reactivex.disposables.Disposable)1 Runner (io.vertx.example.util.Runner)1 Route (io.vertx.reactivex.ext.web.Route)1 CSRFHandler (io.vertx.reactivex.ext.web.handler.CSRFHandler)1 StaticHandler (io.vertx.reactivex.ext.web.handler.StaticHandler)1 SockJSHandler (io.vertx.reactivex.ext.web.handler.sockjs.SockJSHandler)1 EventAxis (io.vertx.rx.rs.router.EventAxis)1 RouterAxis (io.vertx.rx.rs.router.RouterAxis)1 Agent (io.vertx.up.annotations.Agent)1 ServerType (io.vertx.up.eon.em.ServerType)1 Fn (io.vertx.up.func.Fn)1 Annal (io.vertx.up.log.Annal)1