Friday, 4 November 2016

"Akka in Action" Notes: Chapter 7-9

Configuration

The configuration library contains a fallback mechanism; the defaults are placed into a configuration object, which is then handed over to the configurator as the fallback configuration source.

val system = ActorSystem("mySystem")
val config = system.settings.config

ConfigFactory.load() is used internally to create a default config for the config argument that is omitted here. Once ActorSystem is constructed, we can get config.

Logging

The logging adapter uses the system eventStream to send the log messages to the eventHandler. The eventStream is the pub-sub mechanism of Akka. The eventHandler receives these message and uses the preferred logging framework to log the message.


Routing

If performance or scaling is the concern, you should use Akka's built-in routers, because they are optimized. The messages can be processed in parallel.

Concerns with a message's content or state, use normal Actors. The message should go to a different task.

The router actor is a self contained actor that loads the routing logic and other settings from configuration and is able to manage the routees itself.

Pool: These routers are managing the routees. They are responsible for creating the routees and removing them from the list if they terminate. We don't have to create or manage them. A pool can be used when all the routees are created and disributed the same way and there isn't a need for special recovery of the routees.

Group: The Group routers don't manage the routees. The routees have to be created by the system and the group router will use the actor selection to find the routees. A group can be used when you need to control the routee's life cycle in a special way.

Creating a pool needs the number of routee instances, and a group needs a list of routee paths.
When a routee terminate within a pool, the router detect this and removes the routee from the pool.
When a routee terminates the group router will still send messages to the routee. This is because the router doesn't manage the routees.






No comments:

Post a Comment