Skip to content

Instantly share code, notes, and snippets.

@Horusiath Horusiath/Program.cs
Last active Dec 13, 2016

Embed
What would you like to do?
Akka cluster router
using System;
using Akka.Actor;
using Akka.Configuration;
using Akka.Routing;
namespace AkkaClustering
{
public class JobCoordinatorActor : ReceiveActor
{
public JobCoordinatorActor()
{
Receive<string>(s => Console.WriteLine($"{Self}: {s}"));
}
}
class Program
{
static void Main(string[] args)
{
var config = ConfigurationFactory.ParseString(@"
akka {
actor {
provider = ""Akka.Cluster.ClusterActorRefProvider, Akka.Cluster""
deployment {
/JobCoordinator {
router = round-robin-pool
nr-of-instances = 20
cluster {
enabled = on
allow-local-routees = on
use-role = prototype
max-nr-of-instances-per-node = 5
}
}
}
}
remote.helios.tcp {
hostname = ""127.0.0.1""
port = 5000
}
cluster {
roles = [ prototype ]
seed-nodes = [ ""akka.tcp://cluster@127.0.0.1:5000/"" ]
}
}
");
using (var system = ActorSystem.Create("cluster", config))
{
var props = Props.Create<JobCoordinatorActor>().WithRouter(FromConfig.Instance);
var coordinatorRef = system.ActorOf(props, "JobCoordinator");
var oneSec = TimeSpan.FromSeconds(1);
system.Scheduler.ScheduleTellRepeatedly(oneSec, oneSec, coordinatorRef, "hello", ActorRefs.NoSender);
Console.ReadLine();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.