Prop
- Props는 액터 생성을 위한 옵션을 지정하는 구성 클래스로,
- 관련 배포 정보를 포함하여 액터를 생성하기 위한 변경 불가능하고 자유롭게 공유 가능한 레시피로 생각하십시오.
- 액터는 ActorSystem 및 ActorContext에서 사용할 수 있는 ActorOf라는 팩토리 메서드에 Props 인스턴스를 전달하여 생성됩니다.
- ActorOf에 대한 호출은 IActorRef의 인스턴스를 반환합니다.
using Akka.Actor;
using System;
namespace AkkaNET_Actor_Tell
{
class Program
{
static ActorSystem system = ActorSystem.Create("actorSystem");
static void Main(string[] args)
{
IActorRef actor1 = system.ActorOf(ExampleActor1.Props(), "exampleActor1");
IActorRef actor2 = system.ActorOf(ExampleActor2.Props(), "exampleActor2");
actor1.Tell("actor1 tell msg");
actor2.Tell("actor2 tell msg");
system.WhenTerminated.Wait();
}
}
public class ExampleActor1 : ReceiveActor
{
public ExampleActor1()
{
Receive<string>(_ => Handle(_));
}
public static Props Props()
{
return Akka.Actor.Props.Create(() => new ExampleActor1());
}
public void Handle(string msg)
{
Console.WriteLine($"Actor1 Received : {msg}");
//Self.Tell("Actor1 : Self tell ");
}
}
public class ExampleActor2 : ReceiveActor
{
public ExampleActor2()
{
Receive<string>(_ => Handle(_));
// Self.Tell("Actor2 : self tell ");
}
public static Props Props()
{
return Akka.Actor.Props.Create(() => new ExampleActor2());
}
public void Handle(string msg)
{
Console.WriteLine($"Actor2 Received : {msg}");
}
}
}