Skip to content

techmonad/akka-kryo-serialization-sample

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

akka-kryo-serialization-sample

  1. Add library dependency to build.sbt:
libraryDependencies ++= Seq(
  "com.github.romix.akka" %% "akka-kryo-serialization" % "0.5.1"
)
  1. Update application.conf
akka {
  extensions = ["com.romix.akka.serialization.kryo.KryoSerializationExtension$"]
  actor {
    serializers {
      kryo = "com.romix.akka.serialization.kryo.KryoSerializer"
    }

    serialization-bindings {
      // classes to be serialized
      "com.techmonad.service.WordCountActor$Request" = kryo,
      "com.techmonad.service.WordCountActor$Response" = kryo

    }
  }

}
  1. Testing: Akka does not serialized messages in a same JVM(sender actor and receiver actor are on same JVM). for testing purpose just enable serialize-messages flag.
akka {
  actor {
    extensions = ["com.romix.akka.serialization.kryo.KryoSerializationExtension$"]
    **//only for testing, don't on for prduction**
    serialize-messages = on


    serializers {
      kryo = "com.romix.akka.serialization.kryo.KryoSerializer"
    }

    serialization-bindings {
      "com.techmonad.service.WordCountActor$Request" = kryo,
      "com.techmonad.service.WordCountActor$Response" = kryo

    }
  }

}
  1. Actor Unit test:
import akka.actor.{ActorSystem, Props}
import akka.testkit.{ImplicitSender, TestKit}
import org.scalatest.{BeforeAndAfterAll, Matchers, WordSpecLike}

import scala.concurrent.duration._

class WordCountActorSpec extends TestKit(ActorSystem("WordCountActorSpec")) with ImplicitSender
  with WordSpecLike with Matchers with BeforeAndAfterAll {

  import WordCountActor._

  "WordCountActor " should {
    " count " in {
      val wordCountActor = system.actorOf(Props[WordCountActor], "wordCountActor")
      wordCountActor ! Request("hello hello")
      expectMsg[Response](1.seconds, Response(Map("hello" ->2)))
    }

  }

  override protected def afterAll(): Unit = {
    TestKit.shutdownActorSystem(system)
  }
}

About

Akka messages serialization using Romix’s kryo-based serialization library.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages