Refactor and improve fallback support for @SentinelResource annotation #693
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Describe what this PR does / why we need it
Refactor and improve fallback support for
@SentinelResource
annotation to improve usability.Does this pull request fix one issue?
Resolves #647
Describe how you did it
blockHandler
andfallback
fallbackClass
support for fallback in global classesdefaultFallback
supportBreaking changes: the behavior of
fallback
has changed. In previous versions, the fallback will take effect only whenblockHandler
is not configured andDegradeException
caught, which might be confusing and inconvenient for users. So I improved the semantics offallback
: now it can handle all kinds of exceptions (except configuredexceptionsToIgnore
). And adefaultFallback
is also added to support universal fallback shared for multiple methods.The method signature requirement of
fallback
has changed. Now it can be:Throwable
parameter can be provided to get the actual exception.For
defaultFallback
, the requirement:Throwable
parameter can be provided to get the actual exception.For
BlockException
, whenblockHandler
is provided, Sentinel will use theblockHandler
, or Sentinel will try to use fallback to handle theBlockException
.Describe how to verify it
Run the test cases and demo.
Special notes for reviews
This PR contains breaking changes. Please take care of the changes.