接收路线回复

时间:2019-04-16 16:12:00

标签: c# akka.net

我有一个演员创建一个ScatterGatherFirstCompleted路由器并发送一条消息以获取一些数据。这只是我尝试不同路由器的简单示例。 收到回复后,回复的发送者为DeadLetters。我希望发送方将成为池路由器管理的参与者之一。 我很好奇为什么会这样,如果我做错了什么?

编辑: 根据acarlsteins的评论,我要添加一些代码。 因此,以下是在actor系统中创建的父actor,它是/ user Guardian actor的子代:

public class TailChoppingActor : ReceiveActor
{
    private static void SendTCMessages(string message, IActorRef router)
    {
        Console.WriteLine(message);

        router.Tell(new Request("Sadržaj... bla bla bla", new Random()));
    }
    public TailChoppingActor(IActorRef collector)
    {
        Receive<Go>(x =>
        {
            var within = TimeSpan.FromSeconds(2);
            var interval = TimeSpan.FromSeconds(10);
            var props = Props.Create(() => new MyActor(collector))
                .WithRouter(new TailChoppingPool(5, within, interval)); 
            var childRouter = Context.ActorOf(props);
            SendTCMessages("TailChopping", childRouter);
        });
        // Context.Sender is DeadLetters
        Receive<Reply>(x => Console.WriteLine($"Got reply from: ${x.Sender} (Akka sender: {Sender})"));
    }
}

以下是儿童演员的代码:

public class MyActor : ReceiveActor
{
    public MyActor(IActorRef collector)
    {            
        Receive<Request>(x =>
        {
            var self = Self.Path.ToString();
            var wait = x.Rnd.Next(0, 2000);
            var millis = TimeSpan.FromMilliseconds(wait);
            Console.WriteLine($"{self} got message: {x.Content}, waiting: {millis} ms");
            Thread.Sleep(millis);
            Sender.Tell(new Reply(x.Content, self));
        });
    }
}

0 个答案:

没有答案