Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagebash
themeEmacs
linenumberstrue
var manager = system.ActorOf<Manager>();

try
{
    await manager.GracefulStop(TimeSpan.FromMilliseconds(5), "shutdown");
    // the actor has been stopped
}
catch (TaskCanceledException)
{
    // the actor wasn't stopped within 5 seconds
}

...
public class Manager : UntypedActor
{
    private IActorRef worker = Context.Watch(Context.ActorOf<Cruncher>("worker"));

    protected override void OnReceive(object message)
    using Akka.Actor;
using Akka.TestKit;
using AkkaDotModule.ActorSample;
using AkkaNetCoreTest;
using System;
using System.Threading.Tasks;
using Xunit;
using Xunit.Abstractions;

namespace TestAkkaDotModule.TestActors
{
    public class HelloActor2 : ReceiveActor
    {        
        private string MyName { get; set; }

        private IActorRef target = null;

        public HelloActor2(string name)
        {
            MyName = name;

            ReceiveAsync<string>(async message =>
            {
                string inComeMessage = $"[{MyName}] : {message}";

            });

        }
    }

    public class TestManager : UntypedActor
    {
        IActorRef probe;

        private IActorRef worker = Context.Watch(Context.ActorOf(
            Props.Create(() => new HelloActor2("hello")), "worker" ));

        public TestManager(IActorRef _probe)
        {
            probe = _probe;
        }

        protected override void OnReceive(object message)
        {
            switch (message)
            {
                case "hello":
                    worker.Tell("hello");
                    break;
                case "shutdown":                    
                    worker.Tell(PoisonPill.Instance, Self);
                    Context.Become(ShuttingDown);   //종료모드로 메시지처리 상태변경
                    break;                
            }
        }

        private void ShuttingDown(object message)
        {
            switch (message)
            {
                case "hello": //어떤 잡을 시키려고 할시,셧다운중임을 알립니다.
                    Sender.Tell("service unavailable, shutting down", Self);
                    break;
                case Terminated t:
                    probe.Tell("SafeClose");
                    Context.Stop(Self);
                    break;
            }
        }
    }

    public class LifeCycleActorTest : TestKitXunit
    {
        protected TestProbe probe;

        protected IActorRef manager;

        public LifeCycleActorTest(ITestOutputHelper output) : base(output)
        {
        switch    Setup(message);
        {}

        public void Setup()
   case  "job":
   {
            //테스트 worker.Tell("crunch");관찰자..
            probe    break= this.CreateTestProbe();

            //GraceFulDown을 case위한 ShutdownManager액터 s:생성
            manager =   workerSys.TellActorOf(PoisonPill.Instance, Self); //하위 worker의 작동을 중지시킵니다.Props.Create(() => new TestManager(probe)));
            
    Context.Become(ShuttingDown);
    }

        [Theory(DisplayName    break;= "GracefulStopTest")]
        }[InlineData(5)]
    }

    public privateasync voidTask ShuttingDownGtaceFulStopAreOK(objectint messagewaitTimeSec)
    {
    {
    switch (message)
        {//Step:
            case "job": //어떤 잡을1.GracefulStop 시키려고을통한 할시,셧다운중임을 알립니다.
  종료 시그널 발생 
            //  Sender.Tell("service unavailable, shutting down", Self);2.자식 액터종료(PoisonPill, 지금까지 받은메시지까지만 처리하고)
            // 3.GracefulStop , Terminated 될때까지 break;대기
            case// Terminated검증 t:
 안전한 종료메시지가 왔는지 검사

            await Context.Stop(Selfmanager.GracefulStop(TimeSpan.FromMilliseconds(3), "shutdown");

                breakprobe.ExpectMsg("SafeClose", TimeSpan.FromSeconds(waitTimeSec));
        }
    }
}







액터접근 주소체계

...


  ActorPath는 총 4가지로 구분이 되며  http의 RestAPI의 주소체계와 거의 흡사하다고 볼수 있습니다.

...