Last active
December 13, 2016 09:43
-
-
Save Horusiath/7337490cba3740bbe8e6f33aa699f348 to your computer and use it in GitHub Desktop.
Akka cluster router
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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://[email protected]: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