public Task Evict <T>(string bucket, string streamId) where T : class, IEventSource { var streamName = _streamGen(typeof(T), bucket + ".SNAP", streamId); _cache.Evict(streamName); return(Task.CompletedTask); }
public async Task WriteEvents(String bucket, String stream, Int32 expectedVersion, IEnumerable <IWritableEvent> events, IDictionary <String, String> commitHeaders) { Logger.DebugFormat("Writing {0} events to stream id '{1}'. Expected version: {2}", events.Count(), stream, expectedVersion); var streamId = String.Format("{0}.{1}", bucket, stream); if (_shouldCache) { _cache.Evict(streamId); } var settings = new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.All, Binder = new EventSerializationBinder(_mapper) }; var translatedEvents = events.Select(e => { var descriptor = new EventDescriptor { EntityType = e.Descriptor.EntityType, Timestamp = e.Descriptor.Timestamp, Version = e.Descriptor.Version, Headers = e.Descriptor.Headers.Merge(commitHeaders) }; var mappedType = _mapper.GetMappedTypeFor(e.Event.GetType()); return(new EventData( e.EventId, mappedType.AssemblyQualifiedName, true, e.Event.Serialize(settings).AsByteArray(), descriptor.Serialize(settings).AsByteArray() )); }); try { await _client.AppendToStreamAsync(streamId, expectedVersion, translatedEvents); } catch (global::System.AggregateException e) { throw e.InnerException; } }
public void SubscribeToAll(String endpoint) { var readSize = _settings.Get <Int32>("ReadSize"); Logger.InfoFormat("Endpoint '{0}' subscribing to all events from END", endpoint); _client.SubscribeToAllFrom(Position.End, false, (subscription, e) => { // Unsure if we need to care about events from eventstore currently if (!e.Event.IsJson) { return; } _cache.Evict(e.OriginalStreamId); var descriptor = e.Event.Metadata.Deserialize(_jsonSettings); if (descriptor == null) { return; } // Check if the event was written by this domain handler // We don't need to publish events saved by other domain instances String header = null; Guid domain = Guid.Empty; if (descriptor.Headers == null || !descriptor.Headers.TryGetValue(Defaults.DomainHeader, out header) || !Guid.TryParse(header, out domain) || domain != Defaults.Domain) { return; } var data = e.Event.Data.Deserialize(e.Event.EventType, _jsonSettings); // Data is null for certain irrelevant eventstore messages (and we don't need to store position) if (data == null) { return; } try { _dispatcher.Dispatch(data, descriptor, e.OriginalPosition?.CommitPosition); } catch (SubscriptionCanceled) { subscription.Stop(); throw; } }, liveProcessingStarted: (_) => { Logger.Info("Live processing started"); ProcessingLive = true; }, subscriptionDropped: (_, reason, e) => { Logger.WarnFormat("Subscription dropped for reason: {0}. Exception: {1}", reason, e); ProcessingLive = false; if (Dropped != null) { Dropped.Invoke(reason.ToString(), e); } }, readBatchSize: readSize); }