static Task SendSagaMessage(IMessageSession endpointInstance) { Console.WriteLine(); Console.WriteLine("StartSagaMessage sent"); var message = new StartSagaMessage { SentTime = DateTimeOffset.UtcNow, TheId = Guid.NewGuid() }; return endpointInstance.SendLocal(message); }
static Task SendSagaMessage(IMessageSession endpointInstance) { Console.WriteLine(); Console.WriteLine("StartSagaMessage sent"); var message = new StartSagaMessage { SentTime = DateTimeOffset.UtcNow, TheId = Guid.NewGuid() }; return(endpointInstance.SendLocal(message)); }
public Task Handle(StartSagaMessage message, IMessageHandlerContext context) { log.Info("Received StartSagaMessage"); Data.TheId = message.TheId; Data.MessageSentTime = message.SentTime; var completeSagaMessage = new CompleteSagaMessage { TheId = Data.TheId }; return(context.SendLocal(completeSagaMessage)); }
public void Handle(StartSagaMessage message) { if (Context.SagaId != Guid.Empty) { Context.SameSagaInstanceFound = Context.SagaId == Data.Id; Context.SecondMessageProcessed = true; return; } Context.SagaId = Data.Id; }
void StartSaga(string tennant = "") { var message = new StartSagaMessage { OrderId = Guid.NewGuid() }; if (!string.IsNullOrEmpty(tennant)) message.SetHeader("tennant", tennant); Bus.SendLocal(message); Console.WriteLine(string.Format("{0} - {1}", DateTime.Now.ToLongTimeString(), "Saga start message sent")); }
static void SendSagaMessage(IBus bus) { var message = new StartSagaMessage { SentTime = DateTimeOffset.UtcNow, TheId = Guid.NewGuid() }; bus.SendLocal(message); Console.WriteLine(); Console.WriteLine("StartSagaMessage sent"); }
public Task Handle(StartSagaMessage message, IMessageHandlerContext context) { if (Context.SagaId != Guid.Empty) { Context.SameSagaInstanceFound = Context.SagaId == Data.Id; Context.SecondMessageProcessed = true; return(Task.FromResult(0)); } Context.SagaId = Data.Id; return(Task.FromResult(0)); }
public void Handle(StartSagaMessage message) { Data.SomeId = message.SomeId; if (message.SecondMessage) { Context.SecondSagaInstance = Data.Id; Context.SecondMessageReceived = true; } else { Context.FirstSagaInstance = Data.Id; } }
public static async Task Start(string endpointName, Action <PersistenceExtensions <SqlPersistence> > configurePersistence) { var endpointConfiguration = new EndpointConfiguration($"SqlPersistence.Sample{endpointName}"); endpointConfiguration.EnableInstallers(); endpointConfiguration.UseTransport <MsmqTransport>(); endpointConfiguration.EnableOutbox(); endpointConfiguration.SendFailedMessagesTo("Error"); var persistence = endpointConfiguration.UsePersistence <SqlPersistence>(); configurePersistence(persistence); var subscriptions = persistence.SubscriptionSettings(); subscriptions.CacheFor(TimeSpan.FromMinutes(1)); var endpoint = await Endpoint.Start(endpointConfiguration) .ConfigureAwait(false); Console.WriteLine("Press any key to exit"); var myEvent = new MyEvent { Property = "PropertyValue" }; await endpoint.Publish(myEvent) .ConfigureAwait(false); var startSagaMessage = new StartSagaMessage { MySagaId = Guid.NewGuid() }; await endpoint.SendLocal(startSagaMessage) .ConfigureAwait(false); var deferMessage = new DeferMessage { Property = "PropertyValue" }; var options = new SendOptions(); options.RouteToThisEndpoint(); options.DelayDeliveryWith(TimeSpan.FromSeconds(1)); await endpoint.Send(deferMessage, options) .ConfigureAwait(false); Console.ReadKey(); await endpoint.Stop() .ConfigureAwait(false); }
public Task <TestSaga.SagaData> FindBy(StartSagaMessage message, SynchronizedStorageSession session, ReadOnlyContextBag context) { Context.StartSagaFinderUsed = true; return(session.GetSagaData <TestSaga.SagaData>( context: context, whereClause: "json_value(Data,'$.Property') = @propertyValue", appendParameters: (builder, append) => { var parameter = builder(); parameter.ParameterName = "propertyValue"; parameter.Value = "Test"; append(parameter); })); }
void StartSaga(string tennant = "") { var message = new StartSagaMessage { OrderId = Guid.NewGuid() }; if (!string.IsNullOrEmpty(tennant)) { message.SetHeader("tennant", tennant); } Bus.Send(message); Console.WriteLine("{0} - {1}", DateTime.Now.ToLongTimeString(), "Saga start message sent"); }
public Task Handle(StartSagaMessage message, IMessageHandlerContext context) { if (message.SecondMessage) { Data.SomeId = Guid.NewGuid(); //this is not allowed TestContext.ModifiedCorrelationProperty = true; return(Task.FromResult(0)); } return(context.SendLocal(new StartSagaMessage { SecondMessage = true, SomeId = Data.SomeId })); }
public Task <TestSaga.SagaData> FindBy(StartSagaMessage message, SynchronizedStorageSession session, ReadOnlyContextBag context, CancellationToken cancellationToken = default) { testContext.FinderUsed = true; return(session.GetSagaData <TestSaga.SagaData>( context: context, whereClause: @"""Data""->>'Property' ='Test'", appendParameters: (builder, append) => { var parameter = builder(); parameter.ParameterName = "propertyValue"; parameter.Value = "Test"; append(parameter); }, cancellationToken)); }
public Task Handle(StartSagaMessage message, IMessageHandlerContext context) { //oops I forgot Data.SomeId = message.SomeId if (message.SecondMessage) { Context.SomeId = Data.SomeId; Context.Done = true; return(Task.FromResult(0)); } return(context.SendLocal(new StartSagaMessage { SomeId = message.SomeId, SecondMessage = true })); }
public async Task Should_apply_base_class_mapping_to_sub_classes() { var correlationId = Guid.NewGuid(); var context = await Scenario.Define <Context>() .WithEndpoint <SagaEndpoint>(b => b.When(session => { var startSagaMessage = new StartSagaMessage { SomeId = correlationId }; return(session.SendLocal(startSagaMessage)); })) .Done(c => c.SecondMessageFoundExistingSaga) .Run(TimeSpan.FromSeconds(20)); Assert.True(context.SecondMessageFoundExistingSaga); }
public Task Handle(StartSagaMessageBase message, IMessageHandlerContext context) { if (Data.SomeId != Guid.Empty) { TestContext.SecondMessageFoundExistingSaga = true; } else { var startSagaMessage = new StartSagaMessage { SomeId = message.SomeId }; return(context.SendLocal(startSagaMessage)); } return(Task.FromResult(0)); }
public async Task Should_use_existing_saga() { var context = await Scenario.Define <Context>() .WithEndpoint <SagaEndpoint>(b => b .When(session => { var startSagaMessage = new StartSagaMessage { Property = "Test" }; return(session.SendLocal(startSagaMessage)); })) .Done(c => c.HandledOtherMessage) .Run() .ConfigureAwait(false); Assert.True(context.FinderUsed); }
public void Should_throw_validation_exception() { var exception = Assert.ThrowsAsync <Exception>(async() => await Scenario.Define <Context>() .WithEndpoint <SagaEndpoint>(b => b .When(session => { var startSagaMessage = new StartSagaMessage { Property = "Test" }; return(session.SendLocal(startSagaMessage)); })) .Done(c => c.StartSagaFinderUsed) .Run()); Assert.AreEqual("The saga 'When_correlation_property_is_not_mapped+SagaEndpoint+TestSaga' defines a correlation property 'Property' which is not mapped to any message. Either map it or remove it from the saga definition.", exception.Message); }
public Task Handle(StartSagaMessage message, IMessageHandlerContext context) { if (message.SecondMessage) { TestContext.SecondSagaId = Data.Id; TestContext.SecondMessageReceived = true; } else { TestContext.FirstSagaId = Data.Id; return(context.SendLocal(new StartSagaMessage { SomeId = message.SomeId, SecondMessage = true })); } return(Task.FromResult(0)); }
public async Task Doesnt_Load_Endpoints_With_Timeouts_outside_the_cutoff_date() { await Scenario.Define <Context>(c => c.NumberOfTimeouts = 10) .WithEndpoint <SqlPEndpoint>(b => b.CustomConfig(ec => SetupPersistence(ec)) .When(session => { var startSagaMessage = new StartSagaMessage { Id = Guid.NewGuid() }; return(session.SendLocal(startSagaMessage)); })) .Done(c => c.NumberOfTimeouts == NumberOfTimeouts(sourceEndpoint)) .Run(); var endpoints = await GetTimeoutStorage().ListEndpoints(DateTime.Now.AddYears(10)); CollectionAssert.IsEmpty(endpoints); }
public async Task Loads_Destinations_For_Endpoints_With_Valid_Timeouts() { await Scenario.Define <Context>(c => c.NumberOfTimeouts = 1) .WithEndpoint <SqlPEndpoint>(b => b.CustomConfig(ec => SetupPersistence(ec)) .When(async session => { var delayedMessage = new StartSagaMessage(); var options = new SendOptions(); options.DelayDeliveryWith(TimeSpan.FromSeconds(15)); options.SetDestination("FirstDestination"); await session.Send(delayedMessage, options); delayedMessage = new StartSagaMessage(); options = new SendOptions(); options.DelayDeliveryWith(TimeSpan.FromSeconds(15)); options.SetDestination("SecondDestination"); await session.Send(delayedMessage, options); delayedMessage = new StartSagaMessage(); options = new SendOptions(); options.DelayDeliveryWith(TimeSpan.FromSeconds(15)); options.SetDestination("ThirdDestination"); await session.Send(delayedMessage, options); })) .Done(c => NumberOfTimeouts(sourceEndpoint) == 3) .Run(); var endpoints = await GetTimeoutStorage().ListEndpoints(DateTime.Now.AddYears(-10)); CollectionAssert.AreEquivalent(new List <string> { "FirstDestination", "SecondDestination", "ThirdDestination" }, endpoints.First().Destinations); }
public async Task Can_prepare_storage_for_migration() { await Scenario.Define <Context>(c => c.NumberOfTimeouts = 10) .WithEndpoint <SqlPEndpoint>(b => b.CustomConfig(ec => SetupPersistence(ec)) .When(session => { var startSagaMessage = new StartSagaMessage { Id = Guid.NewGuid() }; return(session.SendLocal(startSagaMessage)); })) .Done(c => c.NumberOfTimeouts == NumberOfTimeouts(sourceEndpoint)) .Run(); var timeoutStorage = GetTimeoutStorage(3); var toolState = await timeoutStorage.Prepare(DateTime.Now, sourceEndpoint, new Dictionary <string, string>()); Assert.AreEqual(4, toolState.NumberOfBatches); }
public async Task Only_Moves_timeouts_After_migrateTimeoutsWithDeliveryDateLaterThan_date() { await Scenario.Define <Context>(c => c.NumberOfTimeouts = 10) .WithEndpoint <SqlPEndpoint>(b => b.CustomConfig(ec => SetupPersistence(ec)) .When(session => { var startSagaMessage = new StartSagaMessage { Id = Guid.NewGuid() }; return(session.SendLocal(startSagaMessage)); })) .Done(c => c.NumberOfTimeouts == NumberOfTimeouts(sourceEndpoint)) .Run(); var timeoutStorage = GetTimeoutStorage(1); var toolState = await timeoutStorage.Prepare(DateTime.Now.AddDays(10), sourceEndpoint, new Dictionary <string, string>()); Assert.AreEqual(6, toolState.NumberOfBatches); }
public async Task Loads_Endpoints_With_Valid_Timeouts() { await Scenario.Define <Context>(c => c.NumberOfTimeouts = 10) .WithEndpoint <SqlPEndpoint>(b => b.CustomConfig(ec => SetupPersistence(ec)) .When(session => { var startSagaMessage = new StartSagaMessage { Id = Guid.NewGuid() }; return(session.SendLocal(startSagaMessage)); })) .Done(c => c.NumberOfTimeouts == NumberOfTimeouts(sourceEndpoint)) .Run(); var timeoutStorage = GetTimeoutStorage(); var endpoints = await timeoutStorage.ListEndpoints(DateTime.Now.AddYears(-10)); CollectionAssert.Contains(endpoints.Select(e => e.EndpointName), sourceEndpoint); Assert.AreEqual(1, endpoints.Single(e => e.EndpointName == sourceEndpoint).Destinations.Count()); }
private void StartSagaAndCompleteBeforeTimeout(bool fail) { var startSagaMessage = new StartSagaMessage { OrderId = Guid.NewGuid() }; this.Bus.SendLocal(startSagaMessage); Console.WriteLine("Starting saga with for order id {0}.", startSagaMessage.OrderId); Console.WriteLine("=========================================================================="); Thread.Sleep(1000); var completeSagaMessage = new CompleteSagaMessage { OrderId = startSagaMessage.OrderId, ThrowDuringCompletion = fail }; this.Bus.SendLocal(completeSagaMessage); }
public async Task Should_use_existing_saga() { if (!MsSqlMicrosoftDataClientConnectionBuilder.IsSql2016OrHigher()) { return; } var context = await Scenario.Define <Context>() .WithEndpoint <SagaEndpoint>(b => b .When(session => { var startSagaMessage = new StartSagaMessage { Property = "Test" }; return(session.SendLocal(startSagaMessage)); })) .Done(c => c.HandledOtherMessage) .Run() .ConfigureAwait(false); Assert.True(context.FinderUsed); }
public async Task Removes_Timeouts_From_Original_TimeoutData_Table() { await Scenario.Define <Context>(c => c.NumberOfTimeouts = 10) .WithEndpoint <SqlPEndpoint>(b => b.CustomConfig(ec => SetupPersistence(ec)) .When(session => { var startSagaMessage = new StartSagaMessage { Id = Guid.NewGuid() }; return(session.SendLocal(startSagaMessage)); })) .Done(c => c.NumberOfTimeouts == NumberOfTimeouts(sourceEndpoint)) .Run(); var timeoutStorage = GetTimeoutStorage(); await timeoutStorage.Prepare(DateTime.Now, sourceEndpoint, new Dictionary <string, string>()); var numberOfTimeouts = await QueryScalarAsync <int>($"SELECT COUNT(*) FROM [{sourceEndpoint}_TimeoutData]"); Assert.AreEqual(0, numberOfTimeouts); }
public async Task Should_correlate_the_following_message_correctly() { if (!MsSqlConnectionBuilder.IsSql2016OrHigher()) { return; } var context = await Scenario.Define <Context>() .WithEndpoint <SagaEndpoint>(b => b .When(session => { var startSagaMessage = new StartSagaMessage { Property = "Test" }; return(session.SendLocal(startSagaMessage)); })) .Done(c => c.HandledOtherMessage) .Run() .ConfigureAwait(false); Assert.True(context.StartSagaFinderUsed); }
public async Task WhenCompletingMigrationStatusIsSetToCompleted() { await Scenario.Define <Context>(c => c.NumberOfTimeouts = 5) .WithEndpoint <SqlPEndpoint>(b => b.CustomConfig(ec => SetupPersistence(ec)) .When(session => { var startSagaMessage = new StartSagaMessage { Id = Guid.NewGuid() }; return(session.SendLocal(startSagaMessage)); })) .Done(c => c.NumberOfTimeouts == NumberOfTimeouts(sourceEndpoint)) .Run(); var timeoutStorage = GetTimeoutStorage(); await timeoutStorage.Prepare(DateTime.Now, sourceEndpoint, new Dictionary <string, string>()); Assert.NotNull(await timeoutStorage.TryLoadOngoingMigration()); await timeoutStorage.Complete(); Assert.Null(await timeoutStorage.TryLoadOngoingMigration()); }
public Task <SagaData> FindBy(StartSagaMessage message, SynchronizedStorageSession storageSession, ReadOnlyContextBag context) { return(Task.FromResult(default(SagaData))); }
public Task Handle(StartSagaMessage message, IMessageHandlerContext context) { return(TaskEx.CompletedTask); }
public Task <TestSaga06.SagaData06> FindBy(StartSagaMessage message, SynchronizedStorageSession storageSession, ReadOnlyContextBag context) { Context.FinderUsed = true; return(Task.FromResult(default(TestSaga06.SagaData06))); }