Created
June 6, 2015 17:10
-
-
Save NeoDarque/e955aea9de85512d9b54 to your computer and use it in GitHub Desktop.
Message missing in PreRestart?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
using Akka.Actor; | |
using Akka.Routing; | |
using AkkaLab.Messages; | |
namespace AkkaLab.Publisher { | |
class Program { | |
static void Main(string[] args) { | |
using(var system = ActorSystem.Create("my-system")) { | |
var props = Props.Create<SubscriberActor>().WithRouter(new Akka.Routing.ConsistentHashingPool(5)); | |
var subscribers = system.ActorOf(props, "subscribers"); | |
Console.WriteLine("Enter a number please..."); | |
while(true) { | |
int id = 0; | |
var text = Console.ReadLine(); | |
if(String.Equals(text, "quit", StringComparison.CurrentCultureIgnoreCase)) { | |
return; | |
} else if(Int32.TryParse(text, out id)) { | |
var payload = new PayLoad() {Id = id, Content = text}; | |
var msg = new ConsistentHashableEnvelope(payload, payload.Id); | |
subscribers.Tell(msg); | |
} else { | |
var payload = new PayLoad() { Id = -1, Content = text }; | |
var msg = new ConsistentHashableEnvelope(payload, payload.Id); | |
subscribers.Tell(msg); | |
} | |
} | |
} | |
} | |
} | |
public class SubscriberActor : UntypedActor { | |
private Guid Guid { get; set; } | |
public SubscriberActor() { | |
this.Guid = Guid.NewGuid(); | |
} | |
protected override void OnReceive(object message) { | |
if(message is PayLoad) { | |
var payload = message as PayLoad; | |
Console.WriteLine("({2}) Received content: {0} with Id: {1}", payload.Content, payload.Id, this.Guid.ToString()); | |
if(payload.Id < 0) | |
throw new Exception("Boom!"); | |
} else { | |
Console.WriteLine("Received unknown message"); | |
} | |
} | |
protected override void PreRestart(Exception reason, object message) { | |
base.PreRestart(reason, message); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment