Akka.NETAkka? 的 .NET 開(kāi)源實(shí)現(xiàn)
Akka.NET 是 Akka 的 .NET 開(kāi)源實(shí)現(xiàn)。用于構(gòu)建強(qiáng)大的并發(fā)和分布式應(yīng)用。Akka 是一個(gè)用 Scala 編寫(xiě)的庫(kù),用于簡(jiǎn)化編寫(xiě)容錯(cuò)的、高可伸縮性的 Java 和 Scala 的 Actor 模型應(yīng)用。
示例代碼:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Akka;
using Akka.Actor;
namespace ConsoleApplication11
{
public class Greet
{
public Greet(string who)
{
Who = who;
}
public string Who { get;private set; }
}
public class GreetingActor : ReceiveActor
{
public GreetingActor()
{
Receive<Greet>(greet =>
Console.WriteLine("Hello {0}", greet.Who));
}
}
class Program
{
static void Main(string[] args)
{
//create a new actor system (a container for your actors)
var system = ActorSystem.Create("MySystem");
//create your actor and get a reference to it.
//this will be an "ActorRef", which is not a
//reference to the actual actor instance
//but rather a client or proxy to it
var greeter = system.ActorOf<GreetingActor>("greeter");
//send a message to the actor
greeter.Tell(new Greet("World"));
//this prevents the app from exiting
//Before the async work is done
Console.ReadLine();
}
}
}評(píng)論
圖片
表情
