private void HandleMessageAsync(X processingMessage, int retryTimes) { var message = processingMessage.Message; _ioHelper.TryAsyncActionRecursively("GetPublishedVersionAsync", () => _publishedVersionStore.GetPublishedVersionAsync(Name, message.AggregateRootTypeName, message.AggregateRootStringId), currentRetryTimes => HandleMessageAsync(processingMessage, currentRetryTimes), result => { var publishedVersion = result.Data; if (publishedVersion + 1 == message.Version) { DispatchProcessingMessageAsync(processingMessage, 0); } else if (publishedVersion + 1 < message.Version) { _logger.InfoFormat("The sequence message cannot be process now as the version is not the next version, it will be handle later. contextInfo [aggregateRootId={0},lastPublishedVersion={1},messageVersion={2}]", message.AggregateRootStringId, publishedVersion, message.Version); processingMessage.AddToWaitingList(); } else { processingMessage.Complete(); } }, () => string.Format("sequence message [messageId:{0}, messageType:{1}, aggregateRootId:{2}, aggregateRootVersion:{3}]", message.Id, message.GetType().Name, message.AggregateRootStringId, message.Version), errorMessage => { _logger.Fatal(string.Format("Get published version has unknown exception, the code should not be run to here, errorMessage: {0}", errorMessage)); }, retryTimes, true); }
public async Task Should_Insert_Published_Version() { //Arrange var processName = "test1"; var aggregateId = ObjectId.GenerateNewStringId(); var aggregateTypeName = _typeNameProvider.GetTypeName(typeof(Product)); var version = 1; //Act await _store.UpdatePublishedVersionAsync(processName, aggregateTypeName, aggregateId, version); //Assert var publishedVersion = await _store.GetPublishedVersionAsync(processName, aggregateTypeName, aggregateId); publishedVersion.ShouldBe(version); }
private async Task <int> GetAggregateRootLatestPublishedEventVersion(string aggregateRootTypeName, string aggregateRootId) { try { return(await _publishedVersionStore.GetPublishedVersionAsync(Name, aggregateRootTypeName, aggregateRootId)); } catch (Exception ex) { throw new Exception(string.Format("_publishedVersionStore.GetPublishedVersionAsync has unknown exception, aggregateRootTypeName: {0}, aggregateRootId: {1}", aggregateRootTypeName, aggregateRootId), ex); } }
private int GetAggregateRootLatestHandledEventVersion(string aggregateRootTypeName, string aggregateRootId) { try { return(_publishedVersionStore.GetPublishedVersionAsync(Name, aggregateRootTypeName, aggregateRootId).Result); } catch (Exception ex) { throw new Exception(string.Format("_publishedVersionStore.GetPublishedVersionAsync has unknown exception, aggregateRootTypeName: {0}, aggregateRootId: {1}", aggregateRootTypeName, aggregateRootId), ex); } }
private void GetAggregateRootLatestPublishedEventVersion(ProcessingEventMailBox processingEventMailBox, int retryTimes) { _ioHelper.TryAsyncActionRecursively("GetAggregateRootLatestPublishedEventVersion", () => _publishedVersionStore.GetPublishedVersionAsync(Name, processingEventMailBox.AggregateRootTypeName, processingEventMailBox.AggregateRootId), currentRetryTimes => GetAggregateRootLatestPublishedEventVersion(processingEventMailBox, currentRetryTimes), result => { processingEventMailBox.SetNextExpectingEventVersion(result + 1); _refreshingAggregateRootDict.TryRemove(processingEventMailBox.AggregateRootId, out bool removed); }, () => string.Format("_publishedVersionStore.GetPublishedVersionAsync has unknown exception, aggregateRootTypeName: {0}, aggregateRootId: {1}", processingEventMailBox.AggregateRootTypeName, processingEventMailBox.AggregateRootId), null, retryTimes, true); }
private int GetAggregateRootLatestHandledEventVersion(string aggregateRootType, string aggregateRootId) { try { var task = _publishedVersionStore.GetPublishedVersionAsync(_processorName, aggregateRootType, aggregateRootId); task.Wait(); if (task.Exception != null) { throw task.Exception; } else if (task.Result.Status == AsyncTaskStatus.Success) { return(task.Result.Data); } else { throw new Exception("_publishedVersionStore.GetPublishedVersionAsync has unknown exception, errorMessage: " + task.Result.ErrorMessage); } } catch (Exception ex) { throw new Exception("_publishedVersionStore.GetPublishedVersionAsync has unknown exception.", ex); } }