Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@
</dependency>

<!-- AWS SDK version 2 libs -->
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>sns</artifactId>
<version>2.13.36</version>
</dependency>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>sqs</artifactId>
Expand All @@ -133,9 +138,9 @@
<version>2.13.36</version>
</dependency>
<dependency>
<artifactId>netty-nio-client</artifactId>
<groupId>software.amazon.awssdk</groupId>
<version>2.0.0</version>
<artifactId>netty-nio-client</artifactId>
<version>2.13.36</version>
</dependency>


Expand Down
8 changes: 6 additions & 2 deletions src/main/java/cloud/localstack/awssdkv2/TestUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import software.amazon.awssdk.utils.*;
import software.amazon.awssdk.http.*;
import software.amazon.awssdk.services.kinesis.*;
import software.amazon.awssdk.services.sns.*;
import software.amazon.awssdk.services.sqs.*;
import software.amazon.awssdk.http.nio.netty.NettyNioAsyncHttpClient;

Expand All @@ -26,8 +27,11 @@ public static SqsAsyncClient getClientSQSAsyncV2() {
return wrapApiClientV2(SqsAsyncClient.builder(), Localstack.INSTANCE.getEndpointSQS()).build();
}

public static <T extends software.amazon.awssdk.core.client.builder.SdkAsyncClientBuilder> T wrapApiClientV2(
T builder, String endpointURL) {
public static SnsAsyncClient getClientSNSAsyncV2() {
return wrapApiClientV2(SnsAsyncClient.builder(), Localstack.INSTANCE.getEndpointSNS()).build();
}

public static <T extends software.amazon.awssdk.core.client.builder.SdkAsyncClientBuilder> T wrapApiClientV2(T builder, String endpointURL) {
try {
return (T) ((software.amazon.awssdk.awscore.client.builder.AwsClientBuilder)builder
.httpClient(NettyNioAsyncHttpClient.builder().buildWithDefaults(
Expand Down
34 changes: 34 additions & 0 deletions src/test/java/cloud/localstack/awssdkv2/SNSMessagingTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package cloud.localstack.awssdkv2;

import cloud.localstack.LocalstackTestRunner;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import software.amazon.awssdk.services.sns.SnsAsyncClient;
import software.amazon.awssdk.services.sns.model.CreateTopicRequest;
import software.amazon.awssdk.services.sns.model.CreateTopicResponse;
import software.amazon.awssdk.services.sns.model.PublishRequest;
import software.amazon.awssdk.services.sns.model.PublishResponse;

import java.util.concurrent.ExecutionException;

/**
* Test integration of SNS messaging with LocalStack using SDK v2
*/
@RunWith(LocalstackTestRunner.class)
public class SNSMessagingTest {
private static final String TOPIC = "topic";

@Test
public void testSendMessage() throws ExecutionException, InterruptedException {
final SnsAsyncClient clientSNS = TestUtils.getClientSNSAsyncV2();
CreateTopicResponse createTopicResponse = clientSNS.createTopic(CreateTopicRequest.builder().name(TOPIC).build()).get();

String topicArn = createTopicResponse.topicArn();
Assert.assertNotNull(topicArn);
PublishRequest publishRequest = PublishRequest.builder().topicArn(topicArn).subject("test subject").message("message test.").build();

PublishResponse publishResponse = clientSNS.publish(publishRequest).get();
Assert.assertNotNull(publishResponse.messageId());
}
}