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);
}
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);
});
}
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);
}
Aggregations