Skip to content

Latest commit

 

History

History
220 lines (191 loc) · 14.6 KB

README.md

File metadata and controls

220 lines (191 loc) · 14.6 KB

Book Akka Essentials

Akka project Directory akka-essentials\ contains Akka code examples from Gupta's book Akka Essentials (Packt, 2012).
It also includes different build scripts for experimenting with Akka on a Windows machine.

The code examples presented below are written both in Java and in Scala and can be built/run with the following tools:

Build tool Build file Parent file Environment(s)
ant.bat build.xml build.xml Any a)
gradle.bat build.gradle common.gradle Any
make.exe b) Makefile Makefile.inc Any
mvn.cmd pom.xml pom.xml Any
sbt.bat build.sbt   Any
cmd.exe build.bat   Windows only
a) Here "Any" means "tested on Windows, Cygwin, MSYS2 and UNIX".
b) Default shell is /bin/sh as described in the online document Choosing the Shell.
 

FirstAkkaApplication Example

Code example FirstAkkaApplication1 is an Akka application written in Java (e.g. MapReduceApplication.java, MasterActor.java2).

Batch file build.bat matches what the user would run from the command prompt (use option -debug to see the execution details):

> build -verbose run
Compile 9 Java source files to directory "target\classes"
[MapReduceApp-akka.actor.default-dispatcher-4] INFO akka.event.slf4j.Slf4jLogger - Slf4jLogger started
{over=1, quick=1, belong=1, lazy=1, best=1, man's=1, brown=1, fox=2, fell=1, tried=1, same=1, friend=1, family=1, dog=4, jump=1}

Commands ant.bat (build.xml), gradle.bat (build.gradle), make (Makefile), mvn (pom.xml) and sbt (build.sbt) produce the same output; for instance :

> make -s run
{over=1, quick=1, belong=1, lazy=1, best=1, man's=1, brown=1, fox=2, fell=1, tried=1, same=1, friend=1, family=1, dog=4, jump=1}

🔎 FirstAkkaApplicationScala is the same Akka application written in Scala (e.g. MapReduceApplication.scala, MasterActor.scala). For instance build.bat generates the following output:  

> build run
[MapReduceApp-akka.actor.default-dispatcher-4] INFO akka.event.slf4j.Slf4jLogger - Slf4jLogger started
HashMap(over -> 1, quick -> 1, belong -> 1, lazy -> 1, best -> 1, man's -> 1, brown -> 1, fox -> 2, fell -> 1, tried -> 1, same -> 1, friend -> 1, family -> 1, dog -> 4, jump -> 1)

ProcessOrder Example

Code example ProcessOrder is an Akka application written in Java (e.g. ProcessOrderApp.java, ProcessOrderActor.java).

Batch file build.bat matches what the user would run from the command prompt (use option -debug to see the execution details):

> build -verbose run
Compile 8 Java source files to directory "target\classes"
[ProcessOrder-akka.actor.default-dispatcher-5] INFO akka.event.slf4j.Slf4jLogger - Slf4jLogger started
OrderActor: userId=1
OrderAggregate: akka.actor.Status$Failure

🔎 Code example ProcessOrderScala is the same Akka application written in Scala (e.g. MapReduceApplication.scala, MasterActor.scala). For instance build.bat generates the following output :  

> build run
...

PingPong Example

Code example PingPong is an Akka application written in Java (e.g. PingPongApp.java, PingPongActor.java).

Batch file build.bat matches what the user would run from the command prompt (use option -debug to see the execution details):

> build -verbose run
Compile 2 Java source files to directory "target\classes"
[PingPong-akka.actor.default-dispatcher-5] INFO akka.event.slf4j.Slf4jLogger - Slf4jLogger started
PING
PONG
PING
PONG
PING
PONG
PING
PONG
PING
PONG
PING

🔎 PingPongScala is the same Akka application written in Scala (e.g. MapReduceApplication.scala, PingPongActor.scala). For instance build.bat generates the following output :  

> build run
[PingPong-akka.actor.default-dispatcher-4] INFO akka.event.slf4j.Slf4jLogger - Slf4jLogger started
PING
PONG
PING
PONG
PING
PONG
PING
PONG
PING
PONG
PING

Footnotes

[1] Source code updates

We have updated several deprecated code in the original examples of Gupta's book:
Original source code Updated source code a)
(≤2.5) akka.actor.UntypedActor akka.actor.UntypedAbstractActor
(≤2.3) akka.routing.RoundRobinRouter akka.routing.RoundRobinPool
akka.dispatch.Await scala.concurrent.Awaitb)
akka.dispatch.Future scala.concurrent.Futurec)
(≤2.4) _system.shutdown() _system.terminate()
a) Akka version 2.6.x
b) Object Await is defined in file scala/concurrent/package.scala since Scala 2.10.
c) Trait/object Future is defined in file scala/concurrent/Future.scala since Scala 2.10.
See the online documentation for further informations:

[2] FirstAkkaApplication: 2 versions

We actually provide two versions of FirstAkkaApplication:

mics/May 2024