Luffy


alt tag

Luffy is a simple resilience and transient-fault handling library for .NET

NuGet version

NuGet Packages

PM> Install-Package Luffy

Features:

  • Luffy provides circuit breaker feature
  • Luffy provides retry mechanism with back-off (linear and exponentially)
  • Luffy provides fallback feature

Usages:


Sample usage for the circuit breaker:

async Task<double> CircuitBreakerSample(double amount, string from, string to)
{
    double currentRate = await Luffy.Instance
                        .UseCircuitBreaker(new CircuitBreakerOptions(key: "CurrencyConverterSampleAPI",
                                                                     exceptionThreshold: 5,
                                                                     successThresholdWhenCircuitBreakerHalfOpenStatus: 5,
                                                                     durationOfBreak: TimeSpan.FromSeconds(5)))
                        .ExecuteAsync<double>(async () => {
                            // Some API calls...
                            double rate = await CurrencyConverterSampleAPI(amount, from, to);

                            return rate;
                        });

    return currentRate;
}

Sample usage for the retry mechanism:

async Task<double> RetryMechanismSample(double amount, string from, string to)
{
    double currentRate = await Luffy.Instance
                        .UseRetry(new RetryMechanismOptions(RetryPolicies.Linear,
                                                            retryCount: 3,
                                                            interval: TimeSpan.FromSeconds(5)))
                        .ExecuteAsync<double>(async () => {
                            // Some API calls...
                            double rate = await CurrencyConverterSampleAPI(amount, from, to);

                            return rate;
                        });

    return currentRate;
}

Sample usage for the retry mechanism and fallback scenario:

async Task<double> RetryMechanismWithFallbackSample(double amount, string from, string to)
{
    double currentRate = await Luffy.Instance
                        .UseRetry(new RetryMechanismOptions(RetryPolicies.Linear,
                                                            retryCount: 3,
                                                            interval: TimeSpan.FromSeconds(5)))
                        .ExecuteAsync<double>(async () => {
                            // Some API calls...
                            double rate = await CurrencyConverterSampleAPI(amount, from, to);

                            return rate;
                        }, async () => {
                            // Some fallback scenario.
                            double rate = 100;

                            return await Task.FromResult(rate);                                    
                        });

    return currentRate;
}

Samples:

Luffy

Luffy is a simple resilience and transient-fault handling library

Luffy Info

⭐ Stars 19
🔗 Homepage www.gokhan-gokalp.com
🔗 Source Code github.com
🕒 Last Update 6 months ago
🕒 Created 4 years ago
🐞 Open Issues 0
➗ Star-Issue Ratio Infinity
😎 Author GokGokalp