1 /*
2  * Copyright 2013-2019 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      https://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.springframework.cloud.aws.messaging.config.annotation;
18
19 import com.amazonaws.auth.AWSCredentialsProvider;
20 import com.amazonaws.services.sqs.AmazonSQS;
21 import com.amazonaws.services.sqs.AmazonSQSAsyncClient;
22 import com.amazonaws.services.sqs.buffered.AmazonSQSBufferedAsyncClient;
23
24 import org.springframework.beans.factory.annotation.Autowired;
25 import org.springframework.cloud.aws.context.annotation.ConditionalOnMissingAmazonClient;
26 import org.springframework.cloud.aws.core.config.AmazonWebserviceClientFactoryBean;
27 import org.springframework.cloud.aws.core.region.RegionProvider;
28 import org.springframework.context.annotation.Bean;
29 import org.springframework.context.annotation.Configuration;
30 import org.springframework.context.annotation.Lazy;
31
32 /**
33  * @author Alain Sahli
34  * @since 1.0
35  */

36 @Configuration(proxyBeanMethods = false)
37 @ConditionalOnMissingAmazonClient(AmazonSQS.class)
38 public class SqsClientConfiguration {
39
40     @Autowired(required = false)
41     private AWSCredentialsProvider awsCredentialsProvider;
42
43     @Autowired(required = false)
44     private RegionProvider regionProvider;
45
46     @Lazy
47     @Bean(destroyMethod = "shutdown")
48     public AmazonSQSBufferedAsyncClient amazonSQS() throws Exception {
49         AmazonWebserviceClientFactoryBean<AmazonSQSAsyncClient> clientFactoryBean = new AmazonWebserviceClientFactoryBean<>(
50                 AmazonSQSAsyncClient.classthis.awsCredentialsProvider,
51                 this.regionProvider);
52         clientFactoryBean.afterPropertiesSet();
53         return new AmazonSQSBufferedAsyncClient(clientFactoryBean.getObject());
54     }
55
56 }
57