分布式架构

1、分布式锁
String lockkey = "test-info-uid-" + testInfo.getUid();
Lock lock = domainDistributedLockService.obtain(lockkey);
boolean lockFlag = lock.tryLock();
if (!lockFlag) {
log.warn("未获取到锁 ,taskId=" + taskId);
return;
}
try {
} catch (Exception ex) {
throw ex;
} finally {
if (lockFlag) {
lock.unlock();
}
}

@Service
public class RedisDistributedLock implements DomainDistributedLockService {

@Autowired
RedisLockRegistry redisLockRegistry;

@Override
public Lock obtain(String lockKey) {
return redisLockRegistry.obtain(lockKey);
}
}

2、基于状态更新保证幂等

   update(int statusBefore, int statusAfter)

3、事前,事中,事后思想

   doBefore

   do

   doAfter

4、

posted @ 2026-07-21 09:56  yuxuan0802  阅读(2)  评论(0)    收藏  举报