1
votes

I am trying to configure a cluster group router and wanted to sanity check my assumptions on "how" this works.

I have 2 separate nodes in a cluster these have the following roles "mainservice" and "secondservice". Inside the "mainservice" I want to send messages to an Actor within the "secondservice" using a round-robin-group router.

In the akka hocon config I have the following within the akka.actor.deployment section:

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

My assumption based on the documentation is that I can create a "secondserviceproxy" actor in the "mainservice" and this handles the routing of messages to any running instances of my "secondservice" on a round-robin basis.

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

I also made the assumption that the routees.path property means that messages are sent to an Actor in the "secondservice" located in it's Actor hierarchy as follows: "/user/gateway".

Is my working assumption correct? As this implementation is yielding no results in the "secondservice".

1

1 Answers

1
votes

Your assumptions are correct. What’s probably happening is that your message is being blasted through the cluster router before the router has had a chance to build its routee table of routees around the cluster (which it builds from monitoring cluster gossip).

Result? Your message initially is ending up in DeadLetters. And then later, once the cluster has fully formed, it will go through because the router knows about its intended recipients around the cluster.

You could verify that if you want by subscribing to dead letters from that actor and checking if that’s where the message is going. You can do that like so:

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);
      })
    }
  }
}