多活高可用服务 MAS-ShedLock

时间:2024-10-23 17:37:41

ShedLock

对接ShedLock。

import com.huawei.devspore.mas.Redis.core.MultiZoneClient;
import com.huawei.devspore.mas.Redis.spring.boot.cache.DcsConnectionFactory;
import net.javacrumbs.shedlock.core.LockProvider;
import net.javacrumbs.shedlock.provider.Redis.spring.RedisLockProvider;
import net.javacrumbs.shedlock.spring.annotation.EnableSchedulerLock;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;

@Configuration
@EnableScheduling
@EnableSchedulerLock(defaultLockAtMostFor = "PT30S")
public class ShedLockJdbcConfig {
    @Bean
    public DcsConnectionFactory dcsConnectionFactory(MultiZoneClient client) {
        return new DcsConnectionFactory(client);
    }

    @Bean
    public LockProvider lockProvider(DcsConnectionFactory connectionFactory) {
        return new RedisLockProvider(connectionFactory);
    }
}
support.huaweicloud.com/devg-mas/mas-devg-00117.html