public void TimeoutInThePast() { var expected = DateTime.UtcNow.AddDays(-3); var message = new TheMessage { TimeoutAt = expected }; Test.Saga <TimeoutSaga>() .ExpectTimeoutToBeSetAt <TheTimeout>((m, at) => at == expected) .When((s, c) => s.Handle(message, c)); }
public void TimeoutInTheFuture() { var expected = DateTime.UtcNow.AddDays(3); var message = new TheMessage { TimeoutAt = expected }; Test .Saga <TheSaga>() .ExpectTimeoutToBeSetAt <TheTimeout>((m, at) => at == expected) .When(s => s.Handle(message)); }
public void TimeoutInThePastWithSendOnTimeout() { var message = new TheMessage { TimeoutAt = DateTime.UtcNow.AddDays(-3) }; Test .Saga <TheSaga>() .ExpectTimeoutToBeSetAt <TheTimeout>((m, at) => true) .When(s => s.Handle(message)) .ExpectSend <TheMessageSentAtTimeout>() .WhenSagaTimesOut(); }
public static void Main(string[] args) { // real-world variables, keep them typed as base Message // to be able to silently replace them with different objects Message original1; Message original2; // let's construct some one-time readable messages { original1 = new TheMessage("dad", "dog"); original2 = new TheMessage("dad", "dog"); } // test1 - can't read twice Console.WriteLine("test0A:" + original1.GetReaderAtBodyContents().ReadOuterXml()); // Console.WriteLine("test0B:" + original1.GetReaderAtBodyContents().ReadOuterXml()); // fail: InvalidOperationException - it was already read // test2 - can read ONCE with Reader's help, but the message is replaced and is usable again var backup1 = original2; using (var rd1 = new ReaderOnce(ref original2)) { Console.WriteLine("is message replaced after opening Reader:" + (original2 != backup1)); Console.WriteLine("test1A:" + rd1.ReadBodyXml()); // Console.WriteLine("test1B:" + rd1.ReadBodyXml()); // fail: InvalidOperationException - it was already read } // test3 - can read MANY TIMES with ReaderMany's help // also note we use 'original2' again, which was already used above, so in fact ReaderOnce really works as well var backup2 = original2; using (var rd1 = new ReaderMany(ref original2)) { Console.WriteLine("is message replaced after opening Reader:" + (original2 != backup2)); Console.WriteLine("test2A:" + rd1.ReadBodyXml()); Console.WriteLine("test2B:" + rd1.ReadBodyXml()); // ok } Console.WriteLine("Press enter to exit"); Console.ReadLine(); }
public void Handle(TheMessage message) { RequestUtcTimeout <TheTimeout>(message.TimeoutAt); }
static async Task AsyncMain() { Console.Title = "Endpoint1"; var endpointConfiguration = new EndpointConfiguration("Endpoint1"); #region UseTransport endpointConfiguration.UseTransport <LearningTransport>(); #endregion var endpointInstance = await Endpoint.Start(endpointConfiguration) .ConfigureAwait(false); Console.WriteLine("Press S to send a message"); Console.WriteLine("Press D to send a delayed message"); Console.WriteLine("Press E to send a message that will throw an exception"); Console.WriteLine("Press any key to exit"); #region StartMessageInteraction while (true) { var key = Console.ReadKey(); Console.WriteLine(); if (key.Key == ConsoleKey.D) { var message = new TheMessage(); var sendOptions = new SendOptions(); sendOptions.DelayDeliveryWith(TimeSpan.FromSeconds(10)); sendOptions.SetDestination("Endpoint2"); await endpointInstance.Send(message, sendOptions) .ConfigureAwait(false); Console.WriteLine("Sent a delayed message"); continue; } if (key.Key == ConsoleKey.S) { var message = new TheMessage(); var sendOptions = new SendOptions(); sendOptions.SetDestination("Endpoint2"); await endpointInstance.Send(message, sendOptions) .ConfigureAwait(false); Console.WriteLine("Sent a message"); continue; } if (key.Key == ConsoleKey.E) { var message = new TheMessage { ThrowException = true }; var sendOptions = new SendOptions(); sendOptions.SetDestination("Endpoint2"); await endpointInstance.Send(message, sendOptions) .ConfigureAwait(false); Console.WriteLine("Sent a message that will throw"); continue; } break; } #endregion Console.WriteLine("Message sent. Press any key to exit"); Console.ReadKey(); await endpointInstance.Stop() .ConfigureAwait(false); }
public Task Handle(TheMessage message, IMessageHandlerContext context) { return(RequestTimeout <TheTimeout>(context, message.TimeoutAt)); }
public void SendMessage(TheMessage message) { Clients.All.SendAsync("ReceiveMessage", JsonSerializer.Serialize(message)); }
static async Task Main() { //required to prevent possible occurrence of .NET Core issue https://github.com/dotnet/coreclr/issues/12668 Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US"); Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US"); Console.Title = "Endpoint1"; var endpointConfiguration = new EndpointConfiguration("Endpoint1"); #region UseTransport endpointConfiguration.UseTransport <LearningTransport>(); #endregion var endpointInstance = await Endpoint.Start(endpointConfiguration) .ConfigureAwait(false); Console.WriteLine("Press S to send a message"); Console.WriteLine("Press D to send a delayed message"); Console.WriteLine("Press E to send a message that will throw an exception"); Console.WriteLine("Press any key to exit"); #region StartMessageInteraction while (true) { var key = Console.ReadKey(); Console.WriteLine(); if (key.Key == ConsoleKey.D) { var message = new TheMessage(); var sendOptions = new SendOptions(); sendOptions.DelayDeliveryWith(TimeSpan.FromSeconds(10)); sendOptions.SetDestination("Endpoint2"); await endpointInstance.Send(message, sendOptions) .ConfigureAwait(false); Console.WriteLine("Sent a delayed message"); continue; } if (key.Key == ConsoleKey.S) { var message = new TheMessage(); var sendOptions = new SendOptions(); sendOptions.SetDestination("Endpoint2"); await endpointInstance.Send(message, sendOptions) .ConfigureAwait(false); Console.WriteLine("Sent a message"); continue; } if (key.Key == ConsoleKey.E) { var message = new TheMessage { ThrowException = true }; var sendOptions = new SendOptions(); sendOptions.SetDestination("Endpoint2"); await endpointInstance.Send(message, sendOptions) .ConfigureAwait(false); Console.WriteLine("Sent a message that will throw"); continue; } break; } #endregion Console.WriteLine("Message sent. Press any key to exit"); Console.ReadKey(); await endpointInstance.Stop() .ConfigureAwait(false); }