jaywayco jaywayco - 26 days ago 19
C# Question

I need to communicate with multiple remote actor systems

Im playing with using akka.Net to develop a plugin architecture whereby each dll that contains one or more plugins is loaded into its own

AppDomain
and a new actor system is initialized ready to recieve messages from the "Host".

I become unstuck trying to get this to work with multiple plugins.

So the Host config looks like:

akka {
actor {
provider = ""Akka.Remote.RemoteActorRefProvider, Akka.Remote""
}
remote {
helios.tcp {
transport-class = ""Akka.Remote.Transport.Helios.HeliosTcpTransport, Akka.Remote""
applied-adapters = []
transport-protocol = tcp
port = 50003
hostname = localhost
}
}
}


And the plugin config looks like:

akka {
actor {
provider = ""Akka.Remote.RemoteActorRefProvider, Akka.Remote""
}
remote {
helios.tcp {
transport-class = ""Akka.Remote.Transport.Helios.HeliosTcpTransport, Akka.Remote""
applied-adapters = []
transport-protocol = tcp
port = 50004
hostname = localhost
}
}


(there are many of these)

My question is how do i get messages from the Host to all of the plugins?

Answer

The best recommendation is to use Akka.Cluster. Here's a well-documented example: https://github.com/petabridge/akkadotnet-code-samples/tree/master/Cluster.WebCrawler

Edit - removed suggestion to use dynamic port. Much better off using static ones so node reboots can be handled correctly.

Have each plugin config use a plugin-specific port (akka.remote.helios.tcp.port = 1231) and then define a clustered router that talks to actor systems fulfilling specific roles.

/api/broadcaster {
  router = broadcast-group
  routees.paths = ["user/api"]
  cluster {
      enabled = on
      max-nr-of-instances-per-node = 1
      allow-local-routees = on
      use-role = crawler
  }
}

This router, deployed at the path user/api/broadcaster on some node can communicate (via the Broadcast routing strategy) with any actor deployed at path user/api on any node in the cluster with role crawler without needing to look up IP addresses, ports, or any of that crap.

You configure a node's clustering information via the following section in Akka.NET's config:

cluster {
  #manually populate other seed nodes here, i.e. "akka.tcp://lighthouse@127.0.0.1:4053"
  seed-nodes = ["akka.tcp://webcrawler@127.0.0.1:4053"]
  roles = [crawler]
}

Seed nodes - has to be a well-known, statically-defined port and IP address. Read the article for an explanation on why this is important.

Roles - comma-delimited strings that define what this particular nodes' capabilities are. They're more like tags. You can use them inside clustered routers (like the one I showed earlier) to articulate which types of nodes you want to communicate with.

Comments