Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to Apache Pekko #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ $ ./runNode2.sh
* Observe the logs. You will know your cluster has successfully formed when the first node (running on port 2551) reports:

```
Node [akka://Loyalty@127.0.0.1:2552] is JOINING, roles [dc-default]
Leader is moving node [akka://Loyalty@127.0.0.1:2552] to [Up]
Node [pekko://Credibility@127.0.0.1:2552] is JOINING, roles [dc-default]
Leader is moving node [pekko://Credibility@127.0.0.1:2552] to [Up]
```

* The second node (running on port 2552) should report:

```
Cluster Node [akka://Loyalty@127.0.0.1:2552] - Welcome from [akka://Loyalty@127.0.0.1:2551]
Cluster Node [pekko://Credibility@127.0.0.1:2552] - Welcome from [pekko://Credibility@127.0.0.1:2551]
```

2. At this point, we have enabled Akka Clustering in our application. This creates the foundation for other Akka features such as Akka Cluster Sharding. Try the following experiment:
2. At this point, we have enabled Pekko Clustering in our application. This creates the foundation for other Pekko features such as Pekko Cluster Sharding. Try the following experiment:

```
$ ./credibility.sh -p 8000 -a sample credit 100
Expand Down
26 changes: 13 additions & 13 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ version := "0.2-SNAPSHOT"

scalaVersion := "2.13.6"

lazy val akkaHttpVersion = "10.2.6"
lazy val akkaVersion = "2.6.17"
lazy val akkaManagementVersion = "1.1.1"
lazy val pekkoHttpVersion = "1.0.1"
lazy val pekkoVersion = "1.0.3"
lazy val pekkoManagementVersion = "1.0.0"
lazy val logbackVersion = "1.2.6"
lazy val scalaTestVersion = "3.2.10"

Expand All @@ -21,21 +21,21 @@ scalacOptions ++= Seq(
)

libraryDependencies ++= Seq(
"com.typesafe.akka" %% "akka-http" % akkaHttpVersion,
"com.typesafe.akka" %% "akka-http-spray-json" % akkaHttpVersion,
"com.typesafe.akka" %% "akka-cluster" % akkaVersion,
"com.typesafe.akka" %% "akka-cluster-sharding"% akkaVersion,
"com.typesafe.akka" %% "akka-serialization-jackson" % akkaVersion,
"com.lightbend.akka.management" %% "akka-management" % akkaManagementVersion,
"com.lightbend.akka.management" %% "akka-management-cluster-http" % akkaManagementVersion,
"org.apache.pekko" %% "pekko-http" % pekkoHttpVersion,
"org.apache.pekko" %% "pekko-http-spray-json" % pekkoHttpVersion,
"org.apache.pekko" %% "pekko-cluster" % pekkoVersion,
"org.apache.pekko" %% "pekko-cluster-sharding"% pekkoVersion,
"org.apache.pekko" %% "pekko-serialization-jackson" % pekkoVersion,
"org.apache.pekko" %% "pekko-management" % pekkoManagementVersion,
"org.apache.pekko" %% "pekko-management-cluster-http" % pekkoManagementVersion,
"com.swissborg" %% "lithium" % "0.11.2",

//Logback
"com.typesafe.akka" %% "akka-slf4j" % akkaVersion,
"org.apache.pekko" %% "pekko-slf4j" % pekkoVersion,
"ch.qos.logback" % "logback-classic" % logbackVersion,

//Test dependencies
"com.typesafe.akka" %% "akka-http-testkit" % akkaHttpVersion % Test,
"com.typesafe.akka" %% "akka-testkit" % akkaVersion % Test,
"org.apache.pekko" %% "pekko-http-testkit" % pekkoHttpVersion % Test,
"org.apache.pekko" %% "pekko-testkit" % pekkoVersion % Test,
"org.scalatest" %% "scalatest" % scalaTestVersion% Test
)
2 changes: 1 addition & 1 deletion runNode1.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

set -x

sbt "run -Dakka.http.server.default-http-port=8000 -Dakka.remote.artery.canonical.port=2551 -Dakka.management.http.port=8558 -Dcinnamon.prometheus.http-server.port=9001"
sbt "run -Dpekko.http.server.default-http-port=8000 -Dpekko.remote.artery.canonical.port=2551 -Dpekko.management.http.port=8558 -Dcinnamon.prometheus.http-server.port=9001"
2 changes: 1 addition & 1 deletion runNode2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

set -x

sbt "run -Dakka.http.server.default-http-port=8001 -Dakka.remote.artery.canonical.port=2552 -Dakka.management.http.port=8559 -Dcinnamon.prometheus.http-server.port=9002"
sbt "run -Dpekko.http.server.default-http-port=8001 -Dpekko.remote.artery.canonical.port=2552 -Dpekko.management.http.port=8559 -Dcinnamon.prometheus.http-server.port=9002"
2 changes: 1 addition & 1 deletion runNode3.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

set -x

sbt "run -Dakka.http.server.default-http-port=8002 -Dakka.remote.artery.canonical.port=2553 -Dakka.management.http.port=8560 -Dcinnamon.prometheus.http-server.port=9003"
sbt "run -Dpekko.http.server.default-http-port=8002 -Dpekko.remote.artery.canonical.port=2553 -Dpekko.management.http.port=8560 -Dcinnamon.prometheus.http-server.port=9003"
14 changes: 7 additions & 7 deletions src/main/resources/application.conf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
akka {
loggers = ["akka.event.slf4j.Slf4jLogger"]
pekko {
loggers = ["org.apache.pekko.event.slf4j.Slf4jLogger"]
loglevel = "DEBUG"
logging-filter = "akka.event.slf4j.Slf4jLoggingFilter"
logging-filter = "org.apache.pekko.event.slf4j.Slf4jLoggingFilter"

http {
server {
Expand All @@ -13,7 +13,7 @@ akka {
provider = "cluster"

serialization-bindings {
"com.knoldus.credibility.SerializableMessage" = jackson-cbor
"com.nashtech.credibility.SerializableMessage" = jackson-cbor
}
}

Expand All @@ -29,11 +29,11 @@ akka {

cluster {
seed-nodes = [
"akka://[email protected]:2551",
"akka://[email protected]:2552"
"pekko://[email protected]:2551",
"pekko://[email protected]:2552"
]

downing-provider-class = "com.swissborg.lithium.DowningProviderImpl"
downing-provider-class = "org.apache.pekko.cluster.sbr.SplitBrainResolverProvider"
}

management {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.knoldus.credibility
package com.nashtech.credibility

import akka.actor.{Actor, ActorLogging, Props, Stash}
import akka.pattern.pipe
import org.apache.pekko.actor.{Actor, ActorLogging, Props, Stash}
import org.apache.pekko.pattern.pipe

object CredibilityActor {
sealed trait Command extends SerializableMessage
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.knoldus.credibility
package com.nashtech.credibility

import akka.actor.{Actor, ActorRef, Props}
import akka.cluster.sharding.ShardRegion.{ExtractEntityId, ExtractShardId}
import org.apache.pekko.actor.{Actor, ActorRef, Props}
import org.apache.pekko.cluster.sharding.ShardRegion.{ExtractEntityId, ExtractShardId}

object CredibilityActorSupervisor {
case class Deliver(command: CredibilityActor.Command, to: CredibilityId) extends SerializableMessage
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.knoldus.credibility
package com.nashtech.credibility

case class CredibilityId(value: String)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.knoldus.credibility
package com.nashtech.credibility

import java.io._
import java.nio.file.{Files, Path, Paths}

import akka.Done
import org.apache.pekko.Done

import scala.concurrent.{ExecutionContext, Future}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.knoldus.credibility
package com.nashtech.credibility

import akka.actor.ActorRef
import akka.http.scaladsl.model.StatusCodes
import akka.pattern.ask
import akka.http.scaladsl.server.Directives._
import akka.http.scaladsl.server.Route
import akka.util.Timeout
import com.knoldus.credibility.CredibilityActor.{CredibilityAdjustmentApplied, CredibilityAdjustmentRejected}
import org.apache.pekko.actor.ActorRef
import org.apache.pekko.http.scaladsl.model.StatusCodes
import org.apache.pekko.pattern.ask
import org.apache.pekko.http.scaladsl.server.Directives._
import org.apache.pekko.http.scaladsl.server.Route
import org.apache.pekko.util.Timeout
import CredibilityActor.{CredibilityAdjustmentApplied, CredibilityAdjustmentRejected}

import scala.concurrent.ExecutionContext
import scala.concurrent.duration._
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.knoldus.credibility
package com.nashtech.credibility

import java.nio.file.Paths
import akka.actor.ActorSystem
import akka.cluster.sharding.{ClusterSharding, ClusterShardingSettings}
import akka.http.scaladsl.Http
import akka.management.scaladsl.AkkaManagement
import org.apache.pekko.actor.ActorSystem
import org.apache.pekko.cluster.sharding.{ClusterSharding, ClusterShardingSettings}
import org.apache.pekko.http.scaladsl.Http
import org.apache.pekko.management.scaladsl.PekkoManagement
import com.typesafe.config.ConfigFactory
import org.slf4j.LoggerFactory

Expand All @@ -20,7 +20,7 @@ object Main extends App {

implicit val system: ActorSystem = ActorSystem("Credibility")

AkkaManagement(system).start()
PekkoManagement(system).start()

val rootPath = Paths.get("tmp")
val credibilityRepository: CredibilityRepository = new FileBasedCredibilityRepository(rootPath)(system.dispatcher)
Expand All @@ -35,6 +35,6 @@ object Main extends App {

val credibilityRoutes = new CredibilityRoutes(credibilityActorSupervisor)(system.dispatcher)

private val port: Int = ConfigFactory.load().getInt("akka.http.server.default-http-port")
private val port: Int = ConfigFactory.load().getInt("pekko.http.server.default-http-port")
Http().newServerAt("localhost", port).bindFlow(credibilityRoutes.routes)
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.knoldus.credibility
package com.nashtech.credibility

import com.fasterxml.jackson.annotation.JsonTypeInfo

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.knoldus.credibility
package com.nashtech.credibility

import akka.actor.ActorSystem
import akka.util.Timeout
import org.apache.pekko.actor.ActorSystem
import org.apache.pekko.util.Timeout
import org.scalatest.{BeforeAndAfterAll, Suite}

import scala.concurrent.duration._
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.knoldus.credibility
package com.nashtech.credibility

import akka.pattern.ask
import org.apache.pekko.pattern.ask
import org.scalatest.concurrent.ScalaFutures
import org.scalatest.wordspec.AnyWordSpec

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.knoldus.credibility
package com.nashtech.credibility

import java.util.UUID

import akka.Done
import akka.actor.ActorRef
import akka.pattern.ask
import com.knoldus.credibility.CredibilityActor.CredibilityAdjustmentRejected
import org.apache.pekko.Done
import org.apache.pekko.actor.ActorRef
import org.apache.pekko.pattern.ask
import CredibilityActor.CredibilityAdjustmentRejected
import org.scalatest.concurrent.ScalaFutures
import org.scalatest.wordspec.AnyWordSpec

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.knoldus.credibility
package com.nashtech.credibility

import org.scalatest.wordspec.AnyWordSpec

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.knoldus.credibility
package com.nashtech.credibility

import java.nio.file.{Files, Path}
import java.util.UUID
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.knoldus.credibility
package com.nashtech.credibility

import akka.http.scaladsl.model.{ContentTypes, StatusCodes}
import akka.http.scaladsl.testkit.ScalatestRouteTest
import akka.testkit.{TestActor, TestProbe}
import com.knoldus.credibility.CredibilityActorSupervisor.Deliver
import org.apache.pekko.http.scaladsl.model.{ContentTypes, StatusCodes}
import org.apache.pekko.http.scaladsl.testkit.ScalatestRouteTest
import org.apache.pekko.testkit.{TestActor, TestProbe}
import CredibilityActorSupervisor.Deliver
import org.scalatest.wordspec.AnyWordSpec

class CredibilityRoutesTest
Expand Down