# ModuleEventConfig.java

    package cloud.wconnect.frontoffice.config.snsmoduleevent;

    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.boot.autoconfigure.condition.ConditionalOnProperty;
    import org.springframework.context.annotation.Bean;
    import org.springframework.context.annotation.Configuration;
    import org.springframework.context.annotation.Profile;
    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
     */
    @ConditionalOnProperty(prefix = "w-connect.module-event", name = "status", havingValue = "active")
    @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
         */
        @Profile("!apitest")
        @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);
        }

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