私は akka.net を学んでおり、従来のメッセージ駆動型アプリの一部を置き換えるために使用する可能性があります。
基本的に、 X 個のノードをクラスターに参加させようとしています。これはピア ツー ピアタイプで、ノード上で X 個のアクター (同じアクター) を実行する場合があります。
10 個のジョブ (SendEmailActor など) がある場合、理想的には、10 個のジョブのそれぞれを異なるノードで実行します (負荷を均等に分散します)。
デモ用の非常に単純なコンソール アプリがあります。
using System;
using System.Configuration;
using Akka;
using Akka.Actor;
using Akka.Cluster;
using Akka.Cluster.Routing;
using Akka.Configuration;
using Akka.Configuration.Hocon;
using Akka.Routing;
namespace Console1
{
class MainClass
{
public static void Main(string[] args)
{
Console.Write("Is this the seed node? (Y/n): ");
var port = Console.ReadLine().ToLowerInvariant() == "y" ? 9999 : 0;
var section = (AkkaConfigurationSection)ConfigurationManager.GetSection("akka");
var config =
ConfigurationFactory.ParseString("akka.remote.helios.tcp.port=" + port)
.WithFallback(section.AkkaConfig);
var cluster = ActorSystem.Create("MyCluster", config);
var worker = cluster.ActorOf(Props.Create<Worker>().WithRouter(
new ClusterRouterPool(
new RoundRobinPool(10),
new ClusterRouterPoolSettings(30, true, 5))), "worker");
while (true)
{
Console.Read();
var i = DateTime.Now.Millisecond;
Console.WriteLine("Announce: {0}", i);
worker.Tell(i);
}
}
}
public class Worker : UntypedActor
{
protected override void OnReceive(object message)
{
System.Threading.Thread.Sleep(new Random().Next(1000, 2000));
Console.WriteLine("WORKER ({0}) [{1}:{2}]", message, Context.Self.Path, Cluster.Get(Context.System).SelfUniqueAddress.Address.Port);
}
}
}
そして、私のapp.configは次のようになります
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="akka" type="Akka.Configuration.Hocon.AkkaConfigurationSection, Akka" />
</configSections>
<akka>
<hocon>
<![CDATA[
akka {
actor {
provider = "Akka.Cluster.ClusterActorRefProvider, Akka.Cluster"
}
remote {
helios.tcp {
hostname = "127.0.0.1"
port = 0
}
}
cluster {
seed-nodes = ["akka.tcp://MyCluster@127.0.0.1:9999"]
}
}
]]>
</hocon>
</akka>
</configuration>
HOCON を使用して akka.actor.deployment をセットアップしたいのですが、うまくいきませんでした。routees.paths と、 actor.deployment/workerとの関係、およびroutees.pathsが C# で作成されたアクターにどのようにマップされるかがよくわかりません。
actor {
provider = "Akka.Cluster.ClusterActorRefProvider, Akka.Cluster"
deployment {
/worker {
router = roundrobin-pool
routees.paths = ["/worker"] # what's this?
cluster {
enabled = on
max-nr-of-instances-per-node = 1
allow-local-routees = on
}
}
}
}
別の質問: aka.net.cluster を使用して、ノードを「ミラーリング」して冗長性を提供することは可能ですか? それとも、GuaranteedDeliveryActor (AtLeastOnceDelivery に名前が変更されたと思います) が進むべき道ですか?