Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/koooooo-7/kguarder
:guardsman: A method based guarder for error-handling.
https://github.com/koooooo-7/kguarder
error-handling recovery retry retry-library springboot
Last synced: 10 days ago
JSON representation
:guardsman: A method based guarder for error-handling.
- Host: GitHub
- URL: https://github.com/koooooo-7/kguarder
- Owner: Koooooo-7
- License: mit
- Created: 2023-08-08T09:29:38.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-09-02T04:59:55.000Z (2 months ago)
- Last Synced: 2024-10-14T14:22:53.251Z (23 days ago)
- Topics: error-handling, recovery, retry, retry-library, springboot
- Language: Java
- Homepage:
- Size: 145 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# kguarder
> :guardsman: *A method based guarder for error-handling.*
Lite and simple make things easier and handy, lives in SpringBoot.
Working in normal method calls, api calls and transaction operations.This project provides a declarative error-handling way based on method for SpringBoot applications.
- Method call return time limitation control
- Retry support
- Recovery support
- Custom method failure check## Quick Start
```java
JDK 11+
SpringBoot v2.7+
```### Import Dependency
> Current ${latest-version} : `0.0.1`.
```pom
top.ko8e24
kguarder
0.0.1
``````gradle
implementation 'top.ko8e24.kguarder:kguarder:0.0.1'
```### Enable `kguarder`.
```java
// Active KGuarder
@EnableGuarder
@SpringBootApplication
public class KGuarderDemoApplication {public static void main(String[] args) {
SpringApplication.run(KGuarderDemoApplication.class, args);
}}
```### Usage
```java
@Guarder(
// method cost limitation, if over time, interrupt and do retry
timeout = 1L,
timeoutUnit = TimeUnit.SECONDS,
// custom check if the method call result failed or not
failureCustomChecker = "myFailureCustomChecker",
// except exceptions, throw out directly
excludeEx = IllegalStateException.class,
// include exceptions, default Exception.class
includeEx = {UnsupportedOperationException.class, UnmodifiableClassException.class},
// retry configs
retry = @Retry(
// how much retry times need to do
retryTimes = 3,
// delay to do retry
delay = 2L,
delayTimeUnit = TimeUnit.SECONDS,
// delay to do retry delay time strategy
delayStrategy = Retry.DelayStrategy.FIXED),
// recover
recover = @Recover(
fallback = "myFallbacker"
))
public Foo MyGuarderedMethodCall(String bar) {
// ... save bar
return new Foo(newBar);
}
```## Reminder
Since it bases on `SpringAOP` support, which has the same limitation like `@Transactional` or `@Cacheable`.
The `Order` of `@Guarder` is `org.springframework.core.Ordered#LOWEST_PRECEDENCE-1` by default, which is higher priority than `@Transaction`.
Ideally, We should keep transaction more close to method.Recommend to use `@Guarder` without other SpringAOP Annotations on same method together to avoid any potential `advice order` issue.
Make the sort on method construct level instead of advices is better.FYI, those `@Enable**` configs are works as well, if you know what I mean.
- `@EnableAspectJAutoProxy(exposeProxy = true)`
- `@EnableTransactionManagement(order = 1)`
- `...`## Build Project
```
JDK 11+
Gradle 7.2
```## Contribution
- Folk this project and build locally.
- Make your best changes and raise PR.
- Using the `Issue` trace is a plus.## License
MIT [@Koy](https://github.com/Koooooo-7)