Skip to content

Instantly share code, notes, and snippets.

@creepone
Last active August 29, 2015 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save creepone/080165a934b04379ef8b to your computer and use it in GitHub Desktop.
Save creepone/080165a934b04379ef8b to your computer and use it in GitHub Desktop.
Remote Deathwatch - simplest example where fast restart of one client corrupts the other one.
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="akka" type="Akka.Configuration.Hocon.AkkaConfigurationSection, Akka" />
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<appSettings>
<add key="RemoteSystem" value="akka.tcp://Test@127.0.0.1:58411" />
</appSettings>
<akka>
<hocon>
<![CDATA[
akka {
actor {
provider = "Akka.Remote.RemoteActorRefProvider, Akka.Remote"
}
remote {
helios.tcp {
transport-class = "Akka.Remote.Transport.Helios.HeliosTcpTransport, Akka.Remote"
transport-protocol = tcp
hostname = "127.0.0.1"
port = 58410
}
}
}
]]>
</hocon>
</akka>
</configuration>
using System;
using System.Configuration;
using System.Threading;
using Akka.Actor;
namespace RemoteDeatchwatch
{
class Program
{
static void Main(string[] args)
{
var actorSystem = ActorSystem.Create("Test");
var dummyActor = actorSystem.ActorOf(Props.Create<DummyActor>(), "dummy");
var remoteCounterpartAddress = string.Format("{0}/user/dummy", ConfigurationManager.AppSettings["RemoteSystem"]);
Thread.Sleep(20000);
// simulate our dummy talking to the remote dummy
actorSystem.ActorSelection(remoteCounterpartAddress).Tell(new DummyActor.Init(), dummyActor);
Console.ReadLine();
actorSystem.Shutdown();
}
}
public class DummyActor : ReceiveActor
{
public DummyActor()
{
Receive<Init>(_ =>
{
Console.WriteLine("Deathwatch starting.");
Context.Watch(Sender);
});
Receive<Terminated>(terminated =>
{
Console.WriteLine("Peer terminated.");
});
}
public class Init
{
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment