Friday 15 May 2015

java - akka-spring: How to wire actors -



java - akka-spring: How to wire actors -

i next akka-java-spring still don't know how inject actor within another. example:

public class reader extends untypedconsumeractor { private actorref handler; public reader(actorref handler) { this.handler = handler; } // ... } // create handler first final actorref handler = getcontext() .actorof(springextprovider.get(system).props("handler"), "handler"); // how pass handler above reader ??? final actorref reader = ???

if want using spring actorref have spring bean. it's possible imo not elegant there isn't simple way maintain supervision hierarchy expose actorref's singleton beans. played around @ first ended lot of top-level actors created undesirable. i've found appropriate way me combine spring injection , actorref injection other actors via message passing described in akka docs.

my spring service beans injected via spring, , actorref's injected via message passing required. actorref quite ambiguous represents wrap actoref in class provides type receiving actor can decide it, of import if epxetcing many different actorref's injected.

anyway, answering question, create spring managed actorref bean next in spring @configuration class:

@autowired private actorsystem actorsystem; @bean(name = "handler") public actorref handler() { homecoming actorsystem.actorof(springextprovider.get(system).props("handler"), "handler"); }

and in spring annotated actor have like:

@named("reader") @scope("prototype") public class reader extends untypedconsumeractor { @autowired @qualifier("handler") private actorref handler; // ... }

the dependency injection of "handler" actorref happen when create reader actor using spring extension. it's of import remember actorref proxy actor.

java spring akka

No comments:

Post a Comment