richardhightower / akka-ec2-example Goto Github PK
View Code? Open in Web Editor NEWCreate Simple Akka EC2 Examples
Create Simple Akka EC2 Examples
> 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()
})
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.