scala - Starting Actors on-demand by identifier in Akka -
i'm implementing system that receives inbound messages external monitoring system. i'm translating these messages more concise 'events', , i'm using these alter state of 'managed system' objects. akka actors seemed use case encapsulating mutable state in concurrent applications.
the managed systems identified name (99% of time hostname). whenever proper event received, system routes message correct actor based on name property. @ first used use actorselection , complete paths of said actors, ugly, , saw several people advise against relying on qualified name of actor deliver message. i've set simple eventbus, great can do:
eventbus.subscribe(subscriber1, "/managedsystem01") eventbus.subscribe(subscriber2, "/managedsystem02") eventbus.publish(monitoringevent("/managedsystem01", monitoringmessage("managedsystem01", "n", "cpu_load_high", true))) eventbus.publish(monitoringevent("/managedsystem02", monitoringmessage("managedsystem02", "y", "disk_usage_high", true)))
of course, have issue that, should receive , event concerns managed system i've not spawned actor yet (this entirely possibly, impossible me absolute list of managed systems unfortunately), message routed dead-letter mailbox.
ideally don't want happen. when unable address specific actor, want spawn new 1 dynamically.
i suppose that, theoretically, subscribe deadletter messages but:
- that sounds little 'hacky', since message reserved system
- is possible recover original message (in case, monitoringmessage) sent deadletter mailbox?
alternatively there way check if there 0 subscribers "topic"?
what describe ("send actor identifier, if not exist buffer until gets created , deliver newly on-demand created actor") implemented in akka cluster sharding.
while designed sharding load (work) across cluster, use locally well, since requirement scaled down (to 1 node) version of problem solves. takes care of starting new actors if don't exist given identifier etc, you'd subscribe shard-region events , it'll take care of creating actors you.
Comments
Post a Comment