Search in sources :

Example 6 with Router

use of io.vertx.rxjava.ext.web.Router in project vertx-openshift-it by cescoffier.

the class GreetingServiceVerticle method start.

@Override
public void start() throws Exception {
    circuit = CircuitBreaker.create("circuit-breaker", vertx, new CircuitBreakerOptions().setFallbackOnFailure(true).setMaxFailures(3).setResetTimeout(5000).setNotificationAddress("circuit-breaker").setTimeout(1000));
    client = WebClient.create(vertx, new WebClientOptions().setDefaultHost("name-service").setDefaultPort(8080));
    Router router = Router.router(vertx);
    router.get("/health").handler(rc -> rc.response().end("OK"));
    router.get("/eventbus/*").handler(getSockJsHandler());
    // The address is the circuit breaker notification address configured above.
    router.get("/metrics").handler(HystrixMetricHandler.create(vertx, "circuit-breaker"));
    router.get("/api/greeting").handler(this::greeting);
    router.get("/api/cb-state").handler(rc -> rc.response().putHeader(CONTENT_TYPE.toString(), APPLICATION_JSON.toString()).end(new JsonObject().put("state", circuit.state()).encodePrettily()));
    router.get("/*").handler(StaticHandler.create());
    vertx.createHttpServer().requestHandler(router::accept).listen(8080);
}
Also used : WebClientOptions(io.vertx.ext.web.client.WebClientOptions) Router(io.vertx.rxjava.ext.web.Router) JsonObject(io.vertx.core.json.JsonObject) CircuitBreakerOptions(io.vertx.circuitbreaker.CircuitBreakerOptions)

Example 7 with Router

use of io.vertx.rxjava.ext.web.Router in project vertx-openshift-it by cescoffier.

the class OracleVerticle method start.

@Override
public void start() throws Exception {
    Router router = Router.router(vertx);
    router.route().handler(BodyHandler.create());
    router.route("/api/vegetables/:id").handler(this::validateId);
    router.get("/api/vegetables").handler(this::getAll);
    router.post("/api/vegetables").handler(this::addOne);
    router.get("/api/vegetables/:id").handler(this::getOne);
    router.put("/api/vegetables/:id").handler(this::updateOne);
    router.delete("/api/vegetables/:id").handler(this::deleteOne);
    router.get("/healthcheck").handler(rc -> rc.response().end("OK"));
    JsonObject config = TestUtils.allocateDatabase("oracle", true);
    JDBCClient jdbcClient = JDBCClient.createShared(vertx, config);
    vegetableTableExists(jdbcClient).subscribe(VegetableTableExists -> {
        Completable firstAction = initDatabase(vertx, jdbcClient);
        if (VegetableTableExists) {
            firstAction = dropVegetableTable(jdbcClient).andThen(initDatabase(vertx, jdbcClient));
        }
        firstAction.andThen(initHttpServer(router, jdbcClient)).subscribe((http) -> System.out.println("Server ready on port " + http.actualPort()), Throwable::printStackTrace);
    });
}
Also used : Completable(rx.Completable) Router(io.vertx.rxjava.ext.web.Router) JsonObject(io.vertx.core.json.JsonObject) JDBCClient(io.vertx.rxjava.ext.jdbc.JDBCClient)

Example 8 with Router

use of io.vertx.rxjava.ext.web.Router in project rulesservice by genny-project.

the class Routers method routers.

public static void routers(final Vertx vertx) {
    final Router router = Router.router(vertx);
    router.route().handler(RouterHandlers.cors());
    router.route(HttpMethod.POST, "/write").handler(RouterHandlers::apiMapPutHandler);
    router.route(HttpMethod.GET, "/read/:param1").handler(RouterHandlers::apiMapGetHandler);
    router.route(HttpMethod.GET, "/version").handler(VersionHandler::apiGetVersionHandler);
    vertx.createHttpServer().requestHandler(router::accept).listen(serverPort);
}
Also used : Router(io.vertx.rxjava.ext.web.Router)

Aggregations

Router (io.vertx.rxjava.ext.web.Router)8 JsonObject (io.vertx.core.json.JsonObject)5 JDBCClient (io.vertx.rxjava.ext.jdbc.JDBCClient)4 WebClientOptions (io.vertx.ext.web.client.WebClientOptions)2 AbstractVerticle (io.vertx.rxjava.core.AbstractVerticle)2 CircuitBreakerOptions (io.vertx.circuitbreaker.CircuitBreakerOptions)1 HttpClientOptions (io.vertx.core.http.HttpClientOptions)1 Runner (io.vertx.example.util.Runner)1 HttpClient (io.vertx.rxjava.core.http.HttpClient)1 RoutingContext (io.vertx.rxjava.ext.web.RoutingContext)1 HttpResponse (io.vertx.rxjava.ext.web.client.HttpResponse)1 WebClient (io.vertx.rxjava.ext.web.client.WebClient)1 BodyCodec (io.vertx.rxjava.ext.web.codec.BodyCodec)1 StaticHandler (io.vertx.rxjava.ext.web.handler.StaticHandler)1 SockJSHandler (io.vertx.rxjava.ext.web.handler.sockjs.SockJSHandler)1 ServiceDiscovery (io.vertx.rxjava.servicediscovery.ServiceDiscovery)1 HttpEndpoint (io.vertx.rxjava.servicediscovery.types.HttpEndpoint)1 JDBCDataSource (io.vertx.rxjava.servicediscovery.types.JDBCDataSource)1 Completable (rx.Completable)1 Observable (rx.Observable)1