Akka(6)Remote Actor - akka-sample-remote-scala
Akka(6)Remote Actor - akka-sample-remote-scala
1. Installation of Akka
Download the akka_2.10-2.3.4.zip, put it in the working place.
Deploy my jar to the deploy directory.
>cp target/scala-2.10/sillycat-akka_2.10-1.0.jar /opt/akka/deploy/
The configuration file is in /opt/akka/config/application.conf
2. Find the Example
http://www.typesafe.com/platform/getstarted
After run activator I can create a sample project of remote akka with the search name of akka-sample-remote-scala
activator is really a good tool. I will try to use that later.
After that I have this project on my local akka-sample-remote-scala
And here are a lot of other examples https://github.com/akka/akka/tree/master/akka-samples
3. Implementation
Reading code from akka-sample-remote-scala
4. Deployment
Error Message
bin/akka com.sillycat.akka.server.EventServiceRemoteApp Exception in thread "main" java.lang.NoClassDefFoundError: scala/Function1 at akka.kernel.Main.main(Main.scala) Caused by: java.lang.ClassNotFoundException: scala.Function1 at java.net.URLClassLoader$1.run(URLClassLoader.java:366) at java.net.URLClassLoader$1.run(URLClassLoader.java:355) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:354) at java.lang.ClassLoader.loadClass(ClassLoader.java:425) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
Solution:
[ -n "$AKKA_CLASSPATH" ] || AKKA_CLASSPATH="$AKKA_HOME/lib/scala-library-2.10.4.jar:$AKKA_HOME/config:$AKKA_HOME/lib/akka/*"
Finally I found that because we did not find the scala-library because of the version name. so I change it to scala-library-2.10.4.jar.
Then it runs, but it complains about some ClassNotFound Exception. So I deploy the assembly jar there.
>bin/akka com.sillycat.akka.server.EventServiceRemoteApp
It runs and the codes are in sample project sillycat-akka.
Warning Message
Successfully started Akka SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder". SLF4J: Defaulting to no-operation (NOP) logger implementation SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Solution:
Go the lib/akka directory
>wget http://central.maven.org/maven2/org/slf4j/slf4j-log4j12/1.7.7/slf4j-log4j12-1.7.7.jar
>rm -fr slf4j-api-1.7.5.jar
>wget http://central.maven.org/maven2/org/slf4j/slf4j-log4j12/1.7.7/slf4j-log4j12-1.7.7.jar
>mkdir install
>cd install/
>wget http://apache.mirrors.lucidnetworks.net/logging/log4j/1.2.17/log4j-1.2.17.tar.gz
>tar zxvf log4j-1.2.17.tar.gz
>cp apache-log4j-1.2.17/log4j-1.2.17.jar ../
Make sure these jars are there under lib/akka/
log4j-1.2.17.jar
slf4j-api-1.7.7.jar
slf4j-log4j12-1.7.7.jar
About the Logging Message
Running sbt in debug Level
>sbt test --debug
Actually my logging information is not showing because I am using slf4j-simple
My dependencies are as follow:
"com.typesafe" %% "scalalogging-slf4j" % "1.0.1",
"org.slf4j" % "slf4j-simple" % "1.7.7",
//"org.slf4j" % "slf4j-log4j12" % "1.7.7",
"org.slf4j" % "slf4j-api" % "1.7.7",
The configuration file should be as follow, and the file name should be simple logger.properties:
# SLF4J's SimpleLogger configuration file
# Simple implementation of Logger that sends all enabled log messages, for all defined loggers, to System.err.
# Default logging detail level for all instances of SimpleLogger.
# Must be one of ("trace", "debug", "info", "warn", or "error").
# If not specified, defaults to "info".
org.slf4j.simpleLogger.defaultLogLevel=debug
# Logging detail level for a SimpleLogger instance named "xxxxx".
# Must be one of ("trace", "debug", "info", "warn", or "error").
# If not specified, the default logging detail level is used.
#org.slf4j.simpleLogger.log.xxxxx=
# Set to true if you want the current date and time to be included in output messages.
# Default is false, and will output the number of milliseconds elapsed since startup.
#org.slf4j.simpleLogger.showDateTime=false
# The date and time format to be used in the output messages.
# The pattern describing the date and time format is the same that is used in java.text.SimpleDateFormat.
# If the format is not specified or is invalid, the default format is used.
# The default format is yyyy-MM-dd HH:mm:ss:SSS Z.
#org.slf4j.simpleLogger.dateTimeFormat=yyyy-MM-dd HH:mm:ss:SSS Z
# Set to true if you want to output the current thread name.
# Defaults to true.
#org.slf4j.simpleLogger.showThreadName=true
# Set to true if you want the Logger instance name to be included in output messages.
# Defaults to true.
#org.slf4j.simpleLogger.showLogName=true
# Set to true if you want the last component of the name to be included in output messages.
# Defaults to false.
#org.slf4j.simpleLogger.showShortLogName=false
If I want the log4j working, I need to change the dependencies as follow:
"com.typesafe" %% "scalalogging-slf4j" % "1.0.1",
"org.slf4j" % "slf4j-simple" % "1.7.7",
//"org.slf4j" % "slf4j-log4j12" % "1.7.7",
"org.slf4j" % "slf4j-api" % "1.7.7",
Error Message:
[INFO] [08/11/2014 14:40:35.887] [EventServiceLocalSystem-akka.actor.default-dispatcher-2] [akka://EventServiceLocalSystem/deadLetters] Message [com.sillycat.akka.model.EventMessage] from Actor[akka://EventServiceLocalSystem/temp/$a] to Actor[akka://EventServiceLocalSystem/deadLetters] was not delivered. [1] dead letters encountered. This logging can be turned off or adjusted with configuration settings 'akka.log-dead-letters' and 'akka.log-dead-letters-during-shutdown'.
Error Message:
Can't serialize a non-protobuf message using protobuf
Solution:
"com.typesafe.akka" %% "akka-remote" % "2.3.4"
It is not working if I deploy to akka and run with bin/akka.
5. Another Example
Search for akka-sample-cluster-scala
References:
http://agiledon.github.io/blog/2014/02/18/remote-actor-in-akka/
http://java.dzone.com/articles/how-configure-slf4j-different
http://sillycat.iteye.com/blog/2100232
http://doc.akka.io/docs/akka/snapshot/scala/remoting.html#remote-configuration-scala
http://doc.akka.io/docs/akka/snapshot/scala/remoting.html
Serialization
http://doc.akka.io/docs/akka/snapshot/scala/serialization.html#serialization-scala
http://www.typesafe.com/activator/template/akka-sample-remote-scala?_ga=1.191183337.2134491737.1406929595
http://alvinalexander.com/scala/simple-akka-actors-remote-example
http://alvinalexander.com/scala/akka-remote-sending-objects-messages
https://github.com/alvinj/AkkaRemoteActorsHelloWorld.git
https://typesafe.com/activator/template/akka-sample-cluster-scala
http://doc.akka.io/docs/akka/2.1.2/cluster/cluster-usage-scala.html
http://tersesystems.com/2014/06/25/akka-clustering/