Akka.net 集群循环组配置。不路由消息

Akka.net cluster round-robin-group configuration. Not routing messages

我正在尝试配置集群组路由器,并想检查我对 "how" 的假设是否有效。

我在集群中有 2 个独立的节点,它们具有以下角色 "mainservice" 和 "secondservice"。在 "mainservice" 中,我想使用循环组路由器向 "secondservice" 中的 Actor 发送消息。

在 akka hocon 配置中,我在 akka.actor.deployment 部分中有以下内容:

/secondserviceproxy {
       router = round-robin-group
       routees.paths = ["/user/gateway"]
       nr-of-instances = 3
       cluster {
        enabled = on
        allow-local-routees = off
        use-role = secondservice
       }
}

我基于文档的假设是我可以在 "mainservice" 中创建一个 "secondserviceproxy" actor,它处理消息路由到我的 [=27] 的任何 运行 个实例=] 在循环的基础上。

var secondServiceProxy = Context.System.ActorOf(Props.Empty.WithRouter(FromConfig.Instance), "secondserviceproxy");
secondServiceProxy.Tell("Main Service telling me something");

我还假设 routees.path 属性 意味着消息被发送到位于其 Actor 层次结构中的 "secondservice" 中的 Actor,如下所示:“/user/gateway".

我的工作假设是否正确?由于此实现在 "secondservice".

中没有产生任何结果

你的假设是正确的。可能发生的情况是,在路由器有机会在集群周围构建其路由 table 之前,您的消息已通过集群路由器爆炸(它通过监视集群八卦构建)。

结果?您的消息最初在 DeadLetters 中结束。然后,一旦集群完全形成,它就会通过,因为路由器知道集群周围的预期接收者。

您可以通过订阅该演员的死信并检查消息的去向来验证是否需要。你可以这样做:

using Akka.Actor;
using Akka.Event;

namespace Foo {
  public class DeadLetterAwareActor : ReceiveActor {
    protected ILoggingAdapter Log = Context.GetLogger();

    public DeadLetterAwareActor() {
      // subscribe to DeadLetters in ActorSystem EventStream
      Context.System.EventStream.Subscribe(Self, typeof(DeadLetter));
      Receiving();
    }

    private void Receiving() {
      // is it my message being delivered to DeadLetters?
      Receive<DeadLetter>(msg => msg.Sender.Equals(Self), msg => {
        Log.info("My message to {0} was not delivered :(", msg.Recipient);
      })
    }
  }
}