Simple java library to detect duplicate method calls. The following scenarios can be covered:
- To prevent the system from sending texts or e-mails with the same messages over and over again to the same user
- To prevent the system from approving the same orders multiple times
- Spring Boot v2.1.6
@DuplicateDetection(ttlInSecond = 120, threshold = 1)
@KafkaListener(topicPattern = "texts")
public void send(String smsEvent) {
this.sendText(smsEvent);
}
Very easy to use once you provide CacheClient
implementation. For instance,
@Component
public class DefaultCacheClient implements CacheClient {
private RedisTemplate<String, MethodCall> redisTemplate;
public DefaultCacheClient(RedisTemplate<String, MethodCall> redisTemplate) {
this.redisTemplate = redisTemplate;
}
@Override
public MethodCall get(String key) {
return redisTemplate.opsForValue().get(key);
}
@Override
public void set(String key, MethodCall value, long timeout, TimeUnit unit) {
redisTemplate.opsForValue().set(key, value, timeout, unit);
}
}
If you are using Gradle as your build tool,
- Add the JitPack repository to your build file:
allprojects { repositories { ... maven { url "https://jitpack.io" } } }
- Add the dependency
dependencies { implementation 'com.github.andromedarabbit:Watchman:Tag' }
Maven, SBT, and Leiningen are supported as well.
docker run -p6379:6379 redis
gradle build