Created
April 6, 2020 10:03
-
-
Save Andrea/e886e241486fca56ba4d14a0fac6042d to your computer and use it in GitHub Desktop.
Most of the config
This file contains hidden or 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
``` | |
//... | |
private val nThreads = Runtime.getRuntime.availableProcessors * 2 | |
private val executorService = Executors.newFixedThreadPool(nThreads) | |
implicit val executionContext: ExecutionContextExecutorService = ExecutionContext.fromExecutorService(executorService) | |
implicit val cs: ContextShift[IO] = IO.contextShift(ec) | |
implicit val timer: Timer[IO] = IO.timer(ec) | |
//Here we do a query using doobie | |
val domainRoutes: HttpRoutes[IO] = DomainRoutes.routes(..., ...) | |
val httpApp = Router( | |
"/" -> (domainRoutes) | |
).orNotFound | |
BlazeServerBuilder[IO] | |
.bindHttp(port, host) | |
.withExecutionContext(ec) | |
.withWebSockets(false) | |
.withHttpApp(httpApp) | |
.resource | |
///somewhere else this is how we create the transactor, we use a Blocker[IO] | |
def transactorFrom(config: Db)(implicit be: Blocker): Resource[IO, HikariTransactor[IO]] = { | |
HikariTransactor.newHikariTransactor[IO]( | |
config.driver, | |
config.url, | |
config.user, | |
config.password, | |
ExecutionContext.fromExecutorService(Executors.newFixedThreadPool(10)), | |
be | |
) | |
} | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment