Ejemplo n.º 1
0
        public void BackoffSupervisorOnFailure(ApplicationEnvironment applicationEnvironment)
        {
            ActorSystem actorSystem = ActorSystem.Create("app");
            // This class represents a configuration object used in creating an
            // ActorBase actor
            Props childProps = Props.Create <EchoActor>();
            //
            TimeSpan minBackoff = TimeSpan.FromSeconds(3);

            TimeSpan maxBackoff     = TimeSpan.FromSeconds(30);
            double   randomFactor   = 0.2;
            int      maxNrOfRetries = 2;
            // Builds back-off options for creating a back-off supervisor.
            BackoffOptions backoffOptions  = Backoff.OnFailure(childProps, "myEcho", minBackoff, maxBackoff, randomFactor, maxNrOfRetries);
            Props          supervisor      = BackoffSupervisor.Props(backoffOptions);
            IActorRef      supervisorActor = actorSystem.ActorOf(supervisor, "echoSupervisor");

            supervisorActor.Tell("EchoMessage1");
            supervisorActor.Tell(new Exception("File not found exception"));
            TestUtilities.ThreadSleepSeconds(5);
            supervisorActor.Tell("EchoMessage2");
            TestUtilities.ThreadSleepSeconds(5);
            supervisorActor.Tell("EchoMessage3");
            TestUtilities.MethodEnds();
        }
Ejemplo n.º 2
0
        public void BackoffSupervisorWithAutoResetWithSupervisorStrategy(ApplicationEnvironment applicationEnvironment)
        {
            ActorSystem actorSystem = ActorSystem.Create("app");
            // This class represents a configuration object used in creating an
            // ActorBase actor
            Props childProps = Props.Create <EchoActor>();
            //
            TimeSpan minBackoff     = TimeSpan.FromSeconds(3);
            string   childName      = "myEcho";
            TimeSpan maxBackoff     = TimeSpan.FromSeconds(30);
            double   randomFactor   = 0.2;
            int      maxNrOfRetries = 2;
            // Builds back-off options for creating a back-off supervisor.
            OneForOneStrategy supervisorStrategy = new OneForOneStrategy(exception =>
            {
                TestUtilities.ConsoleWriteJson(new
                {
                    Message          = $"{GetType().Name} OneForOneStrategy",
                    ExceptionMessage = exception.Message
                });
                TestUtilities.ThreadSleepSeconds(10);
                if (exception is FileNotFoundException)
                {
                    return(Directive.Restart);
                }

                return(Directive.Escalate);
            });
            BackoffOptions backoffOptions  = Backoff.OnStop(childProps, childName, minBackoff, maxBackoff, randomFactor, maxNrOfRetries).WithAutoReset(TimeSpan.FromSeconds(10)).WithSupervisorStrategy(supervisorStrategy);
            Props          supervisor      = BackoffSupervisor.Props(backoffOptions);
            IActorRef      supervisorActor = actorSystem.ActorOf(supervisor, "echoSupervisor");

            supervisorActor.Tell("EchoMessage1");
            supervisorActor.Tell(new FileNotFoundException("File not found exception"));
            supervisorActor.Tell("EchoMessage2");
            supervisorActor.Tell("EchoMessage3");
            TestUtilities.MethodEnds();
        }
 private IActorRef Create(BackoffOptions options) => Sys.ActorOf(BackoffSupervisor.Props(options));