Created
February 27, 2018 01:05
-
-
Save dpsoft/79f48c9224d0dd55fed8ad3d2ec80ba0 to your computer and use it in GitHub Desktop.
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
object GoogleService { | |
def service[F[_]: Effect](c: Client[F]): HttpService[F] = { | |
val dsl = new Http4sDsl[F]{} | |
import dsl._ | |
HttpService[F] { | |
case GET -> Root / "not" => | |
Thread.sleep((Math.random() * 1000).toLong) | |
NotFound("NotFound") | |
case req@GET -> Root / "call-google" => | |
println(req.headers) | |
Ok(c.expect[String]("https://www.google.com.ar")) | |
} | |
} | |
} |
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
object Server extends StreamApp[IO] { | |
Kamon.addReporter(new PrometheusReporter()) | |
Kamon.addReporter(new ZipkinReporter()) | |
def serve[F[_]](implicit Effect: Effect[F], EC: ExecutionContext) : Stream[F, StreamApp.ExitCode] = | |
for { | |
_ <- Stream.eval(Sync[F].delay(println("Starting Google Service with Client"))) | |
client <- Http1Client.stream[F]() | |
service = GoogleService.service[F](middleware.client.KamonSupport(client)) | |
exitCode <- BlazeBuilder[F] | |
.bindHttp(Config.server.port, Config.server.interface) | |
.mountService(middleware.server.KamonSupport(service)) | |
.serve | |
} yield exitCode | |
override def stream(args: List[String], requestShutdown: IO[Unit]): Stream[IO, StreamApp.ExitCode] = { | |
implicit val executor: ExecutionContext = ExecutionContext.fromExecutor(Executors.newFixedThreadPool(Config.server.threadPool.size)) | |
serve[IO] | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment