Morning guys. I hope someone can show me how to correctly use the
BackOffSupervisor
. I set up two actors like following, and expect the FakeActor to be restarted after 10 seconds, but it seems to keep processing it without a backoff.
public class TestActor : ReceiveActor
{
private IActorRef _child;
public TestActor()
{
Receive<string>(msg =>
{
_child.Forward(msg);
});
}
protected override void PreStart()
{
var ch = Props.Create(() => new FakeActor(), OneForOneStrategy.StoppingStrategy);
_child = Context.ActorOf(Props.Create(() => new BackoffSupervisor(ch, null, TimeSpan.FromSeconds(10), TimeSpan.FromMinutes(1), 0.25)));
}
}
public class FakeActor : ReceiveActor
{
public FakeActor()
{
Receive<string>(msg =>
{
FatalError();
});
}
protected override void PostStop()
{
Console.WriteLine("Actor is stopped");
}
protected override void PreRestart(Exception reason, object message)
{
if (message != null)
{
Self.Forward(message);
}
base.PreRestart(reason, message);
}
private void FatalError()
{
throw new InvalidOperationException();
}
}