Skip to content

Commit

Permalink
Use Netty instead of Akka HTTP
Browse files Browse the repository at this point in the history
  • Loading branch information
rucek committed Oct 2, 2023
1 parent ff6118e commit cf8d542
Showing 1 changed file with 4 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package sttp.tapir.examples.observability

import akka.actor.ActorSystem
import akka.http.scaladsl.Http
import akka.http.scaladsl.server.Route
import com.typesafe.scalalogging.StrictLogging
import io.circe.generic.auto._
import io.opentelemetry.api.OpenTelemetry
Expand All @@ -14,8 +12,8 @@ import sttp.tapir._
import sttp.tapir.generic.auto._
import sttp.tapir.json.circe.jsonBody
import sttp.tapir.server.ServerEndpoint
import sttp.tapir.server.akkahttp.{AkkaHttpServerInterpreter, AkkaHttpServerOptions}
import sttp.tapir.server.metrics.opentelemetry.OpenTelemetryMetrics
import sttp.tapir.server.netty.{NettyFutureServer, NettyFutureServerOptions}

import scala.concurrent.duration._
import scala.concurrent.{Await, Future}
Expand Down Expand Up @@ -90,15 +88,13 @@ object OpenTelemetryMetricsExample extends App with StrictLogging {

val openTelemetryMetrics = OpenTelemetryMetrics.default[Future](otel)

val serverOptions: AkkaHttpServerOptions =
AkkaHttpServerOptions.customiseInterceptors
val serverOptions: NettyFutureServerOptions =
NettyFutureServerOptions.customiseInterceptors
// Adds an interceptor which collects metrics by executing callbacks
.metricsInterceptor(openTelemetryMetrics.metricsInterceptor())
.options

val routes: Route = AkkaHttpServerInterpreter(serverOptions).toRoute(personEndpoint)

Await.result(Http().newServerAt("localhost", 8080).bindFlow(routes), 1.minute)
Await.ready(NettyFutureServer().port(8080).addEndpoint(personEndpoint, serverOptions).start(), 1.minute)

logger.info(s"Server started. POST persons under http://localhost:8080/person.")
}

0 comments on commit cf8d542

Please sign in to comment.