PM> Install -Package Akka
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; // using Akka; using Akka.Actor; namespace ConsoleApplication11 { class Program { static void Main(string[] args) { } } }
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; } } class Program { static void Main(string[] args) { } } }
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() { // // Greet () Receive<Greet>(greet => Console.WriteLine("Hello {0}", greet.Who)); } } class Program { static void Main(string[] args) { } } }
ActorSystem
and call ActorOf
. 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) { // ( ) var system = ActorSystem.Create("MySystem"); // . // "ActorRef", // , // . var greeter = system.ActorOf<GreetingActor>("greeter"); // greeter.Tell(new Greet("World")); // // , // . Console.ReadLine(); } } }
// () , public class Greet { public Greet(string who) { Who = who; } public string Who { get;private set; } }
ReceiveActor
API: // public class GreetingActor : ReceiveActor { public GreetingActor() { Receive<Greet>(greet => Console.WriteLine("Hello {0}", greet.Who)); } }
TypedActor
API: public class GreetingActor : TypedActor , IHandle<Greet> { public void Handle(Greet greet) { Console.WriteLine("Hello {0}!", greet.Who); } }
// ( ) var system = ActorSystem.Create("MySystem"); // . // "IActorRef", // , // . var greeter = system.ActorOf<GreetingActor>("greeter"); // greeter.Tell(new Greet("World")); // // , // . Console.ReadLine();
// () , type Greet = Greet of string let system = ActorSystem.Create "MySystem" // Use F# computation expression with tail-recursive loop // to create an actor message handler and return a reference let greeter = spawn system "greeter" <| fun mailbox -> let rec loop() = actor { let! msg = mailbox.Receive() match msg with | Greet who -> printf "Hello, %s!\n" who return! loop() } loop() greeter <! Greet "World"
PM> install-package Akka
PM> install-package Akka.Remote
using Akka; using Akka.Actor; using Akka.Configuration; namespace Foo.Bar { class Program { static void Main(string[] args) { // configure remoting for localhost:8081 var fluentConfig = FluentConfig.Begin() .StartRemotingOn("localhost", 8081) .Build(); using (var system = ActorSystem.Create("my-actor-server", fluentConfig)) { // start two services var service1= system.ActorOf<Service1>("service1"); var service2 = system.ActorOf<Service2>("service2"); Console.ReadKey(); } } } }
Source: https://habr.com/ru/post/320396/
All Articles