public Task Handle(DeferMe message, IMessageHandlerContext context) { Data.MessageIds.Add(context.MessageId); var d = Data.IterationCounts; var i = message.Iteration; if (i == d.Count) { d.Add(1); } else if (i < d.Count) { ++d[i]; Log.FatalFormat("Ref: {0}, Iteration: {1} processed {2} times.", message.Ref, message.Iteration, d[i]); } else { throw new InvalidOperationException(); } Console.Out.WriteAsync("."); // Schedule next iteration var at = DateTime.UtcNow.RoundUp(roundingOffset); message.Iteration++; var options = new SendOptions(); options.DoNotDeliverBefore(at); options.RouteToThisEndpoint(); return(context.Send(message, options)); }
public void SendDeferMe() { var numberOfMessages = 100; var endpointConfiguration = new EndpointConfiguration(endpointName: "SagaTimeoutRepro.MessageDispatcher"); endpointConfiguration.UsePersistence <InMemoryPersistence>(); endpointConfiguration.EnableInstallers(); endpointConfiguration.UseSerialization <JsonSerializer>(); endpointConfiguration.SendOnly(); endpointConfiguration.SendFailedMessagesTo("error"); // Initialize the endpoint with the finished configuration var messageSession = Endpoint.Start(endpointConfiguration) .ConfigureAwait(false).GetAwaiter().GetResult(); var tasks = new List <Task>(numberOfMessages); for (int i = 1; i <= numberOfMessages; i++) { var msg = new DeferMe { Ref = i }; tasks.Add(messageSession.Send("SagaTimeoutRepro", msg)); } ; Task.WhenAll(tasks).GetAwaiter().GetResult(); messageSession.Stop(); }