question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

proposal: combination of modules

See original GitHub issue

I’ve just started using resilience4j today so I may be wrong on that… but what to me seems missing and that I have had to implement myself right now is a combinatory class with multiple “resilient” interfaces to get the desired behaviour… I mean , here we have a lot of classes but for a real scenario request, one usually need more than one of these combined… ie : a external call to a api would usually require: circuitBreaker { timeLimiter { retry { CALL } } } in this case the timeLimiter is outside the retry because should not be retried ( and also create a sort of higher cap on retry calls time + CALL time ) this is just one scenario but maybe composability may be usefull in other scenarios too … everything probably should be designed and abstracted with a single handler which also may influcence the metrics/tagging features…

for my very specific usecase I’ve just wrapped callbacks in a class ( which also could be injected as single dependency )

class ResilienceComboImpl(val retry : Retry?,
                          val circuitBreaker: CircuitBreaker?,
                          val timeLimiter  : TimeLimiter?) : ResilienceCombo {

    override suspend fun <R>wrapCBR( block : suspend () -> R ) : R?{
        circuitBreaker ?: throw Exception("Circuit breaker not provided")
        retry ?: throw Exception("Retry not provided")
        return circuitBreaker.executeSuspendFunction{
                retry.executeSuspendFunction {
                    block()
                }
        }
    }
    override suspend fun <R>wrapCBRT( block : suspend () -> R ) : R?{
        circuitBreaker ?: throw Exception("Circuit breaker not provided")
        timeLimiter ?: throw Exception("Timelimiter not provided")
        retry ?: throw Exception("Retry not provided")
        return circuitBreaker.executeSuspendFunction{
            timeLimiter.executeSuspendFunction {
                retry.executeSuspendFunction {
                    block()
                }
            }
        }
    }
}


but this is far away from being something shareable in public code, I’ve just pasted here to give you some code in order to capture your attention 😃

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
hexmindcommented, Jul 8, 2019

Resilience4j promotes a decorator pattern for one or (especially) more resilience components. They are like layers. However because Java functional interfaces are first-class citizens for this library you can also compose your decorators using methods compose/andThen from Function class. Maybe Decorators class (example usage below) can meet your expectations? Fluent interface looks more readable and developer friendly than exceptions throwing. You can also hide this code into your custom class and provide specific constructor for required components.

Supplier<String> decoratedSupplier = Decorators.ofSupplier(supplier)
  .withRetry(retry)
  .withCircuitBreaker(circuitBreaker)
  .withBulkhead(bulkhead)
  .decorate();
1reaction
fvigotticommented, Jul 8, 2019

Yes this is somwehat what I had in mind, I have now seen that this example exists in the guide, but I thought that this Decorators interface was still missing because the package resilience4j-all isn’t specified in docs nor in guide, I’ve seen that in maven but when importing… who want it all ? maybe resilience4j-common or resilience4j-decorators if only contains that is a better name? anyway this seems to solve the problem, even if I’ve yet to adapt for kotlin coroutines , also the ordering of the decoration is important but not documented well I’ll have to reason that around the source code …

I’m going to close this , but I’ll add more comments if I find something usefull 😃 thank you, Francesco

Read more comments on GitHub >

github_iconTop Results From Across the Web

Completing the Module Proposal Form (PG)
The purpose of the Module Proposal Form is to articulate the aims, learning outcomes, and learning, teaching and assessment methods of the module;...
Read more >
COEUS GUIDE Proposal Development Module Overview
The Proposal Development module in Coeus has been designed to allow departmental administrators and investigators to develop full proposals from the desktop, ...
Read more >
T6 New Module Proposal Template - Durham University
This template is designed to help TEIs propose new modules which have not yet been approved. Please use this form to propose a...
Read more >
Proposal: merge book and taxonomy modules | Drupal.org
This module will define two new node types called 'category' (what is now called a 'term') and 'vocabulary'. As with the existing taxonomy ......
Read more >
Streamlyne Research - Modules
The Proposal Development module provides for the collaborative development of a proposal, including the collection of data and attachments required by your ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found