Last active
June 14, 2020 18:53
-
-
Save viktors-telle/f2d33d90e65215086122996a93f8f58f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Threading.Tasks; | |
using GreenPipes; | |
using MassTransit; | |
namespace Retries | |
{ | |
internal static class Program | |
{ | |
static async Task Main(string[] args) | |
{ | |
var busControl = CreateBusControl(); | |
await StartBusControl(busControl); | |
} | |
private static IBusControl CreateBusControl() | |
{ | |
return Bus.Factory.CreateUsingRabbitMq(cfg => | |
{ | |
cfg.Host("localhost"); | |
// Enable redelivery. | |
cfg.UseDelayedExchangeMessageScheduler(); | |
cfg.ReceiveEndpoint("message-queue", e => | |
{ | |
// Configure redelivery retries. | |
e.UseScheduledRedelivery(retryConfigurator => | |
{ | |
retryConfigurator.Intervals( | |
TimeSpan.FromMinutes(1), | |
TimeSpan.FromMinutes(2), | |
TimeSpan.FromMinutes(3) | |
); | |
} | |
); | |
e.UseMessageRetry(retryConfigurator => | |
{ | |
retryConfigurator.Incremental( | |
3, | |
TimeSpan.FromSeconds(1), | |
TimeSpan.FromSeconds(15) | |
); | |
} | |
); | |
e.Consumer<Consumer>(); | |
}); | |
}); | |
} | |
private static async Task StartBusControl(IBusControl busControl) | |
{ | |
await busControl.StartAsync(); | |
await busControl.Publish<IMessage>( | |
new Message(Guid.NewGuid().ToString(), "Valid name") | |
); | |
Console.WriteLine("Press any key to exit"); | |
await Task.Run(() => Console.ReadKey()); | |
await busControl.StopAsync(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment