andromedarabbit / Watchman

Simple java library to detect duplicate method calls

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Build Status codecov

Watchman

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

Prerequisites

How to use Watchman

@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);
    }
}

How to get Watchman into your build

If you are using Gradle as your build tool,

  1. Add the JitPack repository to your build file:
    allprojects {
    	repositories {
    		...
    		maven { url "https://jitpack.io" }
    	}
    }
  2. Add the dependency
    dependencies {
        implementation 'com.github.andromedarabbit:Watchman:Tag'
    }

Maven, SBT, and Leiningen are supported as well.

How to run tests

docker run -p6379:6379 redis

gradle build

About

Simple java library to detect duplicate method calls

License:Apache License 2.0


Languages

Language:Java 100.0%