From d3bc8e3aba85cd9c0320844f15ad735b6dc589c8 Mon Sep 17 00:00:00 2001 From: Alan Doherty Date: Mon, 10 Dec 2018 17:55:23 +0000 Subject: [PATCH] Minor event alterations - Moved to 0.1.6.3 --- samples/Example.General/Program.cs | 36 +++++++++++-------- src/Holon/Events/Event.cs | 1 + .../Serializers/ProtobufEventSerializer.cs | 5 +-- src/Holon/Holon.csproj | 6 ++-- 4 files changed, 28 insertions(+), 20 deletions(-) diff --git a/samples/Example.General/Program.cs b/samples/Example.General/Program.cs index 25c1e10..3f255cb 100644 --- a/samples/Example.General/Program.cs +++ b/samples/Example.General/Program.cs @@ -50,16 +50,25 @@ public Test001(Guid uuid) { } } + class EventObserver : IObserver + { + public void OnCompleted() { + } + + public void OnError(Exception error) { + } + + public void OnNext(Event value) { + + } + } + class Program { public static Node TestNode { get; set; } static void Main(string[] args) => AsyncMain(args).Wait(); - - class EventTest - { - public string Potato { get; set; } - } + static async Task AsyncMain(string[] args) { // attach node @@ -67,20 +76,17 @@ static async Task AsyncMain(string[] args) { ThrowUnhandledExceptions = true }); - TestNode.TraceBegin += (o, e) => Console.WriteLine($"Begin trace {e.TraceId} for {e.Envelope.ID} at {DateTime.UtcNow}"); - TestNode.TraceEnd += (o, e) => Console.WriteLine($"End trace {e.TraceId} for {e.Envelope.ID} at {DateTime.UtcNow}"); - // attach - await TestNode.AttachAsync("auth:login", RpcBehaviour.Bind(new Test001(Guid.NewGuid()))); + //await TestNode.AttachAsync("auth:login", RpcBehaviour.Bind(new Test001(Guid.NewGuid()))); + + // subscribe + (await TestNode.SubscribeAsync("auth:login.happened")) + .AsObservable().Subscribe(new EventObserver()); - ITest001 proxy = TestNode.Proxy("auth:login", new ProxyConfiguration() { - TraceId = Guid.NewGuid().ToString() - }); - - await proxy.Login(new LoginRequestMsg() { + await TestNode.EmitAsync("auth:login.happened", new LoginRequestMsg() { Password = "password", Username = "username" - }); + }).ConfigureAwait(false); await Task.Delay(50000); } diff --git a/src/Holon/Events/Event.cs b/src/Holon/Events/Event.cs index 2fed99b..713b187 100644 --- a/src/Holon/Events/Event.cs +++ b/src/Holon/Events/Event.cs @@ -165,6 +165,7 @@ internal Event(string id, string @namespace, string resource, string name, byte[ _namespace = @namespace; _name = name; _data = data; + _timestamp = DateTime.UtcNow; } #endregion } diff --git a/src/Holon/Events/Serializers/ProtobufEventSerializer.cs b/src/Holon/Events/Serializers/ProtobufEventSerializer.cs index bec0ded..ae60f86 100644 --- a/src/Holon/Events/Serializers/ProtobufEventSerializer.cs +++ b/src/Holon/Events/Serializers/ProtobufEventSerializer.cs @@ -31,7 +31,7 @@ public Event DeserializeEvent(byte[] body) { using (MemoryStream ms = new MemoryStream(body)) { EventMsg msg = Serializer.Deserialize(ms); - return new Event(msg.ID, msg.Namespace, msg.Resource, msg.Name, msg.Data); + return new Event(msg.ID, msg.Namespace, msg.Resource, msg.Name, msg.Data); } } @@ -42,7 +42,8 @@ public byte[] SerializeEvent(Event e) { eventMsg.Type = "serialized"; eventMsg.Data = e.Data; eventMsg.Resource = e.Resource; - eventMsg.Namespace = e.Name; + eventMsg.Namespace = e.Namespace; + eventMsg.ID = e.ID; Serializer.Serialize(ms, eventMsg); return ms.ToArray(); } diff --git a/src/Holon/Holon.csproj b/src/Holon/Holon.csproj index 9a72468..87c166e 100644 --- a/src/Holon/Holon.csproj +++ b/src/Holon/Holon.csproj @@ -2,7 +2,7 @@ netstandard1.6 - 0.1.6.2 + 0.1.6.3 Alan Doherty Alan Doherty A minimal service and event bus with additional support for RPC @@ -10,11 +10,11 @@ https://github.com/alandoherty/holon-net https://github.com/alandoherty/holon-net git - 0.1.6.2 + 0.1.6.3 https://github.com/alandoherty/holon-net/blob/master/LICENSE true https://s3-eu-west-1.amazonaws.com/assets.alandoherty.co.uk/github/holon-net-nuget.png - 0.1.6.2 + 0.1.6.3