title: Can Akka Cluster Client Send Messages to Cluster Nodes Not in Initial Contacts?
body: <p>Using Akka 2.3.14, I'm trying to create an Akka cluster of various services. Until now, I have had all my "services" in one artifact that was clustered across multiple nodes, but now I am trying to break this artifact into multiple services that all exist on the same cluster.</p>
  
  <p>So in breaking this up, we've designed it so that any node on the cluster will first try to connect to the seed nodes. If there is no seed node, it will look to see if it is a candidate to run as a seed node (if it's on the same host that a seed node can be on) in which case it will grab the an open seed node port and become a seed node. So in this sense, any service in the cluster can become the seed node.</p>
  
  <p>At least, that was the idea. Our API into this system running as a separate service implements a ClusterClient into this system. The initialContacts are set to be the same as the seed nodes. The problem is that the only receptionist actors I can send a message to through the ClusterClient are the actors on the seed nodes.</p>
  
  <p>Here is an example if it helps. Let's say I have a String Service and a Double Service, and the receptionist for each service is a StringActor and a DoubleActor respectively. Now lets say I have a Client Service which sends StringMessages and DoubleMessages to the StringActor and DoubleActor</p>
  
  <p>So for simplicity, let's say I have two nodes, server1 and server2 then:</p>
  
  <pre><code>seed-nodes = ["akka.tcp://system@server1:2773", "akka.tcp://system@server2:2773"]
  </code></pre>
  
  <p>My ClusterClient would be initialize like so:</p>
  
  <pre><code>system.actorOf(
      ClusterClient.props(
          Set(
              system.actorSelection("akka.tcp://system@server1:2773/user/receptionist"),
              system.actorSelection("akka.tcp://system@server2:2773/user/receptionist")
          )
      ),     
      "clusterClient"
  )
  </code></pre>
  
  <p>Here are the scenarios that are happening for me:</p>
  
  <ol>
  <li>If the StringServices start up on both servers first, then DoubleMessages from the Client Service just disappear into the ether.</li>
  <li>If the DoubleServices start up on both servers first, then StringMessages from the Client Service just disappear into the ether.</li>
  <li>If the StringService starts up first on serverX and the DoubleService starts up first on serverY, then all StringMessages will be sent to serverX and all DoubleMessages will be sent to serverY, which is not as bad as the above case, but it means it's not really scaling.</li>
  </ol>
  
  <p>This isn't what I expected, it's possible it's just a defect in my code, so I would like to know if this IS expected behavior or not. And if not, then is there another Akka concept that could help me with this?</p>
  
  <p>Arguably, I could just make one service type my entry point, like a RoutingService that could accept StringMessages or DoubleMessages, and then send that to the correct service. But if the Client Service can only send messages to the RoutingService instances that are in the initial contacts, then I can't dynamically scale the RoutingService because no matter how many nodes I add the Client Service can only send to the initial contacts.</p>
  
  <p>I'm also thinking about subscribing to ClusterEvents in my Client Service and seeing if I can add and remove initial contacts from my cluster client as nodes are started up in the cluster, but I'm not sure if this is possible, and it feels like there should be a better solution.</p>