All Projects → Trendyol → Jdempotent

Trendyol / Jdempotent

Licence: MIT license
Make your consumer, API, etc. idempotent easily.

Programming Languages

java
68154 projects - #9 most used programming language
Dockerfile
14818 projects

Projects that are alternatives of or similar to Jdempotent

neo4j-couchbase-connector
Neo4j - Couchbase Connection API
Stars: ✭ 14 (-77.42%)
Mutual labels:  couchbase
couchmove
Java data migration tool for Couchbase
Stars: ✭ 36 (-41.94%)
Mutual labels:  couchbase
lounge
Simple Mongoose-inspired ODM for Couchbase.
Stars: ✭ 27 (-56.45%)
Mutual labels:  couchbase
showfast
Performance dashboard
Stars: ✭ 18 (-70.97%)
Mutual labels:  couchbase
Doramon
个人工具汇总:一致性哈希工具,Bitmap工具,布隆过滤器参数生成器,Yaml和properties互转工具,一键式生成整个前后端工具,单机高性能幂等工具,zookeeper客户端工具,分布式全局id生成器,时间转换工具,Http封装工具
Stars: ✭ 53 (-14.52%)
Mutual labels:  idempotency
Cachalot
Caching rethought – cache a lot in a proper way.
Stars: ✭ 25 (-59.68%)
Mutual labels:  couchbase
CouchDraw
A synchronized drawing app that utilizes Couchbase Sync Gateway and Xamarin to enable shared canvases.
Stars: ✭ 22 (-64.52%)
Mutual labels:  couchbase
lua-resty-couchbase
Lua couchbase client driver for the ngx_lua based on the cosocket API / 使用cosocket纯lua实现的couchbase的client,已经在爱奇艺重要的服务播放服务稳定运行5年多
Stars: ✭ 77 (+24.19%)
Mutual labels:  couchbase
docker-couchbase-server
🎪 Couchbase Server clusters on Docker
Stars: ✭ 20 (-67.74%)
Mutual labels:  couchbase
laravel-idempotency
Laravel Idempotency Middleware
Stars: ✭ 22 (-64.52%)
Mutual labels:  idempotency
Phpfastcache
A high-performance backend cache system. It is intended for use in speeding up dynamic web applications by alleviating database load. Well implemented, it can drops the database load to almost nothing, yielding faster page load times for users, better resource utilization. It is simple yet powerful.
Stars: ✭ 2,171 (+3401.61%)
Mutual labels:  couchbase
sidecache
Sidecar cache for kubernetes applications.
Stars: ✭ 38 (-38.71%)
Mutual labels:  couchbase
couchbase-shell
Shell yeah!
Stars: ✭ 30 (-51.61%)
Mutual labels:  couchbase
doc2graph
Convert JSON from document-oriented DB to neo4j graph
Stars: ✭ 17 (-72.58%)
Mutual labels:  couchbase
synctos
The Syncmaker. A tool to build comprehensive sync functions for Couchbase Sync Gateway.
Stars: ✭ 51 (-17.74%)
Mutual labels:  couchbase
php-couchbase
Couchbase PHP Client Library (Official)
Stars: ✭ 80 (+29.03%)
Mutual labels:  couchbase
couchbase exporter
Export metrics from Couchbase Server for Prometheus consumption
Stars: ✭ 32 (-48.39%)
Mutual labels:  couchbase
one
🚥 Idempotency Handler, for making sure incoming requests are idempotent. Useful for payments, "at least once delivery" systems and more.
Stars: ✭ 18 (-70.97%)
Mutual labels:  idempotency
couchbase-exporter
Prometheus Couchbase 5 Exporter, Grafana dashboard and Alerting rules included
Stars: ✭ 41 (-33.87%)
Mutual labels:  couchbase
mango
Core utility library & data connectors designed for simpler usage in Scala
Stars: ✭ 41 (-33.87%)
Mutual labels:  couchbase

Jdempotent

Release Jdempotent

Goal of this Jdempotent-spring-boot-starter

Make your endpoints idempotent easily

Usage

  1. First of all, you need to add a dependency to pom.xml

For Redis:

<dependency>
    <groupId>com.trendyol</groupId>
    <artifactId>Jdempotent-spring-boot-redis-starter</artifactId>
    <version>1.1.0</version>
</dependency>

For Couchbase:

<dependency>
    <groupId>com.trendyol</groupId>
    <artifactId>Jdempotent-spring-boot-couchbase-starter</artifactId>
    <version>1.1.0</version>
</dependency>
  1. You should add @IdempotentResource annotation to the method that you want to make idempotent resource, listener etc.
@IdempotentResource(cachePrefix = "WelcomingListener")
@KafkaListener(topics = "trendyol.mail.welcome", groupId = "group_id")
public void consumeMessage(@IdempotentRequestPayload String emailAdress) {
    SendEmailRequest request = SendEmailRequest.builder()
            .email(message)
            .subject(subject)
            .build();

    try {
        mailSenderService.sendMail(request);
    } catch (MessagingException e) {
        logger.error("MailSenderService.sendEmail() throw exception {} event: {} ", e, emailAdress);

        // Throwing any exception is enough to delete from redis. When successful, it will not be deleted from redis and will be idempotent.
        throw new RetryIdempotentRequestException(e);
    }
}

If want that idempotencyId in your payload. Put @JdempotentId annotation that places the generated idempotency identifier into annotated field. Can be thought of as @Id annotation in jpa.

public class IdempotentPaylaod {
   @JdempotentId
   private String jdempotentId;
   private Object data;
}

You might want to handle the name of the field differently to ensure idempotency. Just use @JdempotentProperty annotation needs to get the field name differently and generate the hash inspired by jackson (@JsonProperty annotation)

public class IdempotentPaylaod {
   @JdempotentProperty("userId")
   private String customerId;
   private Object data;
}
  1. If you want to handle a custom error case, you need to implement ErrorConditionalCallback like the following example:
@Component
public class AspectConditionalCallback implements ErrorConditionalCallback {

    @Override
    public boolean onErrorCondition(Object response) {
        return response == IdempotentStateEnum.ERROR;
    }
    
    public RuntimeException onErrorCustomException() {
        return new RuntimeException("Status cannot be error");
    }

}
  1. Let's make the configuration:

For redis configuration:

jdempotent:
  enable: true
  cache:
    redis:
      database: 1
      password: "password"
      sentinelHostList: 192.168.0.1,192.168.0.2,192.168.0.3
      sentinelPort: "26379"
      sentinelMasterName: "admin"
      expirationTimeHour: 2
      dialTimeoutSecond: 3
      readTimeoutSecond: 3
      writeTimeoutSecond: 3
      maxRetryCount: 3
      expireTimeoutHour: 3

For couchbase configuration:

jdempotent:
  enable: true
  cryptography:
    algorithm: MD5
  cache:
    couchbase:
      connection-string: XXXXXXXX
      password: XXXXXXXX
      username: XXXXXXXX
      bucket-name: XXXXXXXX
      connect-timeout: 100000
      query-timeout: 20000
      kv-timeout: 3000

Please note that you can disable Jdempotent easily if you need to. For example, assume that you don't have a circut breaker and your Redis is down. In that case, you can disable Jdempotent with the following configuration:

  enable: false
@SpringBootApplication(
      exclude = { RedisAutoConfiguration.class, RedisRepositoriesAutoConfiguration.class }
)

Performance

As it is shown in the following image, the most cpu consuming part of Jdempotent is getting a Redis connection so we don't need to worry performance related issues.

Docs

Jdempotent Medium Article
Jdempotent-core Javadoc
Jdempotent-spring-boot-redis-starter Javadoc

Support

memojja's twitter

Licence

MIT Licence

Contributing

  1. Fork it ( https://github.com/Trendyol/Jdempotent/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Contributors

  • memojja Mehmet ARI - creator, maintainer
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].