Skip to content

Instantly share code, notes, and snippets.

@amarwadi
Last active January 3, 2016 06:54
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 amarwadi/a887b26e14b0d42191b7 to your computer and use it in GitHub Desktop.
Save amarwadi/a887b26e14b0d42191b7 to your computer and use it in GitHub Desktop.
using (var system = ActorSystem.Create("example123", config))
{
MongoDbPersistence.Instance.Apply(system);
var pActor = system.ActorOf(Props.Create<SectionActor>(), "section-actor");
pActor.Tell(new CheckSeatMessage("1", "1", new List<string> {"A", "B"}));
Console.ReadLine();
}
public class SectionActor : PersistentActor
{
public SectionActor()
{
}
protected override bool ReceiveRecover(object message)
{
//throw new NotImplementedException();
if (message is SnapshotOffer)
{
var snap = ((SnapshotOffer) message).Snapshot;
}
return true;
}
protected override bool ReceiveCommand(object message)
{
try
{
PatternMatch.Match(message)
.With<CheckSeatMessage>(CheckIfSeatsAvailable);
}
catch (Exception ex)
{
}
return true;
}
private void CheckIfSeatsAvailable(CheckSeatMessage message)
{
Console.WriteLine("Checking for seats.");
Persist(message, PersistCheckSeatsMessage);
}
private void PersistCheckSeatsMessage(CheckSeatMessage obj)
{
Console.WriteLine("Persisted");
}
public override string PersistenceId => "SectionActor";
}
public class CheckSeatMessage
{
public List<string> SeatKeys { get; set; }
public string RowKey { get; set; }
public string SectionKey { get; set; }
public CheckSeatMessage(string sectionKey, string rowKey, List<string> seatKeys)
{
SeatKeys = seatKeys;
RowKey = rowKey;
SectionKey = sectionKey;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment