# ModuleEventConfig.java

    package cloud.wconnect.workperformance.config;

    import cloud.wconnect.aws.sns.messaging.core.AwsSignatureVerifier;
    import cloud.wconnect.aws.sns.messaging.core.VerificationProperties;
    import cloud.wconnect.sns.http.configuration.SnsHttpProperties;
    import cloud.wconnect.sns.http.processor.Sender;
    import org.springframework.beans.factory.annotation.Qualifier;
    import org.springframework.beans.factory.annotation.Value;
    import org.springframework.context.annotation.Bean;
    import org.springframework.context.annotation.Configuration;
    import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
    import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
    import software.amazon.awssdk.http.urlconnection.UrlConnectionHttpClient;
    import software.amazon.awssdk.regions.Region;
    import software.amazon.awssdk.services.sns.SnsClient;

    /**
     * aws事件配置类
     * Monthly Report数据发生变化后发送事件
     *
     * @author lichen
     * @date 2023/9/4
     */
    @Configuration
    public class ModuleEventConfig {

        @Value("${w-connect.module-event.access-key}")
        private String moduleEventAccessKey;

        @Value("${w-connect.module-event.secret-key}")
        private String moduleEventSecretKey;

        @Value("${w-connect.module-event.region}")
        private String moduleEventRegion;

        @Value("${w-connect.module-event.topic}")
        private String moduleEventTopic;

        @Value("${w-connect.module-event.category-name}")
        private String categoryName;

        @Value("${w-connect.module-event.max-life-time-of-message}")
        private long maxLifeTimeOfMessage;

        /**
         * 创建SnsClient
         *
         * @return software.amazon.awssdk.services.sns.SnsClient
         * @author lichen
         * @date 2023/9/4
         */
        @Bean("moduleEventSnsClient")
        public SnsClient getSnsClient() {
            return SnsClient.builder()
                    .credentialsProvider(StaticCredentialsProvider.create(AwsBasicCredentials.create(moduleEventAccessKey, moduleEventSecretKey)))
                    .region(Region.of(moduleEventRegion))
                    .httpClient(UrlConnectionHttpClient.builder().build())
                    .build();
        }

        /**
         * 创建Sender
         *
         * @param snsClient sns客户端
         * @return cloud.wconnect.sns.http.processor.Sender
         * @author lichen
         * @date 2023/9/4
         */
        @Bean("moduleEventSender")
        public Sender getSender(@Qualifier("moduleEventSnsClient") SnsClient snsClient) {
            SnsHttpProperties properties = new SnsHttpProperties();
            properties.setTopic(moduleEventTopic);
            properties.setCategoryName(categoryName);
            return new Sender(properties, snsClient);
        }

        @Bean("moduleAwsSignatureVerifier")
        public AwsSignatureVerifier getAwsSignatureVerifier() {
            VerificationProperties config = new VerificationProperties();
            config.setMaxLifeTimeOfMessage(maxLifeTimeOfMessage);
            return new AwsSignatureVerifier(config);
        }
    }