Akka.NETAkka 的 .NET 开源实现
Akka.NET 是 Akka 的 .NET 开源实现。用于构建强大的并发和分布式应用。Akka 是一个用 Scala 编写的库,用于简化编写容错的、高可伸缩性的 Java 和 Scala 的 Actor 模型应用。
示例代码:
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();
}
}
}评论
