public async Task NotifyAsync(EventMessage message) { try { _ = message ?? throw new ArgumentNullException(nameof(message)); State.MessageCount++; State.ByteCount += message.Message.LongLength; State.LastMessageTimestamp = DateTime.UtcNow; if (!string.IsNullOrEmpty(State.Metadata.NotifyAddress)) { if (sink == null && !EventSinkFactory.IsInitialized) { IServiceIdentity identity = GrainFactory.GetGrain <IServiceIdentity>("PiraeusIdentity"); byte[] certBytes = await identity.GetCertificateAsync(); List <KeyValuePair <string, string> > kvps = await identity.GetClaimsAsync(); X509Certificate2 certificate = certBytes == null ? null : new X509Certificate2(certBytes); List <Claim> claims = GetClaims(kvps); sink = EventSinkFactory.Create(State.Metadata, claims, certificate); sink.OnResponse += Sink_OnResponse; } await sink.SendAsync(message); } else if (State.MessageLeases.Count > 0) { foreach (var observer in State.MessageLeases.Values) { observer.Notify(message); } } else { if (State.Metadata.DurableMessaging && State.Metadata.TTL.HasValue) { await QueueDurableMessageAsync(message); } else { await QueueInMemoryMessageAsync(message); } } await NotifyMetricsAsync(); } catch (Exception ex) { await logger?.LogErrorAsync(ex, "Subscription notify."); await NotifyErrorAsync(ex); throw; } }
public async Task NotifyAsync(EventMessage message) { Exception error = null; State.MessageCount++; State.ByteCount += message.Message.LongLength; State.LastMessageTimestamp = DateTime.UtcNow; try { if (!string.IsNullOrEmpty(State.Metadata.NotifyAddress)) { if (sink == null) { sink = EventSinkFactory.Create(State.Metadata); } await sink.SendAsync(message); } else if (State.MessageLeases.Count > 0) { //send to actively connected subsystem foreach (var observer in State.MessageLeases.Values) { observer.Notify(message); } } else { if (State.Metadata.DurableMessaging && State.Metadata.TTL.HasValue) //durable message queue { await QueueDurableMessageAsync(message); } else //in-memory message queue { await QueueInMemoryMessageAsync(message); } } } catch (Exception ex) { Trace.TraceWarning("Subscription publish failed to complete."); Trace.TraceError("Subscription publish error {0}", ex.Message); error = ex; //GetLogger().Log(2, Orleans.Runtime.Severity.Error, "Subscription notification exception {0}", new object[] { State.Metadata.SubscriptionUriString }, ex); } await NotifyMetricsAsync(); if (error != null) { await NotifyErrorAsync(error); } }
public async Task UpsertMetadataAsync(SubscriptionMetadata metadata) { try { _ = metadata ?? throw new ArgumentNullException(nameof(metadata)); State.Metadata = metadata; await WriteStateAsync(); if (sink != null) { sink = EventSinkFactory.Create(State.Metadata); } } catch (Exception ex) { await logger?.LogErrorAsync(ex, "Subscription get metadata."); await NotifyErrorAsync(ex); throw; } }
public async Task NotifyAsync(EventMessage message) { Exception error = null; State.MessageCount++; State.ByteCount += message.Message.LongLength; State.LastMessageTimestamp = DateTime.UtcNow; try { if (!string.IsNullOrEmpty(State.Metadata.NotifyAddress)) { if (sink == null) { if (!EventSinkFactory.IsInitialized) { IServiceIdentity identity = GrainFactory.GetGrain <IServiceIdentity>("PiraeusIdentity"); byte[] certBytes = await identity.GetCertificateAsync(); List <KeyValuePair <string, string> > kvps = await identity.GetClaimsAsync(); X509Certificate2 certificate = certBytes == null ? null : new X509Certificate2(certBytes); List <Claim> claims = GetClaims(kvps); sink = EventSinkFactory.Create(State.Metadata, claims, certificate); } else { sink = EventSinkFactory.Create(State.Metadata); } } await sink.SendAsync(message); } else if (State.MessageLeases.Count > 0) { //send to actively connected subsystem foreach (var observer in State.MessageLeases.Values) { observer.Notify(message); } } else { if (State.Metadata.DurableMessaging && State.Metadata.TTL.HasValue) //durable message queue { await QueueDurableMessageAsync(message); } else //in-memory message queue { await QueueInMemoryMessageAsync(message); } } } catch (Exception ex) { Trace.TraceWarning("Subscription publish failed to complete."); Trace.TraceError("Subscription publish error {0}", ex.Message); error = ex; //GetLogger().Log(2, Orleans.Runtime.Severity.Error, "Subscription notification exception {0}", new object[] { State.Metadata.SubscriptionUriString }, ex); } await NotifyMetricsAsync(); if (error != null) { await NotifyErrorAsync(error); } }