Giter Club home page Giter Club logo

akka-ec2-example's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

joyoyoyoyoyo

akka-ec2-example's Issues

kyro serialization - Does not appear to work with Akka 2.5.4


> 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()
  })

}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.