Created
January 21, 2021 01:03
-
-
Save limadelrey/a0157b43ea67694a0cf2c06dd1122972 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ApiVerticle extends AbstractVerticle { | |
private static final Logger LOGGER = LoggerFactory.getLogger(ApiVerticle.class); | |
@Override | |
public void start(Promise<Void> promise) { | |
final PgPool dbClient = DbUtils.buildDbClient(vertx); | |
final BookRepository bookRepository = new BookRepository(); | |
final BookService bookService = new BookService(dbClient, bookRepository); | |
final BookHandler bookHandler = new BookHandler(bookService); | |
final BookValidationHandler bookValidationHandler = new BookValidationHandler(vertx); | |
final BookRouter bookRouter = new BookRouter(vertx, bookHandler, bookValidationHandler); | |
final Router router = Router.router(vertx); | |
ErrorHandler.buildHandler(router); | |
HealthCheckRouter.setRouter(vertx, router, dbClient); | |
MetricsRouter.setRouter(router); | |
bookRouter.setRouter(router); | |
buildHttpServer(vertx, promise, router); | |
} | |
/** | |
* Run HTTP server on port 8888 with specified routes | |
* | |
* @param vertx Vertx context | |
* @param promise Callback | |
* @param router Router | |
*/ | |
private void buildHttpServer(Vertx vertx, | |
Promise<Void> promise, | |
Router router) { | |
final int port = 8888; | |
vertx.createHttpServer() | |
.requestHandler(router) | |
.listen(port, http -> { | |
if (http.succeeded()) { | |
promise.complete(); | |
LOGGER.info(LogUtils.RUN_HTTP_SERVER_SUCCESS_MESSAGE.buildMessage(port)); | |
} else { | |
promise.fail(http.cause()); | |
LOGGER.info(LogUtils.RUN_HTTP_SERVER_ERROR_MESSAGE.buildMessage()); | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment