public void CollectCommandsToBePublished() { var sagaCommand1 = new SagaCommand(GuidStrategy.NewGuid(), new HeaderCollection((IEnumerable <Header>)HeaderCollection.Empty), new FakeCommand()); var sagaCommand2 = new SagaCommand(GuidStrategy.NewGuid(), new HeaderCollection((IEnumerable <Header>)HeaderCollection.Empty), new FakeCommand()); using (var context = new SagaContext(typeof(Saga), GuidStrategy.NewGuid(), new FakeEvent())) { context.Publish(sagaCommand1.AggregateId, sagaCommand1.Headers, sagaCommand1.Command); context.Publish(sagaCommand2.AggregateId, sagaCommand2.Headers, sagaCommand2.Command); var publishedCommands = context.GetPublishedCommands().ToArray(); Assert.Equal(sagaCommand1.AggregateId, publishedCommands[0].AggregateId); Assert.Equal(sagaCommand2.AggregateId, publishedCommands[1].AggregateId); } }
public void CollectCommandsToBePublished() { var sagaCommand1 = new SagaCommand(GuidStrategy.NewGuid(), new HeaderCollection((IEnumerable<Header>) HeaderCollection.Empty), new FakeCommand()); var sagaCommand2 = new SagaCommand(GuidStrategy.NewGuid(), new HeaderCollection((IEnumerable<Header>)HeaderCollection.Empty), new FakeCommand()); using (var context = new SagaContext(typeof(Saga), GuidStrategy.NewGuid(), new FakeEvent())) { context.Publish(sagaCommand1.AggregateId, sagaCommand1.Headers, sagaCommand1.Command); context.Publish(sagaCommand2.AggregateId, sagaCommand2.Headers, sagaCommand2.Command); var publishedCommands = context.GetPublishedCommands().ToArray(); Assert.Equal(sagaCommand1.AggregateId, publishedCommands[0].AggregateId); Assert.Equal(sagaCommand2.AggregateId, publishedCommands[1].AggregateId); } }
public async Task ProcessChangesAsync(IChangeFeedObserverContext context, IReadOnlyList <Document> docs, CancellationToken cancellationToken) { foreach (var doc in docs) { log.Info($"Processing changes for document {doc.Id}"); var item = (dynamic)doc; if (item.Outbox.Count > 0) { SagaCommand message = SagaCommand.New <T>(item); await Program.Endpoint.SendLocal(message); } } }
public async Task Dispatch(SagaCommand command) { var documentType = Type.GetType(command.DocumentType); var repository = GetRepository(documentType); var document = await repository.FindById(command.DocumentId); if (document == null) { return; } foreach (var message in document.Outbox.ToArray()) { var handler = GetHandler(message); await handler.Handle(message, _serviceFactory); document.ProcessDocumentMessage(message); await repository.Update(document); } }