java - Creating Spring-backed actors as routees -
problem: have thread pool allocated number of actors making blocking calls (eg. web service, database, etc).
i have following configuration:
threadpool-dispatcher { type = dispatcher executor = "thread-pool-executor" thread-pool-executor { core-pool-size-min = 4 core-pool-size-max = 8 } }
and following setup method router actor:
private final int numberofchildren = 4; @override public void prestart() throws exception { log.info("starting up.. creating {} children", numberofchildren); list<routee> routees = new arraylist<>(); (int = 0; < numberofchildren; i++) { actorref actor = getcontext().actorof(springactorextension.props(routeeclass) .withdispatcher(threadpool_dispatcher)); getcontext().watch(actor); routees.add(new actorrefroutee(actor)); } router = new router(new smallestmailboxroutinglogic(), routees); super.prestart(); }
springactorextension similar code presented here, uses class objects instead of names.
the routees created spring in end, example:
@bean @scope(value = "prototype") public httpclientactor httpclient() { return new httpclientactor(); }
all works fine, problem number of threads thread pool executor configured use must declared @ 2 places:
- in threadpool-dispatcher configuration
- in code of router (
numberofchildren
)
reading through akka docs there seems way create routees automatically based on configuration alone, eg.
akka.actor.deployment { /parent/router1 { router = round-robin-pool nr-of-instances = 5 } }
however, not how (by whom) should routee actors created.
is there way either
- explain akka have routees created spring
- or access
thread-pool-executor
configuration (eg. number of threads) in code above , remove need specifying number of threads 2 times.
Comments
Post a Comment