Skip to content

Commit

Permalink
AWS SDK 2 upgrade: Fix compile errors in messaging - spring-atticgh-267
Browse files Browse the repository at this point in the history
  • Loading branch information
tinexw committed Feb 13, 2020
1 parent ee65dd5 commit 774f4b6
Show file tree
Hide file tree
Showing 40 changed files with 1,257 additions and 1,191 deletions.
12 changes: 8 additions & 4 deletions spring-cloud-aws-messaging/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@
<artifactId>spring-cloud-aws-context</artifactId>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-sns</artifactId>
<groupId>software.amazon.awssdk</groupId>
<artifactId>sns</artifactId>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-sqs</artifactId>
<groupId>software.amazon.awssdk</groupId>
<artifactId>sqs</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
Expand Down Expand Up @@ -76,5 +76,9 @@
<artifactId>jackson-datatype-jsr310</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
import java.util.Arrays;
import java.util.List;

import com.amazonaws.services.sqs.AmazonSQS;
import com.amazonaws.services.sqs.AmazonSQSAsync;
import software.amazon.awssdk.services.sqs.SqsClient;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.cloud.aws.core.env.ResourceIdResolver;
Expand All @@ -47,7 +46,7 @@ public class QueueMessageHandlerFactory {

private DestinationResolvingMessageSendingOperations<?> sendToMessagingTemplate;

private AmazonSQSAsync amazonSqs;
private SqsClient amazonSqs;

private ResourceIdResolver resourceIdResolver;

Expand Down Expand Up @@ -78,26 +77,26 @@ public void setSendToMessagingTemplate(
this.sendToMessagingTemplate = sendToMessagingTemplate;
}

public AmazonSQS getAmazonSqs() {
public SqsClient getAmazonSqs() {
return this.amazonSqs;
}

/**
* <p>
* Sets the {@link AmazonSQS} client that is going to be used to create a new
* Sets the {@link SqsClient} client that is going to be used to create a new
* {@link QueueMessagingTemplate} if {@code sendToMessagingTemplate} is {@code null}.
* This template is used by the {@link SendToHandlerMethodReturnValueHandler} to send
* the return values of handler methods annotated with
* {@link org.springframework.messaging.handler.annotation.SendTo}.
* </p>
* <p>
* An {@link AmazonSQS} client is only needed if {@code sendToMessagingTemplate} is
* An {@link SqsClient} client is only needed if {@code sendToMessagingTemplate} is
* {@code null}.
* </p>
* @param amazonSqs The {@link AmazonSQS} client that is going to be used by the
* @param amazonSqs The {@link SqsClient} client that is going to be used by the
* {@link SendToHandlerMethodReturnValueHandler} to send messages.
*/
public void setAmazonSqs(AmazonSQSAsync amazonSqs) {
public void setAmazonSqs(SqsClient amazonSqs) {
this.amazonSqs = amazonSqs;
}

Expand Down Expand Up @@ -157,7 +156,7 @@ public QueueMessageHandler createQueueMessageHandler() {
}

private QueueMessagingTemplate getDefaultSendToQueueMessagingTemplate(
AmazonSQSAsync amazonSqs, ResourceIdResolver resourceIdResolver) {
SqsClient amazonSqs, ResourceIdResolver resourceIdResolver) {
return new QueueMessagingTemplate(amazonSqs, resourceIdResolver,
getDefaultMappingJackson2MessageConverter());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@

package org.springframework.cloud.aws.messaging.config;

import com.amazonaws.services.sqs.AmazonSQS;
import com.amazonaws.services.sqs.AmazonSQSAsync;
import software.amazon.awssdk.services.sqs.SqsClient;

import org.springframework.cloud.aws.core.env.ResourceIdResolver;
import org.springframework.cloud.aws.messaging.listener.QueueMessageHandler;
Expand All @@ -43,7 +42,7 @@ public class SimpleMessageListenerContainerFactory {

private boolean autoStartup = true;

private AmazonSQSAsync amazonSqs;
private SqsClient amazonSqs;

private QueueMessageHandler queueMessageHandler;

Expand Down Expand Up @@ -105,16 +104,16 @@ public void setAutoStartup(boolean autoStartup) {
this.autoStartup = autoStartup;
}

public AmazonSQS getAmazonSqs() {
public SqsClient getAmazonSqs() {
return this.amazonSqs;
}

/**
* Sets the {@link AmazonSQSAsync} that is going to be used by the container to
* interact with the messaging (SQS) API.
* @param amazonSqs The {@link AmazonSQSAsync}, must not be {@code null}.
* Sets the {@link SqsClient} that is going to be used by the container to interact
* with the messaging (SQS) API.
* @param amazonSqs The {@link SqsClient}, must not be {@code null}.
*/
public void setAmazonSqs(AmazonSQSAsync amazonSqs) {
public void setAmazonSqs(SqsClient amazonSqs) {
Assert.notNull(amazonSqs, "amazonSqs must not be null");
this.amazonSqs = amazonSqs;
}
Expand Down Expand Up @@ -188,6 +187,7 @@ public SimpleMessageListenerContainer createSimpleMessageListenerContainer() {
Assert.notNull(this.amazonSqs, "amazonSqs must not be null");

SimpleMessageListenerContainer simpleMessageListenerContainer = new SimpleMessageListenerContainer();
// TODO SDK2 migration: solve the issue with the async and sync client
simpleMessageListenerContainer.setAmazonSqs(this.amazonSqs);
simpleMessageListenerContainer.setAutoStartup(this.autoStartup);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@

package org.springframework.cloud.aws.messaging.config.annotation;

import com.amazonaws.auth.AWSCredentialsProvider;
import com.amazonaws.services.sns.AmazonSNS;
import com.amazonaws.services.sns.AmazonSNSClient;
import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider;
import software.amazon.awssdk.services.sns.SnsClient;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.aws.context.annotation.ConditionalOnMissingAmazonClient;
Expand All @@ -36,15 +35,15 @@
public class SnsConfiguration {

@Autowired(required = false)
private AWSCredentialsProvider awsCredentialsProvider;
private AwsCredentialsProvider awsCredentialsProvider;

@Autowired(required = false)
private RegionProvider regionProvider;

@ConditionalOnMissingAmazonClient(AmazonSNS.class)
@ConditionalOnMissingAmazonClient(SnsClient.class)
@Bean
public AmazonWebserviceClientFactoryBean<AmazonSNSClient> amazonSNS() {
return new AmazonWebserviceClientFactoryBean<>(AmazonSNSClient.class,
public AmazonWebserviceClientFactoryBean<SnsClient> amazonSNS() {
return new AmazonWebserviceClientFactoryBean<>(SnsClient.class,
this.awsCredentialsProvider, this.regionProvider);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import java.util.List;

import com.amazonaws.services.sns.AmazonSNS;
import software.amazon.awssdk.services.sns.SnsClient;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.aws.context.annotation.ConditionalOnClass;
Expand All @@ -36,7 +36,7 @@
public class SnsWebConfiguration implements WebMvcConfigurer {

@Autowired
private AmazonSNS amazonSns;
private SnsClient amazonSns;

@Override
public void addArgumentResolvers(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@

package org.springframework.cloud.aws.messaging.config.annotation;

import com.amazonaws.auth.AWSCredentialsProvider;
import com.amazonaws.services.sqs.AmazonSQS;
import com.amazonaws.services.sqs.AmazonSQSAsyncClient;
import com.amazonaws.services.sqs.buffered.AmazonSQSBufferedAsyncClient;
import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider;
import software.amazon.awssdk.services.sqs.SqsAsyncClient;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.aws.context.annotation.ConditionalOnMissingAmazonClient;
Expand All @@ -34,23 +32,28 @@
* @since 1.0
*/
@Configuration(proxyBeanMethods = false)
@ConditionalOnMissingAmazonClient(AmazonSQS.class)
@ConditionalOnMissingAmazonClient(SqsAsyncClient.class)
public class SqsClientConfiguration {

@Autowired(required = false)
private AWSCredentialsProvider awsCredentialsProvider;
private AwsCredentialsProvider awsCredentialsProvider;

@Autowired(required = false)
private RegionProvider regionProvider;

@Lazy
@Bean(destroyMethod = "shutdown")
public AmazonSQSBufferedAsyncClient amazonSQS() throws Exception {
AmazonWebserviceClientFactoryBean<AmazonSQSAsyncClient> clientFactoryBean = new AmazonWebserviceClientFactoryBean<>(
AmazonSQSAsyncClient.class, this.awsCredentialsProvider,
this.regionProvider);
public SqsAsyncClient amazonSQS() throws Exception {
AmazonWebserviceClientFactoryBean<SqsAsyncClient> clientFactoryBean = new AmazonWebserviceClientFactoryBean<>(
SqsAsyncClient.class, this.awsCredentialsProvider, this.regionProvider);
clientFactoryBean.afterPropertiesSet();
return new AmazonSQSBufferedAsyncClient(clientFactoryBean.getObject());
// TODO SDK2 migration: update
// Important
// The AWS SDK for Java 2.x isn't currently compatible with the
// AmazonSQSBufferedAsyncClient.
// https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-client-side-buffering-request-batching.html
// return new AmazonSQSBufferedAsyncClient(clientFactoryBean.getObject());
return clientFactoryBean.getObject();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import java.util.Arrays;

import com.amazonaws.services.sqs.AmazonSQSAsync;
import software.amazon.awssdk.services.sqs.SqsClient;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -64,7 +64,7 @@ public class SqsConfiguration {

@Bean
public SimpleMessageListenerContainer simpleMessageListenerContainer(
AmazonSQSAsync amazonSqs) {
SqsClient amazonSqs) {
if (this.simpleMessageListenerContainerFactory.getAmazonSqs() == null) {
this.simpleMessageListenerContainerFactory.setAmazonSqs(amazonSqs);
}
Expand All @@ -80,7 +80,7 @@ public SimpleMessageListenerContainer simpleMessageListenerContainer(
}

@Bean
public QueueMessageHandler queueMessageHandler(AmazonSQSAsync amazonSqs) {
public QueueMessageHandler queueMessageHandler(SqsClient amazonSqs) {
if (this.simpleMessageListenerContainerFactory.getQueueMessageHandler() != null) {
return this.simpleMessageListenerContainerFactory.getQueueMessageHandler();
}
Expand All @@ -89,7 +89,7 @@ public QueueMessageHandler queueMessageHandler(AmazonSQSAsync amazonSqs) {
}
}

private QueueMessageHandler getMessageHandler(AmazonSQSAsync amazonSqs) {
private QueueMessageHandler getMessageHandler(SqsClient amazonSqs) {
if (this.queueMessageHandlerFactory.getAmazonSqs() == null) {
this.queueMessageHandlerFactory.setAmazonSqs(amazonSqs);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import java.util.Collections;

import com.amazonaws.services.sns.AmazonSNS;
import software.amazon.awssdk.services.sns.SnsClient;

import org.springframework.cloud.aws.core.env.ResourceIdResolver;
import org.springframework.cloud.aws.messaging.core.support.AbstractMessageChannelMessagingSendingTemplate;
Expand All @@ -33,25 +33,25 @@
public class NotificationMessagingTemplate
extends AbstractMessageChannelMessagingSendingTemplate<TopicMessageChannel> {

private final AmazonSNS amazonSns;
private final SnsClient amazonSns;

public NotificationMessagingTemplate(AmazonSNS amazonSns) {
public NotificationMessagingTemplate(SnsClient amazonSns) {
this(amazonSns, (ResourceIdResolver) null, null);
}

public NotificationMessagingTemplate(AmazonSNS amazonSns,
public NotificationMessagingTemplate(SnsClient amazonSns,
ResourceIdResolver resourceIdResolver) {
this(amazonSns, resourceIdResolver, null);
}

public NotificationMessagingTemplate(AmazonSNS amazonSns,
public NotificationMessagingTemplate(SnsClient amazonSns,
ResourceIdResolver resourceIdResolver, MessageConverter messageConverter) {
super(new DynamicTopicDestinationResolver(amazonSns, resourceIdResolver));
this.amazonSns = amazonSns;
initMessageConverter(messageConverter);
}

public NotificationMessagingTemplate(AmazonSNS amazonSns,
public NotificationMessagingTemplate(SnsClient amazonSns,
DestinationResolver<String> destinationResolver,
MessageConverter messageConverter) {
super(destinationResolver);
Expand Down
Loading

0 comments on commit 774f4b6

Please sign in to comment.