All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.dengchen2020.message.config.MessageAutoConfiguration Maven / Gradle / Ivy

package io.github.dengchen2020.message.config;

import io.github.dengchen2020.message.dingtalk.DingTalkClient;
import io.github.dengchen2020.message.dingtalk.DingTalkClientImpl;
import io.github.dengchen2020.message.email.EmailClient;
import io.github.dengchen2020.message.email.EmailClientImpl;
import io.github.dengchen2020.message.feishu.FeiShuClient;
import io.github.dengchen2020.message.feishu.FeiShuClientImpl;
import io.github.dengchen2020.message.properties.DcMessageBuilder;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.task.SimpleAsyncTaskExecutorBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.task.SimpleAsyncTaskExecutor;
import org.springframework.mail.javamail.JavaMailSender;

/**
 * 消息自动配置
 * @author xiaochen
 * @since 2024/6/4
 */
@EnableConfigurationProperties(DcMessageBuilder.class)
@Configuration(proxyBeanMethods = false)
public class MessageAutoConfiguration {

    private final DcMessageBuilder dcMessageBuilder;

    public MessageAutoConfiguration(DcMessageBuilder dcMessageBuilder) {
        this.dcMessageBuilder = dcMessageBuilder;
    }

    public static final String MESSAGE_SEND_ASYNC_EXECUTOR = "messageSendAsyncExecutor";

    @Bean(MESSAGE_SEND_ASYNC_EXECUTOR)
    public SimpleAsyncTaskExecutor messageSendAsyncExecutor() {
        return new SimpleAsyncTaskExecutorBuilder().threadNamePrefix("message-send-").virtualThreads(true)
                .concurrencyLimit(dcMessageBuilder.getConcurrencyLimit()).build();
    }

    @ConditionalOnMissingBean(FeiShuClient.class)
    @Bean
    public FeiShuClient feiShuService(){
        return new FeiShuClientImpl(dcMessageBuilder.getFeiShu().getWebhook());
    }

    @ConditionalOnMissingBean(DingTalkClient.class)
    @Bean
    public DingTalkClient dingTalkService(){
        return new DingTalkClientImpl(dcMessageBuilder.getDingTalk().getWebhook());
    }

    @ConditionalOnBean(JavaMailSender.class)
    @Bean
    public EmailClient emailService(JavaMailSender javaMailSender){
        return new EmailClientImpl(javaMailSender,dcMessageBuilder.getEmail().getTo());
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy