Does not appear to work with Akka 2.5.3
RichardHightower opened this issue · 2 comments
RichardHightower commented
> Task :userAliasService:run
Exception in thread "main" java.lang.Exception: Could not recognise the transformer: [none]
at com.romix.akka.serialization.kryo.KryoSerializer.$anonfun$transform$1(KryoSerializer.scala:288)
at scala.collection.immutable.List.map(List.scala:283)
at com.romix.akka.serialization.kryo.KryoSerializer.<init>(KryoSerializer.scala:292)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at akka.actor.ReflectiveDynamicAccess.$anonfun$createInstanceFor$1(ReflectiveDynamicAccess.scala:32)
at scala.util.Try$.apply(Try.scala:209)
at akka.actor.ReflectiveDynamicAccess.createInstanceFor(ReflectiveDynamicAccess.scala:27)
at akka.actor.ReflectiveDynamicAccess.$anonfun$createInstanceFor$4(ReflectiveDynamicAccess.scala:38)
at scala.util.Success.flatMap(Try.scala:247)
at akka.actor.ReflectiveDynamicAccess.createInstanceFor(ReflectiveDynamicAccess.scala:38)
Build...
ext {
scalaVersion = "2.12"
akkaVersion = "2.5.3"
akkaHttpVersion = "10.0.9"
}
apply plugin: 'scala'
apply plugin: 'application'
mainClassName = "com.rick.user.RunServer"
repositories {
mavenCentral()
jcenter()
}
dependencies {
compile project(':userModel')
compile "com.github.romix.akka:akka-kryo-serialization_$scalaVersion:0.5.1"
//Added akka remote
compile "com.typesafe.akka:akka-remote_$scalaVersion:$akkaVersion"
compile "org.scala-lang:scala-library:$scalaVersion"
compile "com.typesafe.akka:akka-actor_$scalaVersion:$akkaVersion"
testCompile "com.typesafe.akka:akka-testkit_$scalaVersion:$akkaVersion"
testCompile "org.scalatest:scalatest_$scalaVersion:3.0.3"
}
Config
akka {
actor {
provider = remote
serializers {
kryo = "com.romix.akka.serialization.kryo.KryoSerializer"
}
kryo {
# Possibles values for type are: graph or nograph
type = "nograph"
idstrategy = "incremental"
buffer-size = 4096
max-buffer-size = -1
use-manifests = false
use-unsafe = false
post-serialization-transformations = "none"
implicit-registration-logging = false
kryo-trace = false
}
}
remote {
netty.tcp {
hostname = "127.0.0.1"
port = 7000
}
}
}
Complete code
package com.rick.user
import akka.actor.{Actor, ActorRef, ActorSystem, Props}
object UserAliasActor {
def apply(system: ActorSystem, localOnly: Boolean = false): ActorRef = {
if (localOnly) {
system.actorOf(props())
} else {
system.actorOf(props(), "userAlias")
}
}
def props(): Props = Props[UserAliasActor]
}
class UserAliasActor extends Actor {
/** Map that holds mappings to response data from user id. */
val userIdToResponseMap: Map[String, UserResponse] = Map(
("1234", UserResponse("ABC", Seq()))
)
/** Map that holds mappings to userId from userAlias. */
val userAliasMap: Map[String, String] = Map(
("ABC", "1234")
)
def receive: Receive = {
//Grab the sender (for tell and ask), and send a response from the map.
// sender refers to actor who sent the message.
case UserId(userId) =>
sender ! userIdToResponseMap(userId)
case UserAlias(userAlias) =>
sender ! userIdToResponseMap(userAliasMap(userAlias))
}
}
package com.rick.user
import akka.actor.{ActorRef, ActorSystem}
import akka.stream.ActorMaterializer
import com.typesafe.config.ConfigFactory
import scala.concurrent.ExecutionContextExecutor
import scala.io.StdIn
object RunServer extends App {
val config = if (args.length > 0) {
ConfigFactory.load(args(0))
} else {
ConfigFactory.load("user-alias-application.conf")
}
implicit val system = ActorSystem("UserAliasServer", config)
implicit val materializer = ActorMaterializer()
// needed for the future flatMap/onComplete in the end
implicit val executionContext: ExecutionContextExecutor = system.dispatcher
val userAliasActorRef: ActorRef = UserAliasActor(system)
sys.addShutdownHook({
system.terminate()
})
}
luben commented
try to remove the post-serialization-transformations = "none"
from your config file - by default there no transformations are applied. If you want to explicitly disable it, then add: post-serialization-transformations = "off"
danischroeter commented
Cleanup... No feedback - seems outdated. Please reopen if necessary.