示例#1
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="eventProcessorId"></param>
 /// <param name="committedEventVersion"></param>
 /// <param name="partitionKey"></param>
 /// <returns></returns>
 public static Offset From(EventProcessorId eventProcessorId, CommittedEventVersion committedEventVersion, string partitionKey)
 {
     return(new Offset {
         Id = eventProcessorId.ToString(), Major = committedEventVersion.Major, Minor = committedEventVersion.Minor,
         Revision = committedEventVersion.Revision, PartitionKey = partitionKey
     });
 }
示例#2
0
        CommittedEvent ToCommittedEvent(CommitSequenceNumber commitSequenceNumber, EventEnvelope @event)
        {
            var eventType             = _artifactTypeMap.GetTypeFor(@event.Metadata.Artifact);
            var eventInstance         = _objectFactory.Build(eventType, @event.Event) as IEvent;
            var committedEventVersion = new CommittedEventVersion(commitSequenceNumber, @event.Metadata.VersionedEventSource.Version.Commit, @event.Metadata.VersionedEventSource.Version.Sequence);

            return(new CommittedEvent(committedEventVersion, @event.Metadata, eventInstance));
        }
示例#3
0
 /// <inheritdoc />
 public SingleEventTypeEventStream GetUnprocessedEvents(ArtifactId eventType, CommittedEventVersion committedEventVersion)
 {
     using (var eventStore = _getEventStore())
     {
         var eventStream = eventStore.FetchAllEventsOfTypeAfter(eventType, committedEventVersion.Major);
         return(new SingleEventTypeEventStream(eventStream.Where(e => e.Version > committedEventVersion)));
     }
 }
 /// <inheritdoc />
 public void Set(EventProcessorId eventProcessorId, CommittedEventVersion committedEventVersion)
 {
     _connection.AppendToStreamAsync(
         GetStreamForEventProcessorId(eventProcessorId),
         ExpectedVersion.Any,
         CreateCommittedEventVersionEvent(committedEventVersion)
         ).Wait();
 }
 /// <summary>
 /// Converts a <see cref="CommittedEventVersion" /> into its <see cref="BsonDocument" /> representation
 /// </summary>
 /// <param name="version">The <see cref="CommittedEventVersion" /></param>
 /// <returns>A <see cref="BsonDocument" /> representation of the <see cref="CommittedEventVersion" /></returns>
 public static BsonDocument AsBson(this CommittedEventVersion version)
 {
     return(new BsonDocument(new Dictionary <string, object>
     {
         { Constants.MAJOR_VERSION, version.Major },
         { Constants.MINOR_VERSION, version.Minor },
         { Constants.REVISION, version.Revision }
     }));
 }
        /// <inheritdoc />
        public void Set(EventProcessorId eventProcessorId, CommittedEventVersion committedEventVersion)
        {
            var versionBson = committedEventVersion.AsBson();

            versionBson.Add(Constants.ID, eventProcessorId.Value);
            _offsets.ReplaceOne(eventProcessorId.ToFilter(), versionBson, new UpdateOptions {
                IsUpsert = true
            });
        }
 EventData CreateCommittedEventVersionEvent(CommittedEventVersion committedEventVersion)
 {
     return(new EventData(
                Guid.NewGuid(),
                "EventProcessorOffset",
                true,
                _serializer.ToJsonBytes(committedEventVersion),
                Array.Empty <byte>()
                ));
 }
 /// <inheritdoc />
 public void Set(EventProcessorId eventProcessorId, CommittedEventVersion committedEventVersion)
 {
     using (var es = _database.GetContext())
     {
         //TODO: this can be optimized so that the update is the thing we expect most and the insert is the edge case
         var commandText = "INSERT OR REPLACE INTO Offsets (Id, Major, Minor, Revision) VALUES (@Id,@Major,@Minor,@Revision);";
         var id          = new SqliteParameter("@Id", eventProcessorId.Value.ToString());
         var major       = new SqliteParameter("@Major", committedEventVersion.Major);
         var minor       = new SqliteParameter("@Minor", committedEventVersion.Minor);
         var revision    = new SqliteParameter("@Revision", committedEventVersion.Revision);
         es.Database.ExecuteSqlCommand(commandText, id, major, minor, revision);
     }
 }
示例#9
0
文件: given.cs 项目: woksin/Runtime
        public static List <CommittedEventStream> committed_event_streams(CommittedEventVersion startingCommit = null, uint numberOfCommits = 3)
        {
            var commits = new List <CommittedEventStream>();
            CommittedEventVersion version = startingCommit;

            for (int i = 0; i < numberOfCommits; i++)
            {
                var commit = Dolittle.Runtime.Events.Specs.given.Events.Build(version);
                commits.Add(commit);
                version = commit.LastEventVersion;
            }
            return(commits);
        }
        async Task SetAsync(EventProcessorId eventProcessorId, CommittedEventVersion committedEventVersion)
        {
            var offset = Offset.From(eventProcessorId, committedEventVersion, _config.BasePartitionKey);

            try
            {
                var result = await _config.Client.UpsertDocumentAsync(_config.OffsetsUri, offset, new RequestOptions { PartitionKey = new PartitionKey(_config.BasePartitionKey) });

                _logger.Debug(ResponseMetadata.FromOffset("Setting Offset", result)?.ToString());
            }
            catch (DocumentClientException ex)
            {
                throw new EventStorePersistenceError("Error", ex);
            }
        }
示例#11
0
 void SetCurrentVersion(CommittedEventVersion committedEventVersion)
 {
     //the provider should accept the version and is responsible for transient errors and persisting it eventually
     try
     {
         LastVersionProcessed = committedEventVersion;
         using (var repository = _getOffsetRepository())
         {
             repository.Set(ProcessorId, LastVersionProcessed);
         }
     }
     catch (Exception ex)
     {
         _logger.Error($"Error setting offset for '{ProcessorId}' : '{committedEventVersion}' - {ex.ToString()}");
     }
 }
示例#12
0
        public static CommittedEventStream Build(CommittedEventVersion previousVersion = null)
        {
            CommittedEventVersion version;

            if (previousVersion != null)
            {
                version = new CommittedEventVersion(previousVersion.Major + 1, previousVersion.Minor + 1, 0);
            }
            else
            {
                version = new CommittedEventVersion(1, 1, 0);
            }

            var versionedEventSource = new VersionedEventSource(new EventSourceVersion(version.Minor, version.Revision), new EventSourceKey(event_source_id, Artifacts.artifact_for_event_source.Id));
            var now           = DateTimeOffset.UtcNow;
            var correlationId = CorrelationId.New();
            var eventStream   = BuildEventStreamFrom(versionedEventSource, now, correlationId, BuildEvents());

            return(new CommittedEventStream(version.Major, eventStream.Last().Metadata.VersionedEventSource, CommitId.New(), correlationId, now, eventStream));
        }
示例#13
0
 public void Set(EventProcessorId eventProcessorId, CommittedEventVersion committedEventVersion)
 {
 }
示例#14
0
        public static CommittedEvent build_committed_event(VersionedEventSource versionedEventSource, IEvent @event, CommittedEventVersion version)
        {
            var metadata = new EventMetadata(EventId.New(), versionedEventSource, CorrelationId.New(), new Artifact(ArtifactId.New(), 1), DateTime.UtcNow, GetOriginalContext());

            return(new CommittedEvent(version, metadata, @event));
        }
示例#15
0
 /// <inheritdoc />
 public void Set(EventProcessorId eventProcessorId, CommittedEventVersion committedEventVersion)
 {
     _lastProcessed.AddOrUpdate(eventProcessorId, committedEventVersion, (id, v) => committedEventVersion);
 }
示例#16
0
 /// <summary>
 /// Indicates whether the processor can process the <see cref="CommittedEventVersion" /> provided.
 /// </summary>
 /// <param name="version"></param>
 /// <returns>True if the processor has caught up and the version is greater than the last processed version, otherwise false</returns>
 public bool CanProcess(CommittedEventVersion version)
 {
     return(HasCaughtUp && version > LastVersionProcessed);
 }
 /// <inheritdoc />
 public void Set(EventProcessorId eventProcessorId, CommittedEventVersion committedEventVersion)
 {
     _lastProcessed.AddOrUpdate(eventProcessorId, committedEventVersion, (id, v) => committedEventVersion);
     _logger.Information($"Saving event processor offset");
     _jsRuntime.Invoke($"{_globalObject}.save", eventProcessorId, committedEventVersion);
 }
示例#18
0
 /// <summary>
 /// Instantiates an instance of a <see cref="CommittedEvent" />
 /// </summary>
 /// <param name="version">The committed event version</param>
 /// <param name="metadata">Metadata describing the event</param>
 /// <param name="event">The <see cref="IEvent">event</see> instance</param>
 public CommittedEvent(CommittedEventVersion version, EventMetadata metadata, IEvent @event)
 {
     Version  = version;
     Metadata = metadata;
     Event    = @event;
 }
示例#19
0
文件: given.cs 项目: woksin/Runtime
 public void Set(EventProcessorId eventProcessorId, CommittedEventVersion committedEventVersion)
 {
     _offsets.AddOrUpdate(eventProcessorId, committedEventVersion, (id, vsn) => committedEventVersion);
 }
 public EventProcessorOffset(EventProcessorId eventProcessorId, CommittedEventVersion content)
 {
     EventProcessorId = eventProcessorId;
     Content          = content;
 }
 /// <inheritdoc />
 public void Set(EventProcessorId eventProcessorId, CommittedEventVersion committedEventVersion)
 {
     SetAsync(eventProcessorId, committedEventVersion).GetAwaiter().GetResult();
 }