private async Task RefreshSaga(SagaInfo originatingSaga) { _eventAggregator.Publish(new WorkStarted("Loading message body...")); if (Data == null || Data.SagaId != originatingSaga.SagaId) { Data = await _serviceControl.GetSagaById(originatingSaga.SagaId.ToString()); if (Data == SagaData.Empty) { ShowSagaNotFoundWarning = true; Data = null; } else if (Data != null && Data.Changes != null) { ProcessDataValues(Data.Changes); } else { Data = null; } } if (ShowMessageData) { RefreshMessageProperties(); } RefreshShowData(); _eventAggregator.Publish(new WorkFinished()); }
public IMessageContext WrapCommand(ICommand command, bool needReply = false, SagaInfo sagaInfo = null, string producer = null) { throw new NotImplementedException(); }
public IMessageContext WrapMessage(object message, string correlationId = null, string topic = null, string key = null, string replyEndPoint = null, string messageId = null, SagaInfo sagaInfo = null, string producer = null) { var messageContext = new MessageContext(message, messageId); messageContext.Producer = producer; messageContext.IP = Utility.GetLocalIPV4()?.ToString(); if (!string.IsNullOrEmpty(correlationId)) { messageContext.CorrelationID = correlationId; } if (!string.IsNullOrEmpty(topic)) { messageContext.Topic = topic; } if (!string.IsNullOrEmpty(key)) { messageContext.Key = key; } if (!string.IsNullOrEmpty(replyEndPoint)) { messageContext.ReplyToEndPoint = replyEndPoint; } if (sagaInfo != null && !string.IsNullOrWhiteSpace(sagaInfo.SagaId)) { messageContext.SagaInfo = sagaInfo; } return(messageContext); }
public IMessageContext WrapMessage(object message, string correlationId = null, string topic = null, string key = null, string replyEndPoint = null, string messageId = null, SagaInfo sagaInfo = null) { var messageContext = new MessageContext(message, messageId); if (!string.IsNullOrEmpty(correlationId)) { messageContext.CorrelationID = correlationId; } if (!string.IsNullOrEmpty(topic)) { messageContext.Topic = topic; } if (!string.IsNullOrEmpty(key)) { messageContext.Key = key; } if (!string.IsNullOrEmpty(replyEndPoint)) { messageContext.ReplyToEndPoint = replyEndPoint; } if (sagaInfo != null) { messageContext.SagaInfo = sagaInfo; } return(messageContext); }
public SagaInvocation(SagaInfo saga, StoredMessage triggeringMessage) { ID = saga.SagaId; SagaType = TypeHumanizer.ToName(saga.SagaType); IsSagaCompleted = saga.ChangeStatus == "Completed"; IsSagaInitiated = string.IsNullOrEmpty(triggeringMessage.GetHeaderByKey(MessageHeaderKeys.SagaId)) && !string.IsNullOrEmpty(triggeringMessage.GetHeaderByKey(MessageHeaderKeys.OriginatedSagaId)); }
void RefreshSaga(SagaInfo originatingSaga) { try { eventAggregator.PublishOnUIThread(new WorkStarted("Loading message body...")); var previousSagaId = Guid.Empty; if (Data == null || Data.SagaId != originatingSaga.SagaId) { if (Data != null) { previousSagaId = Data.SagaId; } Data = serviceControl.GetSagaById(originatingSaga.SagaId); if (Data != null) { if (Data.SagaId == Guid.Empty) { ShowSagaNotFoundWarning = true; Data = null; } else if (Data.Changes != null) { ProcessDataValues(Data.Changes); } else { Data = null; } } } if (Data == null || Data.Changes == null) { return; } // Skip refreshing if we already displaying the correct saga data if (previousSagaId == Data.SagaId) { return; } RefreshShowData(); if (ShowMessageData) { RefreshMessageProperties(); } } finally { eventAggregator.PublishOnUIThread(new WorkFinished()); } }
public IMessageContext WrapMessage(object message, string correlationId = null, string topic = null, string key = null, string replyEndPoint = null, string messageId = null, SagaInfo sagaInfo = null, string producer = null) { throw new NotImplementedException(); }
void RefreshSaga(SagaInfo originatingSaga) { using (workNotifier.NotifyOfWork("Loading message body...")) { var previousSagaId = Guid.Empty; if (Data == null || Data.SagaId != originatingSaga.SagaId) { if (Data != null) { previousSagaId = Data.SagaId; } Data = FetchOrderedSagaData(originatingSaga.SagaId); if (Data != null) { if (Data.SagaId == Guid.Empty) { ShowSagaNotFoundWarning = true; Data = null; } else if (Data.Changes != null) { ProcessDataValues(Data.Changes); } else { Data = null; } } } if (Data == null || Data.Changes == null) { return; } // Skip refreshing if we already displaying the correct saga data if (previousSagaId == Data.SagaId) { return; } RefreshShowData(); if (ShowMessageData) { RefreshMessageProperties(); } } }
private static void Main(string[] args) { var sagaInfo = new SagaInfo { DatabaseName = "Put Raven database name here", SagaDataTypeFullName = "Put saga data type full name here", SagaKeyPrefix = "Put saga key prefix here", UniqueField = "Put field name that is decorated by Unique attribute here", RavenUrl = "http://localhost:8080", }; new SetSagaUniqueValueInMetadata().Run(sagaInfo); new PopulateSagaUniqueIdentityRecords().Run(sagaInfo); }
public IMessageContext WrapCommand(ICommand command, bool needReply, SagaInfo sagaInfo = null, string producer = null) { if (string.IsNullOrEmpty(command.Id)) { var noMessageIdException = new NoMessageId(); Logger.LogError(noMessageIdException, $"{command.ToJson()}"); throw noMessageIdException; } string commandKey = command.Key; if (command is ILinearCommand linearCommand) { var linearKey = _linearCommandManager.GetLinearKey(linearCommand); if (linearKey != null) { commandKey = linearKey.ToString(); command.Key = commandKey; } } IMessageContext commandContext = null; #region pickup a queue to send command // move this logic into concrete messagequeueClient. kafka sdk already implement it. // service bus client still need it. //int keyUniqueCode = !string.IsNullOrWhiteSpace(commandKey) ? // commandKey.GetUniqueCode() : command.Id.GetUniqueCode(); //var queue = _commandQueueNames[Math.Abs(keyUniqueCode % _commandQueueNames.Length)]; #endregion var topic = command.GetFormatTopic(); commandContext = MessageQueueClient.WrapMessage(command, topic: topic, key: commandKey, replyEndPoint: needReply ? _replyTopicName : null, sagaInfo: sagaInfo, producer: producer ?? _consumerId); if (string.IsNullOrEmpty(commandContext.Topic)) { throw new NoCommandTopic(); } return(commandContext); }
public IMessageContext WrapMessage(object message, string correlationId = null, string topic = null, string key = null, string replyEndPoint = null, string messageId = null, SagaInfo sagaInfo = null, string producer = null) { return(_clientProvider.WrapMessage(message, correlationId, topic, key, replyEndPoint, messageId, sagaInfo, producer)); }
public Task <MessageResponse> StartSaga(ICommand command, CancellationToken sendCancellationToken, TimeSpan sendTimeout, CancellationToken replyCancellationToken, string sagaId = null) { sagaId = sagaId ?? ObjectId.GenerateNewId().ToString(); SagaInfo sagaInfo = null; if (!string.IsNullOrEmpty(sagaId)) { sagaInfo = new SagaInfo { SagaId = sagaId, ReplyEndPoint = _replyTopicName }; } var commandContext = WrapCommand(command, false, sagaInfo); var commandState = BuildCommandState(commandContext, sendCancellationToken, sendTimeout, replyCancellationToken, true); _commandStateQueues.GetOrAdd(sagaId, commandState); SendAsync(commandState); return(commandState.SendTaskCompletionSource.Task); }
public async Task <MessageResponse> StartSaga(ICommand command, CancellationToken sendCancellationToken, TimeSpan sendTimeout, CancellationToken replyCancellationToken, string sagaId = null) { sagaId = sagaId ?? ObjectId.GenerateNewId().ToString(); var sagaInfo = new SagaInfo { SagaId = sagaId, ReplyEndPoint = _replyTopicName }; var commandContext = WrapCommand(command, false, sagaInfo); var commandState = BuildCommandState(commandContext, sendCancellationToken, sendTimeout, replyCancellationToken, true); _commandStateQueues.GetOrAdd(sagaId, commandState); return((await SendAsync(sendCancellationToken, commandState).ConfigureAwait(false)) .FirstOrDefault()); }
private async Task <Tuple <SagaInfo, CheckoutInfo> > LoadFromStorage(Guid correlationId, Guid?orderId = null) { var sagaInfo = await _repository.GetByIdAsync(correlationId); CheckoutInfo internalData; if (sagaInfo != null) { internalData = sagaInfo.Data.ToObject <CheckoutInfo>(); } else { if (!orderId.HasValue) { throw new Exception("Need to have an order id for the first time."); } var order = await _restClient.GetAsync <Order>("order_service", $"/api/orders/{orderId.Value}"); internalData = new CheckoutInfo { OrderId = order.Id, CustomerId = order.CustomerId, EmployeeId = order.EmployeeId, OrderDate = order.OrderDate, OrderStatus = (int)order.OrderStatus, Products = order.OrderDetails.Select(x => new ProductInfo { ProductId = x.ProductId, Quantity = x.Quantity }).ToList() }; var saga = new SagaInfo { Id = correlationId, // correlation id Data = internalData.ToString <CheckoutInfo>() }; sagaInfo = await _repository.AddAsync(saga); } return(new Tuple <SagaInfo, CheckoutInfo>(sagaInfo, internalData)); }
private List <MessageState> GetSagaReplyMessageStates(SagaInfo sagaInfo, IEventBus eventBus) { var eventMessageStates = new List <MessageState>(); if (sagaInfo != null && !string.IsNullOrWhiteSpace(sagaInfo.SagaId)) { eventBus.GetSagaResults() .ForEach(sagaResult => { var topic = sagaInfo.ReplyEndPoint; if (!string.IsNullOrEmpty(topic)) { var sagaReply = _messageQueueClient.WrapMessage(sagaResult, topic: topic, messageId: ObjectId.GenerateNewId().ToString(), sagaInfo: sagaInfo, producer: Producer); eventMessageStates.Add(new MessageState(sagaReply)); } }); } return(eventMessageStates); }
public IMessageContext WrapCommand(ICommand command, bool needReply, SagaInfo sagaInfo = null) { if (string.IsNullOrEmpty(command.ID)) { _logger.Error(new NoMessageId()); throw new NoMessageId(); } string commandKey = null; if (command is ILinearCommand) { var linearKey = _linearCommandManager.GetLinearKey(command as ILinearCommand); if (linearKey != null) { commandKey = linearKey.ToString(); } } IMessageContext commandContext = null; #region pickup a queue to send command // move this logic into concrete messagequeueClient. kafka sdk already implement it. // service bus client still need it. //int keyUniqueCode = !string.IsNullOrWhiteSpace(commandKey) ? // commandKey.GetUniqueCode() : command.ID.GetUniqueCode(); //var queue = _commandQueueNames[Math.Abs(keyUniqueCode % _commandQueueNames.Length)]; #endregion commandContext = _messageQueueClient.WrapMessage(command, key: commandKey, replyEndPoint: needReply ? _replyTopicName : null, sagaInfo: sagaInfo); if (string.IsNullOrEmpty(commandContext.Topic)) { throw new NoCommandTopic(); } return(commandContext); }
public IMessageContext WrapMessage(object message, string correlationId = null, string topic = null, string key = null, string replyEndPoint = null, string messageId = null, SagaInfo sagaInfo = null, string producer = null) { if (message is Exception ex) { if (ex is DomainException domainException) { // Remove inner Exception because it too large after serializing message = new DomainException(domainException.ErrorCode, domainException.Message); } else { message = new Exception(ex.GetBaseException().Message); } } var messageContext = _clientProvider.WrapMessage(message, correlationId, topic, key, replyEndPoint, messageId, sagaInfo, producer); if (string.IsNullOrWhiteSpace(messageContext.Key)) { messageContext.Key = messageContext.MessageId; } return(messageContext); }
public IMessageContext WrapMessage(object message, string correlationId = null, string topic = null, string key = null, string replyEndPoint = null, string messageId = null, SagaInfo sagaInfo = null, string producer = null) { if (message is Exception ex) { if (ex is DomainException domainException) { // Remove inner Exception because it too large after serializing message = new DomainException(domainException.ErrorCode, domainException.Message); } else { message = new Exception(ex.GetBaseException().Message); } } var messageContext = new MessageContext(message, messageId) { Producer = producer, Ip = Utility.GetLocalIpv4()?.ToString() }; if (!string.IsNullOrEmpty(correlationId)) { messageContext.CorrelationId = correlationId; } if (!string.IsNullOrEmpty(topic)) { messageContext.Topic = topic; } if (!string.IsNullOrEmpty(key)) { messageContext.Key = key; } if (string.IsNullOrWhiteSpace(messageContext.Key)) { messageContext.Key = messageContext.MessageId; } if (!string.IsNullOrEmpty(replyEndPoint)) { messageContext.ReplyToEndPoint = replyEndPoint; } if (!string.IsNullOrWhiteSpace(sagaInfo?.SagaId)) { messageContext.SagaInfo = sagaInfo; } return(messageContext); }
public IMessageContext WrapMessage(object message, string correlationId = null, string topic = null, string key = null, string replyEndPoint = null, string messageId = null, SagaInfo sagaInfo = null, string producer = null) { return(new EmptyMessageContext()); }
internal async Task Remove(SagaInfo saga) { using var context = _serviceProvider.GetRequiredService <SagaContext>(); context.Remove(saga); await context.SaveChangesAsync(); }
public C.Saga UpdateSaga(int id, SagaInfo apiClassInfo) { return(_service.Update(id, new C.Saga(id, apiClassInfo.SagaName))); }
public C.Saga AddQuote(SagaInfo apiClassInfo) { return(_service.Insert(new C.Saga(apiClassInfo.SagaName))); }