routing - Akka messaging mechanisms by example -
i have fair amount of apache camel (routing/mediation/orchestation engine; lightweight esb) experience , racking brain trying understand difference between akka:
- dispatchers (
dispatcher
,pinneddispatcher
,callingthreaddispatcher
) - routers
- pools
- groups
- event buses
according docs:
dispatchers are:
...is makes akka actors “tick”, engine of machine speak.
but doesn't explain dispatcher or it's relationship actor is.
routers are:
messages can sent via router efficiently route them destination actors, known routees. router can used inside or outside of actor, , can manage routees yourselves or use self contained router actor configuration capabilities. sounds awful lot dispatcher.
pools are:
[a type of] router [that] creates routees child actors , removes them router if terminate.
groups are:
[a type of] actor [where routees] created externally router , router sends messages specified path using actor selection, without watching termination.
event buses are:
...a way send messages groups of actors
this sounds dispatchers , routers.
so main concerns are:
- what difference between dispatchers, routers , event buses, , when use each?
- when use pool vs group?
a dispatcher thread-pool. akka uses dispatcher multiple things (like enqueueing messages in right mailbox or pick message actor mailbox , process it). every time 1 of these actions need performed thread thread-pool selected , used it. akka comes default default-dispatcher
config can find here in reference.conf searching default-dispatcher
. using default-dispatcher
can define different dispatcher ensure have reserved thread-pool other purposes (for example netty threads when using akka-remote or akka-cluster).
a router in akka actor uses kind of routing logic route messages list of routees. there many types of router depending on logic: broadcast, balancing, roundrobin... can find of them in akka docs. routees of router can pool or group. 1 of popular use cases of routers vertically scale app means maximize use of cpu available in system (using multiple threads @ same time).
a pool means routees being created on-demand given type. example may want randompool
of myfancyactor
3 instances. akka create 3 actors of myfancyactor
, fourth 1 actual router. every time router actor gets message forwarding message 1 of 3 myfancyactor
actors. pool takes care of restarting actors , watch lifecycle ensure have n number of instances running.
a group means routees being created before defining router. once defining router need pass list of routees actor created. group not monitor lifecycle of actors , need yourself.
event buses channels can subscribe particular type of message actor. if there message of particular type, actor it. used akka internals subscribing deadletter
s when message unable reach destination or events regarding formation of cluster (in akka-cluster). use aware of events happening in actorsystem
.
Comments
Post a Comment