Service Fabric spawn actor on startup -
is there way require system spawn actors on startup.
currently activate set of actors need in program.cs
after actor registration.
this working ok, reminderloadinprogressexception
because actor being activated needs register reminder not reminders have been loaded @ time tries that.
is there standard way seed cluster?
no, need activate actors.
program.cs isn't best place because execution doesn't line service's lifecycle, you've noticed.
if need activate actors when actor service starts up, place in runasync method of actor service. can customize actor service writing service derives it, same when write stateful service:
edit: make sure call , await base.runasync() first!
class myactorservice : actorservice { public myactorservice(statefulservicecontext context, actortypeinformation typeinfo, func<actorbase> newactor) : base(context, typeinfo, newactor) { } protected async override task runasync(cancellationtoken cancellationtoken) { await base.runasync(cancellationtoken); var proxy = actorproxy.create<imyactor>(new actorid(0)); await proxy.startdoingstuff(); } }
and register actor service runtime knows use host actor instances:
static class program { private static void main() { actorruntime.registeractorasync<myactor>( (context, actortype) => new myactorservice(context, actortype, () => new myactor())) .getawaiter().getresult(); thread.sleep(timeout.infinite); } }
just make sure actor method idempotent, because execute every time primary replica of actor service started (after failover, resource balancing, application upgrade, etc), nice thing won't execute before actor service ready , execute when service comes up.
see here more info on how work actor service: https://azure.microsoft.com/en-us/documentation/articles/service-fabric-reliable-actors-platform/
Comments
Post a Comment