Skip to content
This repository has been archived by the owner on Oct 10, 2023. It is now read-only.

Migrate from Akka to Pekko. #426

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Scala-HTTP-Client
# Scala-Pekko-HTTP-Client

This is a wrapper around the akka-http-client that adds
This is a wrapper around the pekko-http-client that adds

* handling for domain errors as HTTP 400 returns
* retry logic
Expand All @@ -9,14 +9,14 @@ This is a wrapper around the akka-http-client that adds
* logging
* AWS request signing

![Build & Test](https://github.com/moia-oss/scala-http-client/workflows/Build%20&%20Test/badge.svg)
[![Scala 2.13](https://img.shields.io/maven-central/v/io.moia/scala-http-client_2.13.svg)](https://search.maven.org/search?q=scala-http-client_2.13)
![Build & Test](https://github.com/moia-oss/scala-pekko-http-client/workflows/Build%20&%20Test/badge.svg)
[![Scala 2.13](https://img.shields.io/maven-central/v/io.moia/scala-pekko-http-client_2.13.svg)](https://search.maven.org/search?q=scala-pekko-http-client_2.13)
[![Scala Steward badge](https://img.shields.io/badge/Scala_Steward-helping-blue.svg?style=flat&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA4AAAAQCAMAAAARSr4IAAAAVFBMVEUAAACHjojlOy5NWlrKzcYRKjGFjIbp293YycuLa3pYY2LSqql4f3pCUFTgSjNodYRmcXUsPD/NTTbjRS+2jomhgnzNc223cGvZS0HaSD0XLjbaSjElhIr+AAAAAXRSTlMAQObYZgAAAHlJREFUCNdNyosOwyAIhWHAQS1Vt7a77/3fcxxdmv0xwmckutAR1nkm4ggbyEcg/wWmlGLDAA3oL50xi6fk5ffZ3E2E3QfZDCcCN2YtbEWZt+Drc6u6rlqv7Uk0LdKqqr5rk2UCRXOk0vmQKGfc94nOJyQjouF9H/wCc9gECEYfONoAAAAASUVORK5CYII=)](https://scala-steward.org)

## Usage

```sbt
libraryDependencies += "io.moia" %% "scala-http-client" % "5.0.0"
libraryDependencies += "io.moia" %% "scala-pekko-http-client" % "1.0.0"
```

```scala
Expand Down Expand Up @@ -58,7 +58,7 @@ The lib outputs the following response objects (see `io.moia.scalaHttpClient.Htt
* HTTP 4xx, 5xx, others => `HttpClientError`
* if the deadline expired => `DeadlineExpired`
* if an `AwsRequestSigner` is given, but the request already includes an "Authorization" header => `AlreadyAuthorizedException`
* weird akka-errors => `ExceptionOccurred`
* weird pekko-errors => `ExceptionOccurred`


## Custom Logging
Expand Down Expand Up @@ -110,10 +110,10 @@ See [LoggingExample.scala](/src/it/scala/io/moia/scalaHttpClient/LoggingExample.

## Custom Headers

To use custom-defined headers, you can extend `ModeledCustomHeader` from `akka.http.scaladsl.model.headers`:
To use custom-defined headers, you can extend `ModeledCustomHeader` from `org.apache.pekko.http.scaladsl.model.headers`:

```scala
import akka.http.scaladsl.model.headers.{ModeledCustomHeader, ModeledCustomHeaderCompanion}
import org.apache.pekko.http.scaladsl.model.headers.{ModeledCustomHeader, ModeledCustomHeaderCompanion}
import scala.util.Try

final class CustomHeader(id: String) extends ModeledCustomHeader[CustomHeader] {
Expand Down Expand Up @@ -150,18 +150,18 @@ See [HeaderExample.scala](/src/it/scala/io/moia/scalaHttpClient/HeaderExample.sc

## Publishing

[Tag](https://github.com/moia-oss/scala-http-client/tags) the new version (e.g. `v5.0.0`) and push the tags (`git push origin --tags`).
[Tag](https://github.com/moia-oss/scala-pekko-http-client/tags) the new version (e.g. `v1.0.0`) and push the tags (`git push origin --tags`).

You need a [public GPG key](https://www.scala-sbt.org/release/docs/Using-Sonatype.html) with your MOIA email and an account on https://oss.sonatype.org that can [access](https://issues.sonatype.org/browse/OSSRH-52948) the `io.moia` group.

Add your credentials to `~/.sbt/sonatype_credential` and run
```sbt
sbt:scala-http-client> +publishSigned
sbt:scala-pekko-http-client> +publishSigned
```

Then close and release the [repository](https://oss.sonatype.org/#stagingRepositories).
```
sbt:scala-http-client> +sonatypeRelease
sbt:scala-pekko-http-client> +sonatypeRelease
```

Afterwards, add the release to [GitHub](https://github.com/moia-oss/scala-http-client/releases).
Afterwards, add the release to [GitHub](https://github.com/moia-oss/scala-pekko-http-client/releases).
28 changes: 14 additions & 14 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
lazy val root = (project in file("."))
.settings(
name := "scala-http-client",
name := "scala-pekko-http-client",
organization := "io.moia",
licenses += ("Apache-2.0", url("https://www.apache.org/licenses/LICENSE-2.0")),
scmInfo := Some(ScmInfo(url("https://github.com/moia-oss/scala-http-client"), "scm:[email protected]:moia-oss/scala-http-client.git")),
homepage := Some(url("https://github.com/moia-oss/scala-http-client")),
scmInfo := Some(ScmInfo(url("https://github.com/moia-oss/scala-pekko-http-client"), "scm:[email protected]:moia-oss/scala-pekko-http-client.git")),
homepage := Some(url("https://github.com/moia-oss/scala-pekko-http-client")),
scalaVersion := "2.13.11",
crossScalaVersions := List("2.12.18", "2.13.11"),
versionScheme := Some("early-semver"),
Expand All @@ -15,7 +15,7 @@ lazy val root = (project in file("."))
case _ => Seq()
}
},
libraryDependencies ++= akkaDependencies ++ awsDependencies ++ testDependencies ++ loggingDependencies ++ scalaDependencies
libraryDependencies ++= pekkoDependencies ++ awsDependencies ++ testDependencies ++ loggingDependencies ++ scalaDependencies
)
.settings(sonatypeSettings: _*)
.configs(IntegrationTest)
Expand All @@ -31,15 +31,15 @@ lazy val root = (project in file("."))
)
.settings(mimaSettings)

val akkaVersion = "2.6.19"
val akkaHttpVersion = "10.2.10"
val pekkoVersion = "1.0.1"
val pekkoHttpVersion = "1.0.0"

lazy val akkaDependencies = Seq(
"com.typesafe.akka" %% "akka-stream" % akkaVersion,
"com.typesafe.akka" %% "akka-stream-typed" % akkaVersion,
"com.typesafe.akka" %% "akka-http" % akkaHttpVersion,
"com.typesafe.akka" %% "akka-testkit" % akkaVersion % Test,
"com.typesafe.akka" %% "akka-http-testkit" % akkaHttpVersion % Test
lazy val pekkoDependencies = Seq(
"org.apache.pekko" %% "pekko-stream" % pekkoVersion,
"org.apache.pekko" %% "pekko-stream-typed" % pekkoVersion,
"org.apache.pekko" %% "pekko-http" % pekkoHttpVersion,
"org.apache.pekko" %% "pekko-testkit" % pekkoVersion % Test,
"org.apache.pekko" %% "pekko-http-testkit" % pekkoHttpVersion % Test
)

lazy val awsJavaSdkVersion = "2.20.144"
Expand Down Expand Up @@ -104,7 +104,7 @@ lazy val sonatypeSettings = {
publishTo := sonatypePublishTo.value,
sonatypeProfileName := organization.value,
publishMavenStyle := true,
sonatypeProjectHosting := Some(GitHubHosting("moia-oss", "scala-http-client", "[email protected]")),
sonatypeProjectHosting := Some(GitHubHosting("moia-oss", "scala-pekko-http-client", "[email protected]")),
credentials += Credentials(Path.userHome / ".sbt" / "sonatype_credential")
)
}
Expand All @@ -124,5 +124,5 @@ lazy val sbtGitSettings = Seq(
)

lazy val mimaSettings = Seq(
mimaPreviousArtifacts := Set("io.moia" %% "scala-http-client" % "5.0.0")
mimaPreviousArtifacts := Set("io.moia" %% "scala-pekko-http-client" % "1.0.0")
)
10 changes: 5 additions & 5 deletions src/it/scala/io/moia/scalaHttpClient/HeaderExample.scala
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package io.moia.scalaHttpClient

import akka.actor.typed.ActorSystem
import akka.actor.typed.scaladsl.Behaviors
import akka.http.scaladsl.model._
import akka.http.scaladsl.model.headers.{ModeledCustomHeader, ModeledCustomHeaderCompanion}
import akka.http.scaladsl.unmarshalling.{Unmarshal, Unmarshaller}
import org.apache.pekko.actor.typed.ActorSystem
import org.apache.pekko.actor.typed.scaladsl.Behaviors
import org.apache.pekko.http.scaladsl.model._
import org.apache.pekko.http.scaladsl.model.headers.{ModeledCustomHeader, ModeledCustomHeaderCompanion}
import org.apache.pekko.http.scaladsl.unmarshalling.{Unmarshal, Unmarshaller}
import io.moia.scalaHttpClient.ExampleModel.{DomainErrorObject, GatewayException, MySuccessObject}

import java.time.Clock
Expand Down
6 changes: 3 additions & 3 deletions src/it/scala/io/moia/scalaHttpClient/LoggingExample.scala
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package io.moia.scalaHttpClient

import akka.actor.typed.ActorSystem
import akka.actor.typed.scaladsl.Behaviors
import akka.http.scaladsl.model._
import org.apache.pekko.actor.typed.ActorSystem
import org.apache.pekko.actor.typed.scaladsl.Behaviors
import org.apache.pekko.http.scaladsl.model._
import com.typesafe.scalalogging._
import io.moia.scalaHttpClient.CustomLogging.LoggingContext
import org.slf4j.LoggerFactory
Expand Down
8 changes: 4 additions & 4 deletions src/it/scala/io/moia/scalaHttpClient/SimpleExample.scala
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package io.moia.scalaHttpClient

import akka.actor.typed.ActorSystem
import akka.actor.typed.scaladsl.Behaviors
import akka.http.scaladsl.model._
import akka.http.scaladsl.unmarshalling.{Unmarshal, Unmarshaller}
import org.apache.pekko.actor.typed.ActorSystem
import org.apache.pekko.actor.typed.scaladsl.Behaviors
import org.apache.pekko.http.scaladsl.model._
import org.apache.pekko.http.scaladsl.unmarshalling.{Unmarshal, Unmarshaller}
import io.moia.scalaHttpClient.ExampleModel.{DomainErrorObject, GatewayException, MySuccessObject}

import java.time.Clock
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package io.moia.scalaHttpClient

import akka.http.scaladsl.model.HttpHeader.ParsingResult
import akka.http.scaladsl.model.{HttpHeader, HttpRequest, Uri}
import akka.stream.Materializer
import akka.stream.scaladsl.StreamConverters
import org.apache.pekko.http.scaladsl.model.HttpHeader.ParsingResult
import org.apache.pekko.http.scaladsl.model.{HttpHeader, HttpRequest, Uri}
import org.apache.pekko.stream.Materializer
import org.apache.pekko.stream.scaladsl.StreamConverters
import com.typesafe.scalalogging.StrictLogging
import software.amazon.awssdk.auth.credentials._
import software.amazon.awssdk.auth.signer.{Aws4Signer, AwsSignerExecutionAttribute}
Expand Down
13 changes: 7 additions & 6 deletions src/main/scala/io/moia/scalaHttpClient/HttpClient.scala
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package io.moia.scalaHttpClient

import akka.actor.typed.ActorSystem
import akka.http.scaladsl.Http
import akka.http.scaladsl.model._
import akka.http.scaladsl.model.headers.{`Retry-After`, RetryAfterDateTime, RetryAfterDuration}
import com.typesafe.scalalogging.{Logger, LoggerTakingImplicit}
import org.apache.pekko.actor.typed.ActorSystem
import org.apache.pekko.http.scaladsl.Http
import org.apache.pekko.http.scaladsl.model._
import org.apache.pekko.http.scaladsl.model.headers.{`Retry-After`, RetryAfterDateTime, RetryAfterDuration}
import org.apache.pekko.pattern.after
import org.slf4j.LoggerFactory

import java.time.Clock
Expand Down Expand Up @@ -148,7 +149,7 @@ abstract class HttpLayer[LoggingContext](
Future.successful(DeadlineExpired(Some(response)))
} else {
logger.info(s"[$name] Try #$tryNum: Retrying in ${delay.toMillis}ms.")
akka.pattern.after(delay)(executeRequest(request, tryNum + 1, deadline))
after(delay)(executeRequest(request, tryNum + 1, deadline))
}
} else {
logger.info(s"[$name] Try #$tryNum: No retries left. Giving up.")
Expand All @@ -173,7 +174,7 @@ abstract class HttpLayer[LoggingContext](
case NonFatal(e) if tryNum <= retryConfig.retriesException =>
val delay: FiniteDuration = calculateDelay(None, tryNum)
logger.info(s"[$name] Exception in request: ${e.getMessage}, retrying in ${delay.toMillis}ms.", e)
akka.pattern.after(delay)(executeRequest(request, tryNum + 1, deadline))
after(delay)(executeRequest(request, tryNum + 1, deadline))
case NonFatal(e) =>
logger.warn(s"[$name] Exception in request: ${e.getMessage}, retries exhausted, giving up.", e)
Future.successful(ExceptionOccurred(e))
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/io/moia/scalaHttpClient/HttpMetrics.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.moia.scalaHttpClient

import akka.http.scaladsl.model.{HttpMethod, HttpResponse, Uri}
import org.apache.pekko.http.scaladsl.model.{HttpMethod, HttpResponse, Uri}

trait HttpMetrics[LoggingContext] {
def meterResponse(method: HttpMethod, path: Uri.Path, response: HttpResponse)(implicit ctx: LoggingContext): Unit
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package io.moia.scalaHttpClient

import akka.actor.ActorSystem
import akka.http.scaladsl.model.headers.RawHeader
import akka.http.scaladsl.model.{HttpRequest, Uri}
import org.apache.pekko.actor.ActorSystem
import org.apache.pekko.http.scaladsl.model.headers.RawHeader
import org.apache.pekko.http.scaladsl.model.{HttpRequest, Uri}
import io.moia.scalaHttpClient.AwsRequestSigner.AwsRequestSignerConfig
import org.scalatest.matchers.should.Matchers
import org.scalatest.wordspec.AnyWordSpecLike
Expand Down
6 changes: 3 additions & 3 deletions src/test/scala/io/moia/scalaHttpClient/HttpClientTest.scala
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package io.moia.scalaHttpClient

import akka.http.scaladsl.model._
import akka.http.scaladsl.model.headers.{ModeledCustomHeader, ModeledCustomHeaderCompanion}
import akka.http.scaladsl.unmarshalling.Unmarshal
import org.apache.pekko.http.scaladsl.model._
import org.apache.pekko.http.scaladsl.model.headers.{ModeledCustomHeader, ModeledCustomHeaderCompanion}
import org.apache.pekko.http.scaladsl.unmarshalling.Unmarshal
import com.typesafe.scalalogging.StrictLogging
import io.moia.scalaHttpClient.AwsRequestSigner.AwsRequestSignerConfig
import org.scalatest.{Inside, Inspectors}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.moia.scalaHttpClient

import akka.http.scaladsl.model._
import org.apache.pekko.http.scaladsl.model._
import com.typesafe.scalalogging.{CanLog, Logger, LoggerTakingImplicit}
import org.slf4j.{LoggerFactory, MDC}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.moia.scalaHttpClient

import akka.http.scaladsl.model._
import org.apache.pekko.http.scaladsl.model._
import org.mockserver.matchers.Times
import org.mockserver.model.HttpRequest.request
import org.mockserver.model.HttpResponse.response
Expand Down
6 changes: 3 additions & 3 deletions src/test/scala/io/moia/scalaHttpClient/TestSetup.scala
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package io.moia.scalaHttpClient

import java.time.Clock
import akka.actor.typed.ActorSystem
import akka.actor.typed.scaladsl.Behaviors
import akka.http.scaladsl.model.{HttpMethod, HttpResponse, Uri}
import org.apache.pekko.actor.typed.ActorSystem
import org.apache.pekko.actor.typed.scaladsl.Behaviors
import org.apache.pekko.http.scaladsl.model.{HttpMethod, HttpResponse, Uri}
import org.scalatest.matchers.should.Matchers
import org.scalatest.wordspec.AnyWordSpecLike

Expand Down