O slideshow foi denunciado.
Utilizamos seu perfil e dados de atividades no LinkedIn para personalizar e exibir anúncios mais relevantes. Altere suas preferências de anúncios quando desejar.
Fundamentos de Akka.net para
sistemas concorrentes e distribuídos
usando o modelo de atores.
Elemar Jr
Elemar Júnior
Microsoft Most Valuable Professional (MVP)
Arquiteto de Soluções na Promob há 17 anos
elemarjr.net
github.co...
The Reactive Manifesto
Responsivo
Elástico Resiliente
Orientado a mensagem
Para considerar...
É difícil fazer sistemas verdadeiramente
concorrentes da forma correta
É difícil fazer sistemas que rea...
Akka.net Docs
O “Actor Model” foi definido em 1973, por Carl
Hewitt
A B
ActorRef
ActorSystem
Message
ActorRef
Message
class Program
{
public static ActorSystem MyActorSystem;
static void Main()
{
// initialize MyActorSystem
MyActorSystem = ...
var consoleWriterProps = Props.Create(() => new ConsoleWriterActor());
var consoleWriterActor = MyActorSystem.ActorOf(cons...
// tell console reader to begin
consoleReaderActor.Tell("start");
// blocks the main thread from exiting until the actor s...
class ConsoleReaderActor : UntypedActor
{
public const string ExitCommand = "exit";
private readonly IActorRef _consoleWri...
class ConsoleWriterActor : UntypedActor
{
protected override void OnReceive(object message)
{
var msg = message as string;...
A B
ActorRef
ActorSystem
Message
ActorRef
Message
Transport
Transport
A B
ActorRef
ActorSystem
Message
ActorRef
Message
Transport
Transport
Mensagens são “imutáveis”
public class InputSuccess
{
public string Reason { get; }
public InputSuccess(string reason)
{
Reason = reason;
}
}
public class ContinueProcessing
{}
public class InputError
{
public string Reason { get; }
public InputError(string reason)
{
Reason = reason;
}
}
internal class NullInputError : InputError
{
public NullInputError(string reason) : base(reason)
{}
}
class ValidationError : InputError {
public ValidationError(string reason) : base(reason)
{}
}
public const string StartCommand = "start";
public const string ExitCommand = "exit";
private readonly IActorRef _consoleW...
class ConsoleWriterActor : UntypedActor
{
protected override void OnReceive(object message)
{
if (message is Messages.Inpu...
consoleReaderActor.Tell(ConsoleReaderActor.StartCommand);
A B
ActorRef
ActorSystem
Message
ActorRef
Message
Transport
Transport
var consoleWriterProps = Props.Create<ConsoleWriterActor>();
var consoleWriterActor = MyActorSystem.ActorOf(consoleWriterP...
class ConsoleReaderActor : UntypedActor
{
public const string StartCommand = "start";
public const string ExitCommand = "e...
class ValidationActor : UntypedActor
{
private readonly IActorRef _consoleWriterActor;
public ValidationActor(IActorRef co...
A B
ActorRef
ActorSystem
Message
ActorRef
Message
Transport
Transport
Akka.net Docs
protected override void OnReceive(object message)
{
if (message is StartTail)
{
var msg = message as StartTail;
// here we...
Akka.net Bootcamp
private void GetAndValidateInput()
{
var message = Console.ReadLine();
if (!string.IsNullOrEmpty(message) && string.Equals...
A
ActorRef
ActorSystem
Message
ActorRef
Message
Transport
Transport
State A
State B
State C
Props
Props
Akka.net Bootcamp
A
ActorRef
ActorSystem
Message
ActorRef
Message
Transport
Transport
State A
State B
State C
Props
Props
Scheduler
The Reactive Manifesto
Responsivo
Elástico Resiliente
Orientado a mensagem
Obrigado!
tinyurl.com/feedback-ej
Fundamentos de Akka.net para sistemas concorrentes e distribuidos usando o modelo de atores
Fundamentos de Akka.net para sistemas concorrentes e distribuidos usando o modelo de atores
Próximos SlideShares
Carregando em…5
×

Fundamentos de Akka.net para sistemas concorrentes e distribuidos usando o modelo de atores

395 visualizações

Publicada em

Akka.net vem popularizando o desenvolvimento de sistemas concorrentes e distribuídos em .NET. Ele está baseado no modelo de atores, que surgiu há mais de 40 anos, e que vem ganhando relevância crescente nos últimos anos. Nessa palestra, apresento o framework Akka.net. Discuto seus fundamentos através de exemplos simples, porém práticos, de aplicação. Prepare-se para uma palestra com muito código. Considere também "Considerações de arquitetura para sistemas concorrentes e distribuídos usando o modelo de atores" onde apresento aspectos arquiteturais para adoção do modelo.

Publicada em: Educação
  • DOWNLOAD THIS BOOKS INTO AVAILABLE FORMAT (2019 Update) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://soo.gd/irt2 } ......................................................................................................................... Download Full EPUB Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download Full doc Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download PDF EBOOK here { https://soo.gd/irt2 } ......................................................................................................................... Download EPUB Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download doc Ebook here { https://soo.gd/irt2 } ......................................................................................................................... ......................................................................................................................... ................................................................................................................................... eBook is an electronic version of a traditional print book THIS can be read by using a personal computer or by using an eBook reader. (An eBook reader can be a software application for use on a computer such as Microsoft's free Reader application, or a book-sized computer THIS is used solely as a reading device such as Nuvomedia's Rocket eBook.) Users can purchase an eBook on diskette or CD, but the most popular method of getting an eBook is to purchase a downloadable file of the eBook (or other reading material) from a Web site (such as Barnes and Noble) to be read from the user's computer or reading device. Generally, an eBook can be downloaded in five minutes or less ......................................................................................................................... .............. Browse by Genre Available eBooks .............................................................................................................................. Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, ......................................................................................................................... ......................................................................................................................... .....BEST SELLER FOR EBOOK RECOMMEND............................................................. ......................................................................................................................... Blowout: Corrupted Democracy, Rogue State Russia, and the Richest, Most Destructive Industry on Earth,-- The Ride of a Lifetime: Lessons Learned from 15 Years as CEO of the Walt Disney Company,-- Call Sign Chaos: Learning to Lead,-- StrengthsFinder 2.0,-- Stillness Is the Key,-- She Said: Breaking the Sexual Harassment Story THIS Helped Ignite a Movement,-- Atomic Habits: An Easy &amp; Proven Way to Build Good Habits &amp; Break Bad Ones,-- Everything Is Figureoutable,-- What It Takes: Lessons in the Pursuit of Excellence,-- Rich Dad Poor Dad: What the Rich Teach Their Kids About Money THIS the Poor and Middle Class Do Not!,-- The Total Money Makeover: Classic Edition: A Proven Plan for Financial Fitness,-- Shut Up and Listen!: Hard Business Truths THIS Will Help You Succeed, ......................................................................................................................... .........................................................................................................................
       Responder 
    Tem certeza que deseja  Sim  Não
    Insira sua mensagem aqui
  • DOWNLOAD FULL BOOKS, INTO AVAILABLE FORMAT ......................................................................................................................... ......................................................................................................................... ,DOWNLOAD FULL. PDF EBOOK here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... ,DOWNLOAD FULL. EPUB Ebook here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... ,DOWNLOAD FULL. doc Ebook here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... ,DOWNLOAD FULL. PDF EBOOK here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... ,DOWNLOAD FULL. EPUB Ebook here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... ,DOWNLOAD FULL. doc Ebook here { https://tinyurl.com/yyxo9sk7 } ......................................................................................................................... ......................................................................................................................... ......................................................................................................................... .............. Browse by Genre Available eBooks ......................................................................................................................... Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult,
       Responder 
    Tem certeza que deseja  Sim  Não
    Insira sua mensagem aqui
  • Seja a primeira pessoa a gostar disto

Fundamentos de Akka.net para sistemas concorrentes e distribuidos usando o modelo de atores

  1. 1. Fundamentos de Akka.net para sistemas concorrentes e distribuídos usando o modelo de atores. Elemar Jr
  2. 2. Elemar Júnior Microsoft Most Valuable Professional (MVP) Arquiteto de Soluções na Promob há 17 anos elemarjr.net github.com/elemarjr twitter.com/elemarjr linkedin.com/elemarjr
  3. 3. The Reactive Manifesto Responsivo Elástico Resiliente Orientado a mensagem
  4. 4. Para considerar... É difícil fazer sistemas verdadeiramente concorrentes da forma correta É difícil fazer sistemas que realmente suportem “Scaling up” e “Scaling out” É difícil fazer sistemas resilientes, tolerantes a falhas com “auto recuperação”
  5. 5. Akka.net Docs
  6. 6. O “Actor Model” foi definido em 1973, por Carl Hewitt
  7. 7. A B ActorRef ActorSystem Message ActorRef Message
  8. 8. class Program { public static ActorSystem MyActorSystem; static void Main() { // initialize MyActorSystem MyActorSystem = ActorSystem.Create("MyActorSystem");
  9. 9. var consoleWriterProps = Props.Create(() => new ConsoleWriterActor()); var consoleWriterActor = MyActorSystem.ActorOf(consoleWriterProps); var consoleReaderProps = Props.Create(() => new ConsoleReaderActor(consoleWriterActor)); var consoleReaderActor =MyActorSystem.ActorOf(consoleReaderProps);
  10. 10. // tell console reader to begin consoleReaderActor.Tell("start"); // blocks the main thread from exiting until the actor system is shut down MyActorSystem.AwaitTermination();
  11. 11. class ConsoleReaderActor : UntypedActor { public const string ExitCommand = "exit"; private readonly IActorRef _consoleWriterActor; public ConsoleReaderActor(IActorRef consoleWriterActor) { _consoleWriterActor = consoleWriterActor; } protected override void OnReceive(object message) { var read = Console.ReadLine(); if (!string.IsNullOrEmpty(read) && string.Equals(read, ExitCommand, StringComparison.OrdinalIgnoreCase)) { Context.System.Shutdown(); return; } _consoleWriterActor.Tell(read); Self.Tell("continue"); } }
  12. 12. class ConsoleWriterActor : UntypedActor { protected override void OnReceive(object message) { var msg = message as string; if (string.IsNullOrEmpty(msg)) { Console.ForegroundColor = ConsoleColor.DarkYellow; Console.WriteLine("Please provide an input.n"); Console.ResetColor(); return; } // if message has even # characters, display in red; else, green var even = msg.Length % 2 == 0; var color = even ? ConsoleColor.Red : ConsoleColor.Green; var alert = even ? "Your string had an even # of characters.n" : "Your string had an odd # of characters.n"; Console.ForegroundColor = color; Console.WriteLine(alert); Console.ResetColor(); } }
  13. 13. A B ActorRef ActorSystem Message ActorRef Message Transport Transport
  14. 14. A B ActorRef ActorSystem Message ActorRef Message Transport Transport
  15. 15. Mensagens são “imutáveis”
  16. 16. public class InputSuccess { public string Reason { get; } public InputSuccess(string reason) { Reason = reason; } }
  17. 17. public class ContinueProcessing {}
  18. 18. public class InputError { public string Reason { get; } public InputError(string reason) { Reason = reason; } }
  19. 19. internal class NullInputError : InputError { public NullInputError(string reason) : base(reason) {} }
  20. 20. class ValidationError : InputError { public ValidationError(string reason) : base(reason) {} }
  21. 21. public const string StartCommand = "start"; public const string ExitCommand = "exit"; private readonly IActorRef _consoleWriterActor; public ConsoleReaderActor(IActorRef consoleWriterActor) { _consoleWriterActor = consoleWriterActor; } protected override void OnReceive(object message) { if (message.Equals(StartCommand)) { DoPrintInstructions(); } else if (message is Messages.InputError) { _consoleWriterActor.Tell(message as Messages.InputError); } GetAndValidateInput(); }
  22. 22. class ConsoleWriterActor : UntypedActor { protected override void OnReceive(object message) { if (message is Messages.InputError) { var msg = message as Messages.InputError; Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(msg.Reason); } else if (message is Messages.InputSuccess) { var msg = message as Messages.InputSuccess; Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine(msg.Reason); } else { Console.WriteLine(message); } Console.ResetColor(); } }
  23. 23. consoleReaderActor.Tell(ConsoleReaderActor.StartCommand);
  24. 24. A B ActorRef ActorSystem Message ActorRef Message Transport Transport
  25. 25. var consoleWriterProps = Props.Create<ConsoleWriterActor>(); var consoleWriterActor = MyActorSystem.ActorOf(consoleWriterProps, "consoleWriterActor"); var validationActorProps = Props.Create(() => new ValidationActor(consoleWriterActor)); var validationActor = MyActorSystem.ActorOf(validationActorProps, "validationActor"); var consoleReaderProps = Props.Create<ConsoleReaderActor>(validationActor); var consoleReaderActor = MyActorSystem.ActorOf(consoleReaderProps, "consoleReaderActor");
  26. 26. class ConsoleReaderActor : UntypedActor { public const string StartCommand = "start"; public const string ExitCommand = "exit"; private readonly IActorRef _validationActor; public ConsoleReaderActor(IActorRef validationActor) { _validationActor = validationActor; } protected override void OnReceive(object message) { if (message.Equals(StartCommand)) { DoPrintInstructions(); } GetAndValidateInput(); } private static void DoPrintInstructions() {} private void GetAndValidateInput() { var message = Console.ReadLine(); if (!string.IsNullOrEmpty(message) && string.Equals(message, ExitCommand, StringComparison.OrdinalIgnoreCase)) { Context.System.Shutdown(); return; } _validationActor.Tell(message); } }
  27. 27. class ValidationActor : UntypedActor { private readonly IActorRef _consoleWriterActor; public ValidationActor(IActorRef consoleWriterActor) { _consoleWriterActor = consoleWriterActor; } protected override void OnReceive(object message) { var msg = message as string; if (string.IsNullOrEmpty(msg)) { _consoleWriterActor.Tell(new Messages.NullInputError("No input received.")); } else { if (IsValid(msg)) {_consoleWriterActor.Tell(new Messages.InputSuccess("Thank you! Message was valid."));} else { _consoleWriterActor.Tell(new Messages.ValidationError("Invalid: input had odd number of characters.")); } } Sender.Tell(new Messages.ContinueProcessing()); } private static bool IsValid(string msg) { return = msg.Length % 2 == 0; } }
  28. 28. A B ActorRef ActorSystem Message ActorRef Message Transport Transport
  29. 29. Akka.net Docs
  30. 30. protected override void OnReceive(object message) { if (message is StartTail) { var msg = message as StartTail; // here we are creating our first parent/child relationship! // the TailActor instance created here is a child // of this instance of TailCoordinatorActor Context.ActorOf(Props.Create(() => new TailActor(msg.ReporterActor, msg.FilePath))); } } protected override SupervisorStrategy SupervisorStrategy() { return new OneForOneStrategy( 10, // maxNumberOfRetries TimeSpan.FromSeconds(30), // duration x => { //Maybe we consider ArithmeticException to not be application critical //so we just ignore the error and keep going. if (x is ArithmeticException) return Directive.Resume; //Error that we cannot recover from, stop the failing actor if (x is NotSupportedException) return Directive.Stop; //In all other cases, just restart the failing actor return Directive.Restart; }); }
  31. 31. Akka.net Bootcamp
  32. 32. private void GetAndValidateInput() { var message = Console.ReadLine(); if (!string.IsNullOrEmpty(message) && string.Equals(message, ExitCommand, StringComparison.OrdinalIgnoreCase)) { Context.System.Shutdown(); return; } Context.ActorSelection("akka://MyActorSystem/user/validationActor").Tell(message); }
  33. 33. A ActorRef ActorSystem Message ActorRef Message Transport Transport State A State B State C Props Props
  34. 34. Akka.net Bootcamp
  35. 35. A ActorRef ActorSystem Message ActorRef Message Transport Transport State A State B State C Props Props Scheduler
  36. 36. The Reactive Manifesto Responsivo Elástico Resiliente Orientado a mensagem
  37. 37. Obrigado! tinyurl.com/feedback-ej

×