RELEASE_NOTES.md
with a new version bump. Follow the convention there.master
branch once all of the changes have been brought in.@Horusiath I am doing some test of an Actor that supposes to write into file upon receiving every event. The actor subscribes to the type of event to receive. However when I published N number of events to the event bus the actor only act on the first event by writing it into the file. The others are kind of ignored. This is the test code
ActorSystemRefs.ActorSystem = Sys;
var actorSystem = ActorSystemRefs.ActorSystem;
var loggingActor =
actorSystem.ActorOf(Props.Create(() => new FileLoggerActor()));
actorSystem.EventStream.Subscribe(loggingActor, typeof (AuditLog));
actorSystem.EventStream.Subscribe(TestActor, typeof(Acknowleged));
Within(TimeSpan.FromSeconds(timeout),
() =>
{
actorSystem.EventStream.Publish(new AuditLog(GuidFactory.Create().ToString(), DateTime.UtcNow, "me", "0000", "debit1", "mobile"));
actorSystem.EventStream.Publish(new AuditLog(GuidFactory.Create().ToString(), DateTime.UtcNow, "me", "0000", "debit2", "mobile"));
actorSystem.EventStream.Publish(new AuditLog(GuidFactory.Create().ToString(), DateTime.UtcNow, "me", "0000", "debit3", "mobile"));
var result = ExpectMsgAllOf<Acknowleged>();
Assert.NotNull(result);
});
and this is the Actor:
public class FileLoggerActor : ReceiveActor
{
private static string _filePath;
public FileLoggerActor()
{
Ready();
}
public override void AroundPreStart()
{
ReadConfiguration();
}
public sealed override void Ready()
{
Receive<AuditLog>(log =>
{
WriteToFile(log);
// This code is for testing purpose
ActorSystemRefs.PushEvent(new Acknowleged(log));
});
}
private static void ReadConfiguration()
{
_filePath = ConfigurationManager.AppSettings["FileLogger.FilePath"];
if (_filePath == null)
{
throw new ConfigurationErrorsException(
"Configuration appSetting FileLogger.FilePath not" +
"found for FileLogger actor.");
}
// If audit trail file path is a relative file path,
// convert it to an absolute path.
_filePath = _filePath.Replace("~", AppDomain.CurrentDomain.BaseDirectory);
}
private static void WriteToFile(AuditLog log)
{
var jsonString = JsonConvert.SerializeObject(log, Formatting.None);
File.AppendAllText(_filePath, jsonString + Environment.NewLine);
}
}