Akka actors?的.NET開源移植:Akka.NET

jopen 9年前發布 | 37K 次閱讀 Akka.NET .NET開發

Akka.NET 是Java/Scala 流行框架Akka的一個 .NET 開源移植。可用于構建高并發,分布式和容錯事件驅動的應用在 .NET 和 Mono 平臺之上。Akka 是一個用 Scala 編寫的框架,用于簡化編寫容錯的、高可伸縮性的 Java 和 Scala 的 Actor 模型應用。

Simple Concurrency & Distribution

Asynchronous and Distributed by design. High-level abstractions like Actors and FSM.

High Performance

50 million msg/sec on a single machine. Small memory footprint; ~2.5 million actors per GB of heap.

Resilient by Design

Write systems that self-heal. Remote and/or local supervisor hierarchies.

Elastic & Decentralized

Adaptive load balancing, routing, partitioning and configuration-driven remoting.

Extensible

Use Akka.NET Extensions to adapt Akka to fit your needs.

Open Source

Akka.NET is released under the Apache 2 license

Actor Model

The Actor Model provides a higher level of abstraction for writing concurrent and distributed systems. It alleviates the developer from having to deal with explicit locking and thread management, making it easier to write correct concurrent and parallel systems.

Actors were defined in the 1973 paper by Carl Hewitt but have been popularized by the Erlang language, and used for example at Ericsson with great success to build highly concurrent and reliable telecom systems.

Read more

Akka actors的.NET開源移植:Akka.NET

Distributed by Default

Everything in Akka.NET is designed to work in a distributed setting: all interactions of actors only use message passing, and everything is asynchronous.

This effort has been undertaken to ensure that all functions are available equally when running within a single process or on a cluster of hundreds of machines. The key for enabling this is to go from remote to local by way of optimization instead of trying to go from local to remote by way of generalization. See this classic paper for a detailed discussion on why the second approach is bound to fail.

Read more

Akka actors的.NET開源移植:Akka.NET

Supervision & Monitoring

Actors form a tree with actors being parents to the actors they've created.

As a parent, the actor is responsible for handling its children’s failures (so-called supervision), forming a chain of responsibility, all the way to the top. When an actor crashes, its parent can either restart or stop it, or escalate the failure up the hierarchy of actors. This enables a clean set of semantics for managing failures in a concurrent, distributed system and allows for writing highly fault-tolerant systems that self-heal.

Read more

Akka actors的.NET開源移植:Akka.NET

示例代碼:

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();
        }
    }
}

項目主頁:http://www.baiduhome.net/lib/view/home/1421975491156

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!