I used akka.net persistence to store some message type in sql server database. And on that business scenario it works. In other case i just wanted to deserialize message using C# .net and see the message property without akka.net. how could it possible?
1 Answers
In Akka.Persistence with configured SQL journal, all of your event data lands as serialized binary in the Payload
column of a table used for event sourcing (on SQLServer by default it's dbo.EventJournal
). In the future there will be a possibility to change this format from binary into JSON data type if your database of choice will support that format.
Depending on which serializer you use, you can simply retrieve original event by simply deserializing content of Payload column. While you should never use default serializer, if you already did, you need to know that at the moment of v1.2 it's JSON.NET. You can simply deserialize it using JsonConvert
with preserving object references (PreserveReferencesHandling.Objects):
byte[] payload = ...; // get bytes from Payload column
var settings = new JsonSerializerSettings {PreserveReferencesHandling = PreserveReferencesHandling.Objects};
using (var stream = new MemoryStream(payload))
using (var reader = new StreamReader(stream))
{
var domainEvent = JsonConvert.DeserializeObject(reader.ReadToEnd(), settings);
}
Other fields of the event journal table carry metadata describing things like total order of events (used by tagging feature) and most notably, persistence id of an actor and a sequence number of a particular event (which is growing monotonically in context of a single actor).