protected override async Task ProcessMessage(ExternalEventNotification notification, CancellationToken cancellationToken) { string lockName = $"extevt:{notification.Id}"; if (!await _distributedLock.TryAcquireLock(lockName, cancellationToken)) { return; } try { var subscriber = await _subscriberRepository.Get(notification.CasePlanInstanceId, notification.CasePlanElementInstanceId, notification.EvtName, cancellationToken); if (subscriber == null) { throw new InvalidOperationException("subscriber doesn't exist"); } subscriber.IsCaptured = true; subscriber.Parameters = notification.Parameters; await _subscriberRepository.Update(subscriber, cancellationToken); await MessageBroker.QueueCasePlanInstance(notification.CasePlanInstanceId, cancellationToken); } finally { await _distributedLock.ReleaseLock(lockName, cancellationToken); } }
protected override async Task ProcessMessage(DomainEventNotification notification, CancellationToken cancellationToken) { string lockName = $"domainevt:{notification.Id}"; if (!await _distributedLock.TryAcquireLock(lockName, cancellationToken)) { return; } try { // TODO : Add transaction !!! var assm = Assembly.GetExecutingAssembly(); var lstTask = new List <Task>(); foreach (var record in notification.Evts) { var genericType = assm.GetType(record.Type); var messageBrokerType = typeof(IDomainEvtConsumerGeneric <>).MakeGenericType(genericType); var lst = (IEnumerable <object>)_serviceProvider.GetService(typeof(IEnumerable <>).MakeGenericType(messageBrokerType)); var message = JsonConvert.DeserializeObject(record.Content, genericType); foreach (var r in lst) { await(Task) messageBrokerType.GetMethod("Handle").Invoke(r, new object[] { message, cancellationToken }); } } } finally { await _distributedLock.ReleaseLock(lockName, cancellationToken); } }
protected override async Task ProcessMessage(MessageNotification notification, CancellationToken cancellationToken) { string lockName = $"messages:{notification.Id}"; if (!await _distributedLock.TryAcquireLock(lockName, cancellationToken)) { return; } var processInstance = await _eventStoreRepository.GetLastAggregate <ProcessInstanceAggregate>(notification.ProcessInstanceId, ProcessInstanceAggregate.GetStreamName(notification.ProcessInstanceId)); try { if (processInstance == null || string.IsNullOrWhiteSpace(processInstance.AggregateId)) { throw new InvalidOperationException($"process instance '{notification.ProcessInstanceId}' doesn't exist"); } processInstance.ConsumeMessage(new MessageToken { Name = notification.MessageName, MessageContent = notification.Content }); await _commitAggregateHelper.Commit(processInstance, processInstance.GetStreamName(), cancellationToken); await MessageBroker.QueueProcessInstance(processInstance.AggregateId, false, cancellationToken); } finally { await _distributedLock.ReleaseLock(lockName, cancellationToken); } }
protected override async Task ProcessMessage(CasePlanInstanceNotification notification, CancellationToken cancellationToken) { string lockName = $"caseplaninstance:{notification.Id}"; if (!await _distributedLock.TryAcquireLock(lockName, cancellationToken)) { return; } var casePlanInstance = await _eventStoreRepository.GetLastAggregate <CasePlanInstanceAggregate>(notification.CasePlanInstanceId, CasePlanInstanceAggregate.GetStreamName(notification.CasePlanInstanceId)); try { if (casePlanInstance == null || string.IsNullOrWhiteSpace(casePlanInstance.AggregateId)) { throw new InvalidOperationException($"case plan instance '{notification.CasePlanInstanceId}' doesn't exist"); } await _casePlanInstanceProcessor.Execute(casePlanInstance, cancellationToken); await _commitAggregateHelper.Commit(casePlanInstance, casePlanInstance.GetStreamName(), cancellationToken); } finally { await _distributedLock.ReleaseLock(lockName, cancellationToken); } }
protected override async Task ProcessMessage(StateTransitionNotification message, CancellationToken cancellationToken) { string lockName = $"statetransitions:{message.Id}"; if (!await _distributedLock.TryAcquireLock(lockName, cancellationToken)) { return; } var processInstance = await _eventStoreRepository.GetLastAggregate <ProcessInstanceAggregate>(message.ProcessInstanceId, ProcessInstanceAggregate.GetStreamName(message.ProcessInstanceId)); try { if (processInstance == null || string.IsNullOrWhiteSpace(processInstance.AggregateId)) { throw new InvalidOperationException($"process instance '{message.ProcessInstanceId}' doesn't exist"); } processInstance.ConsumeStateTransition(message); await _commitAggregateHelper.Commit(processInstance, processInstance.GetStreamName(), cancellationToken); await MessageBroker.QueueProcessInstance(processInstance.AggregateId, false, cancellationToken); _logger.LogInformation($"Make transition '{message.State}' on the user task instance '{message.FlowNodeInstanceId}'"); } finally { await _distributedLock.ReleaseLock(lockName, cancellationToken); } }