Skip to content

Commit

Permalink
Replace Blaze with Ember.
Browse files Browse the repository at this point in the history
  • Loading branch information
Caparow committed Jul 18, 2024
1 parent 340bf99 commit 135a9f9
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 22 deletions.
4 changes: 2 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -566,8 +566,8 @@ lazy val `idealingua-v1-runtime-rpc-http4s` = project.in(file("idealingua-v1/ide
"org.scalatest" %% "scalatest" % V.scalatest % Test,
"org.http4s" %% "http4s-dsl" % V.http4s,
"org.http4s" %% "http4s-circe" % V.http4s,
"org.http4s" %% "http4s-blaze-server" % V.http4s_blaze,
"org.http4s" %% "http4s-blaze-client" % V.http4s_blaze,
"org.http4s" %% "http4s-ember-server" % V.http4s_ember,
"org.http4s" %% "http4s-ember-client" % V.http4s_ember,
"org.asynchttpclient" % "async-http-client" % V.asynchttpclient,
"io.7mind.izumi" %% "logstage-core" % Izumi.version,
"io.7mind.izumi" %% "logstage-adapter-slf4j" % Izumi.version
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import org.http4s.client.Client
import org.http4s.{Request, Response, Status, Uri}

class HttpRpcDispatcher[F[+_, +_]: IO2](
blazeClient: Client[F[Throwable, _]],
client: Client[F[Throwable, _]],
uri: Uri,
codec: IRTClientMultiplexor[F],
printer: circe.Printer,
Expand All @@ -38,7 +38,7 @@ class HttpRpcDispatcher[F[+_, +_]: IO2](
for {
req <- F.sync(buildRequest(uri)(method, request.getBytes))
_ <- logger.trace(s"$method: Prepared request $req")
res <- blazeClient.run(req).use(handleResponse(codec, method))
res <- client.run(req).use(handleResponse(codec, method))
} yield res
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@ import izumi.fundamentals.platform.language.Quirks.Discarder
import izumi.idealingua.runtime.rpc.http4s.HttpExecutionContext
import izumi.idealingua.runtime.rpc.{IRTClientMultiplexor, IRTMethodId, IRTMuxRequest, IRTMuxResponse}
import logstage.LogIO2
import org.http4s.blaze.client.BlazeClientBuilder
import org.http4s.client.Client
import org.http4s.ember.client.EmberClientBuilder
import org.http4s.{Header, Headers, Request, Uri}
import org.typelevel.ci.CIString

class HttpRpcDispatcherFactory[F[+_, +_]: IO2](
codec: IRTClientMultiplexor[F],
executionContext: HttpExecutionContext,
printer: circe.Printer,
logger: LogIO2[F],
)(implicit AT: Async[F[Throwable, _]]
Expand All @@ -27,7 +26,7 @@ class HttpRpcDispatcherFactory[F[+_, +_]: IO2](
tweakRequest: Request[F[Throwable, _]] => Request[F[Throwable, _]] = (req: Request[F[Throwable, _]]) => req,
resourceCheck: F[Throwable, Unit] = F.unit,
): Lifecycle[F[Throwable, _], HttpRpcDispatcher[F]] = {
blazeClient.map {
emberClient.map {
new HttpRpcDispatcher[F](_, uri, codec, printer, dispatcherLogger(uri, logger)) {
override def dispatch(input: IRTMuxRequest): F[Throwable, IRTMuxResponse] = {
resourceCheck *> super.dispatch(input)
Expand Down Expand Up @@ -62,16 +61,15 @@ class HttpRpcDispatcherFactory[F[+_, +_]: IO2](
logger
}

protected def blazeClient: Lifecycle[F[Throwable, _], Client[F[Throwable, _]]] = {
protected def emberClient: Lifecycle[F[Throwable, _], Client[F[Throwable, _]]] = {
Lifecycle.fromCats {
blazeClientBuilder {
BlazeClientBuilder[F[Throwable, _]]
.withExecutionContext(executionContext.clientExecutionContext)
}.resource
emberClientBuilder {
EmberClientBuilder.default[F[Throwable, _]]
}.build
}
}

protected def blazeClientBuilder(defaultBuilder: BlazeClientBuilder[F[Throwable, _]]): BlazeClientBuilder[F[Throwable, _]] = {
protected def emberClientBuilder(defaultBuilder: EmberClientBuilder[F[Throwable, _]]): EmberClientBuilder[F[Throwable, _]] = {
defaultBuilder
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package izumi.idealingua.runtime.rpc.http4s

import cats.effect.Async
import com.comcast.ip4s.{Host, Port}
import io.circe.{Json, Printer}
import izumi.functional.bio.Exit.{Error, Success, Termination}
import izumi.functional.bio.UnsafeRun2.FailureHandler
Expand All @@ -21,8 +22,8 @@ import izumi.logstage.api.{IzLogger, Log}
import izumi.r2.idealingua.test.generated.*
import logstage.LogIO2
import org.http4s.*
import org.http4s.blaze.server.*
import org.http4s.dsl.Http4sDsl
import org.http4s.ember.server.EmberServerBuilder
import org.http4s.headers.Authorization
import org.http4s.server.Router
import org.scalatest.wordspec.AnyWordSpec
Expand Down Expand Up @@ -83,10 +84,12 @@ object Http4sTransportTest {
port = addr.getPort
host = addr.getHostName
_ <- Lifecycle.fromCats {
BlazeServerBuilder[F[Throwable, _]]
.bindHttp(port, host)
EmberServerBuilder
.default[F[Throwable, _]]
.withPort(Port.fromInt(port).get)
.withHost(Host.fromString(host).get)
.withHttpWebSocketApp(ws => Router("/" -> ioService.service(ws)).orNotFound)
.resource
.build
}
execCtx = HttpExecutionContext(global)
baseUri = Uri(Some(Uri.Scheme.http), Some(Uri.Authority(host = Uri.RegName(host), port = Some(port))))
Expand All @@ -113,7 +116,7 @@ object Http4sTransportTest {
)(implicit asyncThrowable: Async[F[Throwable, _]]
) {
val httpClientFactory: HttpRpcDispatcherFactory[F] = {
new HttpRpcDispatcherFactory[F](testServices.Client.codec, execCtx, printer, logger)
new HttpRpcDispatcherFactory[F](testServices.Client.codec, printer, logger)
}
def httpRpcClientDispatcher(headers: Headers): Lifecycle[F[Throwable, _], HttpRpcDispatcher.IRTDispatcherRaw[F]] = {
httpClientFactory.dispatcher(baseUri, headers)
Expand Down
6 changes: 3 additions & 3 deletions project/Deps.sc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ object Idealingua {
val izumi_reflect = Version.VExpr("Izumi.Deps.fundamentals_bioJVM.dev_zio_izumi_reflect_version")

val http4s = Version.VExpr("V.http4s")
val http4s_blaze = Version.VExpr("V.http4s_blaze")
val http4s_ember = Version.VExpr("V.http4s_ember")
val scalameta = Version.VExpr("V.scalameta")
val fastparse = Version.VExpr("V.fastparse")
val scala_xml = Version.VExpr("V.scala_xml")
Expand Down Expand Up @@ -116,13 +116,13 @@ object Idealingua {
final val fastparse = Library("com.lihaoyi", "fastparse", V.fastparse, LibraryType.Auto) in Scope.Compile.all

final val http4s_client = Seq(
Library("org.http4s", "http4s-blaze-client", V.http4s_blaze, LibraryType.Auto)
Library("org.http4s", "http4s-ember-client", V.http4s_ember, LibraryType.Auto),
)

val http4s_server = Seq(
Library("org.http4s", "http4s-dsl", V.http4s, LibraryType.Auto),
Library("org.http4s", "http4s-circe", V.http4s, LibraryType.Auto),
Library("org.http4s", "http4s-blaze-server", V.http4s_blaze, LibraryType.Auto),
Library("org.http4s", "http4s-ember-server", V.http4s_ember, LibraryType.Auto),
)

val http4s_all = http4s_server ++ http4s_client
Expand Down
2 changes: 1 addition & 1 deletion project/Versions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ object V {
val scalatest = "3.2.18"

val http4s = "0.23.27"
val http4s_blaze = "0.23.16"
val http4s_ember = "0.23.27"

val scalameta = "4.9.5" // Not available for Scala 3 yet
val fastparse = "3.1.0" // 3.0.0 is available for Scala 3
Expand Down

0 comments on commit 135a9f9

Please sign in to comment.