Code Monkey home page Code Monkey logo

agency-lock's Introduction

agency-lock

This open-source project is a proxy lock project that enables dynamic switching to different lock implementations using the proxy lock approach. It is designed to upgrade from a single-machine lock to a distributed lock, catering to various application scenarios.

Getting started

  • Download project

    git clone https://github.com/luohongtu/agency-lock.git

  • Install to the local repository

    mvn clean install

  • Add agency-lock-spring-boot-starter dependency

<dependency>
  <groupId>cn.foolishbird</groupId>
  <artifactId>agency-lock-spring-boot-starter</artifactId>
  <version>1.1.0</version>
</exclusions>

  • Configure the springboot environment
agency:
  config:
    agencyLockType: "redisson"
  • The lock key generation policy
@Configuration
public class AgencyLockConfig {

    @Bean("springElGenerator")
    public KeyGenerator springELMethonNameKeyGenerator() {
        return new SpringELMethonNameKeyGenerator();
    }

}
  • Idempotent locks are used
@Idempotent(key = "#param.phone", keyGenerator = "springElGenerator", leaseTime = 6)
public String login(@Validated @RequestBody PhoneLoginParam param) {
    return "token";
}
  • AgencyLock locks are used
@AgencyLock(key = "#param.phone", keyGenerator = "springElGenerator", leaseTime = 6)
public String login(@Validated @RequestBody PhoneLoginParam param) {
    return "token";
}
  • Lock code block
@Autowired
private AgencyLockManger agencyLockManger;

public void test1() throws Exception {
    String key = "demoKey";
    AgencyLock lock = agencyLockManger.getLock(key);
    try {
      lock.lock();
      // service code
      Thread.sleep(3000);
      System.out.println("test success");
    } finally {
      lock.unlock();
      agencyLockManger.removeLock(key);
    }
}

agency-lock is Open Source software released under the Apache 2.0 license.

agency-lock's People

Contributors

luohongtu avatar

Stargazers

yx avatar 启明 avatar  avatar Baily燃着的半支烟 avatar  avatar  avatar  avatar  avatar  avatar Silent avatar 小手冰凉 avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.