springboot.delaytask.SpringBootAutoConfiguration Maven / Gradle / Ivy
/*
* @(#)SpringBootAutoConfiguration.java 2021-10-27
*
* Copyright (c) 2021. All Rights Reserved.
*
*/
package springboot.delaytask;
import org.springframework.aop.aspectj.AspectJExpressionPointcut;
import org.springframework.aop.support.DefaultPointcutAdvisor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;
import org.springframework.context.annotation.Primary;
import com.github.javaclub.delaytask.DelayQueueConsumer;
import com.github.javaclub.delaytask.DelayQueueProducer;
import com.github.javaclub.delaytask.DelayTaskConstants.DelayTaskConfig;
import com.github.javaclub.delaytask.impl.BoundedDelayQueueProducer;
import com.github.javaclub.delaytask.impl.DelayQueueConsumerImpl;
import com.github.javaclub.delaytask.impl.DelayQueueProducerImpl;
import com.github.javaclub.delaytask.interceptor.QueueEntityConsumerExecuteInterceptor;
import com.github.javaclub.delaytask.redis.PooledRedisClient;
import com.github.javaclub.toolbox.cache.redis.RedisStore;
/**
* SpringBootAutoConfiguration
*
* @author Gerald Chen
* @version $Id: SpringBootAutoConfiguration.java 2021-10-27 11:36:58 Exp $
*/
@Configuration
public class SpringBootAutoConfiguration {
@Bean
@Lazy
@ConditionalOnMissingBean(PooledRedisClient.class)
public PooledRedisClient pooledRedisClient() {
RedisStore store = DelayTaskBuilder.buildDelayTaskRedisStore();
PooledRedisClient client = new PooledRedisClient(store.getJedisPool());
return client;
}
@Bean
@Primary
public DelayQueueProducer delayQueueProducer(PooledRedisClient pooledRedisClient) {
DelayQueueProducerImpl delayQProducer = new DelayQueueProducerImpl();
delayQProducer.setPooledRedisClient(pooledRedisClient);
BoundedDelayQueueProducer boundedProducer = new BoundedDelayQueueProducer();
boundedProducer.setDelegate(delayQProducer);
return boundedProducer;
}
@Bean
public DelayQueueConsumer delayQueueConsumer(PooledRedisClient pooledRedisClient,
DelayQueueProducer delayQueueProducer) {
DelayQueueConsumerImpl consumer = new DelayQueueConsumerImpl();
consumer.setPooledRedisClient(pooledRedisClient);
consumer.setDelayQueueProducer(delayQueueProducer);
return consumer;
}
@Bean("delayTaskRetryPointcutAdvisor")
public DefaultPointcutAdvisor delayTaskRetryPointcutAdvisor(PooledRedisClient pooledRedisClient) {
QueueEntityConsumerExecuteInterceptor methodInterceptor = new QueueEntityConsumerExecuteInterceptor(pooledRedisClient);
DefaultPointcutAdvisor advisor = new DefaultPointcutAdvisor();
AspectJExpressionPointcut pointcut = new AspectJExpressionPointcut();
pointcut.setExpression(DelayTaskConfig.RETRY_ANNOTATION_EXECUTION);
advisor.setPointcut(pointcut);
advisor.setAdvice(methodInterceptor);
return advisor;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy