com.neko233.skilltree.commons.idempotent.IdempotentApi Maven / Gradle / Ivy
package com.neko233.skilltree.commons.idempotent;
/**
* 幂等 API
* Action = create, mark, isExists, commit
*
* @author SolarisNeko on 2023-07-23
*/
public interface IdempotentApi {
default boolean createIdempotentState(String businessType, Number uniqueId) throws Exception {
if (uniqueId == null) {
return false;
}
return createIdempotentState(businessType, String.valueOf(uniqueId));
}
/**
* 创建幂等状态
*
* @param businessType 业务类型
* @param uniqueId 唯一id
* @return is ok ?
* @throws Exception 具体实现的异常
*/
boolean createIdempotentState(String businessType, String uniqueId) throws Exception;
boolean isExists(String businessType, String uniqueId);
default boolean isNotExists(String businessType, String uniqueId) {
return !isExists(businessType, uniqueId);
}
default boolean isExists(String businessType, Number uniqueId) {
return isExists(businessType, String.valueOf(uniqueId));
}
/**
* @param businessType 业务类型
* @param uniqueId 消息唯一id
* @return 提交是否成功
*/
boolean commit(String businessType, String uniqueId);
default boolean commit(String businessType, Number uniqueId) {
return commit(businessType, String.valueOf(uniqueId));
}
/**
* 标记为废弃. 例如: 订单 30min 超时, 等情况
*
* @return is ok ?
*/
boolean markDeprecated(String businessType, String uniqueId);
}