Skip to content

Commit dfac25e

Browse files
committed
Migrate from Akka to Pekko.
1 parent 1e3ac51 commit dfac25e

File tree

15 files changed

+65
-67
lines changed

15 files changed

+65
-67
lines changed

.gitignore

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,6 @@ native/
3232
# Log files
3333
*.log
3434

35-
# Akka Persistence
36-
snapshots
37-
3835
# jenv
3936
.java-version
4037
.bloop

README.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# Scala-HTTP-Client
1+
# Scala-Pekko-HTTP-Client
22

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

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

12-
![Build & Test](https://github.com/moia-oss/scala-http-client/workflows/Build%20&%20Test/badge.svg)
13-
[![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)
12+
![Build & Test](https://github.com/moia-oss/scala-pekko-http-client/workflows/Build%20&%20Test/badge.svg)
13+
[![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)
1414
[![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)
1515

1616
## Usage
1717

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

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

6363

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

111111
## Custom Headers
112112

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

115115
```scala
116-
import akka.http.scaladsl.model.headers.{ModeledCustomHeader, ModeledCustomHeaderCompanion}
116+
import org.apache.pekko.http.scaladsl.model.headers.{ModeledCustomHeader, ModeledCustomHeaderCompanion}
117117
import scala.util.Try
118118

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

151151
## Publishing
152152

153-
[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`).
153+
[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`).
154154

155155
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.
156156

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

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

167-
Afterwards, add the release to [GitHub](https://github.com/moia-oss/scala-http-client/releases).
167+
Afterwards, add the release to [GitHub](https://github.com/moia-oss/scala-pekko-http-client/releases).

build.sbt

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
lazy val root = (project in file("."))
22
.settings(
3-
name := "scala-http-client",
3+
name := "scala-pekko-http-client",
44
organization := "io.moia",
55
licenses += ("Apache-2.0", url("https://www.apache.org/licenses/LICENSE-2.0")),
6-
scmInfo := Some(ScmInfo(url("https://github.com/moia-oss/scala-http-client"), "scm:[email protected]:moia-oss/scala-http-client.git")),
7-
homepage := Some(url("https://github.com/moia-oss/scala-http-client")),
6+
scmInfo := Some(ScmInfo(url("https://github.com/moia-oss/scala-pekko-http-client"), "scm:[email protected]:moia-oss/scala-pekko-http-client.git")),
7+
homepage := Some(url("https://github.com/moia-oss/scala-pekko-http-client")),
88
scalaVersion := "2.13.11",
99
crossScalaVersions := List("2.12.18", "2.13.11"),
1010
versionScheme := Some("early-semver"),
@@ -15,7 +15,7 @@ lazy val root = (project in file("."))
1515
case _ => Seq()
1616
}
1717
},
18-
libraryDependencies ++= akkaDependencies ++ awsDependencies ++ testDependencies ++ loggingDependencies ++ scalaDependencies
18+
libraryDependencies ++= pekkoDependencies ++ awsDependencies ++ testDependencies ++ loggingDependencies ++ scalaDependencies
1919
)
2020
.settings(sonatypeSettings: _*)
2121
.configs(IntegrationTest)
@@ -31,15 +31,15 @@ lazy val root = (project in file("."))
3131
)
3232
.settings(mimaSettings)
3333

34-
val akkaVersion = "2.6.19"
35-
val akkaHttpVersion = "10.2.10"
34+
val pekkoVersion = "1.0.1"
35+
val pekkoHttpVersion = "1.0.0"
3636

37-
lazy val akkaDependencies = Seq(
38-
"com.typesafe.akka" %% "akka-stream" % akkaVersion,
39-
"com.typesafe.akka" %% "akka-stream-typed" % akkaVersion,
40-
"com.typesafe.akka" %% "akka-http" % akkaHttpVersion,
41-
"com.typesafe.akka" %% "akka-testkit" % akkaVersion % Test,
42-
"com.typesafe.akka" %% "akka-http-testkit" % akkaHttpVersion % Test
37+
lazy val pekkoDependencies = Seq(
38+
"org.apache.pekko" %% "pekko-stream" % pekkoVersion,
39+
"org.apache.pekko" %% "pekko-stream-typed" % pekkoVersion,
40+
"org.apache.pekko" %% "pekko-http" % pekkoHttpVersion,
41+
"org.apache.pekko" %% "pekko-testkit" % pekkoVersion % Test,
42+
"org.apache.pekko" %% "pekko-http-testkit" % pekkoHttpVersion % Test
4343
)
4444

4545
lazy val awsJavaSdkVersion = "2.20.153"
@@ -104,7 +104,7 @@ lazy val sonatypeSettings = {
104104
publishTo := sonatypePublishTo.value,
105105
sonatypeProfileName := organization.value,
106106
publishMavenStyle := true,
107-
sonatypeProjectHosting := Some(GitHubHosting("moia-oss", "scala-http-client", "[email protected]")),
107+
sonatypeProjectHosting := Some(GitHubHosting("moia-oss", "scala-pekko-http-client", "[email protected]")),
108108
credentials += Credentials(Path.userHome / ".sbt" / "sonatype_credential")
109109
)
110110
}
@@ -124,5 +124,5 @@ lazy val sbtGitSettings = Seq(
124124
)
125125

126126
lazy val mimaSettings = Seq(
127-
mimaPreviousArtifacts := Set("io.moia" %% "scala-http-client" % "5.0.0")
127+
mimaPreviousArtifacts := Set("io.moia" %% "scala-pekko-http-client" % "1.0.0")
128128
)

src/it/scala/io/moia/scalaHttpClient/HeaderExample.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package io.moia.scalaHttpClient
22

3-
import akka.actor.typed.ActorSystem
4-
import akka.actor.typed.scaladsl.Behaviors
5-
import akka.http.scaladsl.model._
6-
import akka.http.scaladsl.model.headers.{ModeledCustomHeader, ModeledCustomHeaderCompanion}
7-
import akka.http.scaladsl.unmarshalling.{Unmarshal, Unmarshaller}
3+
import org.apache.pekko.actor.typed.ActorSystem
4+
import org.apache.pekko.actor.typed.scaladsl.Behaviors
5+
import org.apache.pekko.http.scaladsl.model._
6+
import org.apache.pekko.http.scaladsl.model.headers.{ModeledCustomHeader, ModeledCustomHeaderCompanion}
7+
import org.apache.pekko.http.scaladsl.unmarshalling.{Unmarshal, Unmarshaller}
88
import io.moia.scalaHttpClient.ExampleModel.{DomainErrorObject, GatewayException, MySuccessObject}
99

1010
import java.time.Clock

src/it/scala/io/moia/scalaHttpClient/LoggingExample.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package io.moia.scalaHttpClient
22

3-
import akka.actor.typed.ActorSystem
4-
import akka.actor.typed.scaladsl.Behaviors
5-
import akka.http.scaladsl.model._
3+
import org.apache.pekko.actor.typed.ActorSystem
4+
import org.apache.pekko.actor.typed.scaladsl.Behaviors
5+
import org.apache.pekko.http.scaladsl.model._
66
import com.typesafe.scalalogging._
77
import io.moia.scalaHttpClient.CustomLogging.LoggingContext
88
import org.slf4j.LoggerFactory

src/it/scala/io/moia/scalaHttpClient/SimpleExample.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package io.moia.scalaHttpClient
22

3-
import akka.actor.typed.ActorSystem
4-
import akka.actor.typed.scaladsl.Behaviors
5-
import akka.http.scaladsl.model._
6-
import akka.http.scaladsl.unmarshalling.{Unmarshal, Unmarshaller}
3+
import org.apache.pekko.actor.typed.ActorSystem
4+
import org.apache.pekko.actor.typed.scaladsl.Behaviors
5+
import org.apache.pekko.http.scaladsl.model._
6+
import org.apache.pekko.http.scaladsl.unmarshalling.{Unmarshal, Unmarshaller}
77
import io.moia.scalaHttpClient.ExampleModel.{DomainErrorObject, GatewayException, MySuccessObject}
88

99
import java.time.Clock

src/main/scala/io/moia/scalaHttpClient/AwsRequestSigner.scala

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package io.moia.scalaHttpClient
22

3-
import akka.http.scaladsl.model.HttpHeader.ParsingResult
4-
import akka.http.scaladsl.model.{HttpHeader, HttpRequest, Uri}
5-
import akka.stream.Materializer
6-
import akka.stream.scaladsl.StreamConverters
3+
import org.apache.pekko.http.scaladsl.model.HttpHeader.ParsingResult
4+
import org.apache.pekko.http.scaladsl.model.{HttpHeader, HttpRequest, Uri}
5+
import org.apache.pekko.stream.Materializer
6+
import org.apache.pekko.stream.scaladsl.StreamConverters
77
import com.typesafe.scalalogging.StrictLogging
88
import software.amazon.awssdk.auth.credentials._
99
import software.amazon.awssdk.auth.signer.{Aws4Signer, AwsSignerExecutionAttribute}
@@ -57,13 +57,13 @@ class AwsRequestSigner private (credentialsProvider: AwsCredentialsProvider, reg
5757
/** Checks if the given collection of `HttpHeader`s includes one "Authorization" header
5858
*
5959
* @param headers
60-
* `Seq[HttpHeader]` headers of an Akka `HttpRequest`
60+
* `Seq[HttpHeader]` headers of a Pekko `HttpRequest`
6161
* @return
6262
* true if "Authorization" header exists
6363
*/
6464
private def isAlreadyAuthorized(headers: Seq[HttpHeader]): Boolean = headers.exists(_.is("authorization"))
6565

66-
/** Constructs an `SdkHttpFullRequest` from Akka's `HttpRequest` for signing.
66+
/** Constructs an `SdkHttpFullRequest` from Pekko's `HttpRequest` for signing.
6767
*
6868
* @param request
6969
* HttpRequest to convert
@@ -94,7 +94,7 @@ class AwsRequestSigner private (credentialsProvider: AwsCredentialsProvider, reg
9494
.build()
9595
}
9696

97-
/** Extracts the headers from the `SdkHttpFullRequest` as collection of Akka's `HttpHeader`s
97+
/** Extracts the headers from the `SdkHttpFullRequest` as collection of Pekko's `HttpHeader`s
9898
*
9999
* @param signedSdkRequest
100100
* `SdkHttpFullRequest` after signing

src/main/scala/io/moia/scalaHttpClient/HttpClient.scala

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
package io.moia.scalaHttpClient
22

3-
import akka.actor.typed.ActorSystem
4-
import akka.http.scaladsl.Http
5-
import akka.http.scaladsl.model._
6-
import akka.http.scaladsl.model.headers.{`Retry-After`, RetryAfterDateTime, RetryAfterDuration}
73
import com.typesafe.scalalogging.{Logger, LoggerTakingImplicit}
4+
import org.apache.pekko.actor.typed.ActorSystem
5+
import org.apache.pekko.http.scaladsl.Http
6+
import org.apache.pekko.http.scaladsl.model._
7+
import org.apache.pekko.http.scaladsl.model.headers.{`Retry-After`, RetryAfterDateTime, RetryAfterDuration}
8+
import org.apache.pekko.pattern.after
89
import org.slf4j.LoggerFactory
910

1011
import java.time.Clock
@@ -148,7 +149,7 @@ abstract class HttpLayer[LoggingContext](
148149
Future.successful(DeadlineExpired(Some(response)))
149150
} else {
150151
logger.info(s"[$name] Try #$tryNum: Retrying in ${delay.toMillis}ms.")
151-
akka.pattern.after(delay)(executeRequest(request, tryNum + 1, deadline))
152+
after(delay)(executeRequest(request, tryNum + 1, deadline))
152153
}
153154
} else {
154155
logger.info(s"[$name] Try #$tryNum: No retries left. Giving up.")
@@ -173,7 +174,7 @@ abstract class HttpLayer[LoggingContext](
173174
case NonFatal(e) if tryNum <= retryConfig.retriesException =>
174175
val delay: FiniteDuration = calculateDelay(None, tryNum)
175176
logger.info(s"[$name] Exception in request: ${e.getMessage}, retrying in ${delay.toMillis}ms.", e)
176-
akka.pattern.after(delay)(executeRequest(request, tryNum + 1, deadline))
177+
after(delay)(executeRequest(request, tryNum + 1, deadline))
177178
case NonFatal(e) =>
178179
logger.warn(s"[$name] Exception in request: ${e.getMessage}, retries exhausted, giving up.", e)
179180
Future.successful(ExceptionOccurred(e))

src/main/scala/io/moia/scalaHttpClient/HttpClientConfig.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ final case class HttpClientConfig(
3939
* @param retriesServerError
4040
* Number of retries for all other 5xx codes
4141
* @param retriesException
42-
* Number of retries for exceptions in the underlying akka-http client
42+
* Number of retries for exceptions in the underlying pekko-http client
4343
* @param initialBackoff
4444
* Time to wait until the first retry. Is multiplied with 2^(# of retry). Example: 10ms * 2^0 => 10ms 10ms * 2^1 => 20ms 10ms * 2^2 => 40ms 10ms * 2^3 =>
4545
* 80ms 10ms * 2^4 => 160ms

src/main/scala/io/moia/scalaHttpClient/HttpMetrics.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package io.moia.scalaHttpClient
22

3-
import akka.http.scaladsl.model.{HttpMethod, HttpResponse, Uri}
3+
import org.apache.pekko.http.scaladsl.model.{HttpMethod, HttpResponse, Uri}
44

55
trait HttpMetrics[LoggingContext] {
66
def meterResponse(method: HttpMethod, path: Uri.Path, response: HttpResponse)(implicit ctx: LoggingContext): Unit

0 commit comments

Comments
 (0)