Skip to content

Commit

Permalink
[WIP] large SQS message
Browse files Browse the repository at this point in the history
  • Loading branch information
agebhar1 committed Feb 27, 2024
1 parent e4552ce commit fd12d48
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 4 deletions.
22 changes: 22 additions & 0 deletions aws/sqs/java/aws-sqs/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@

<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>amazon-sqs-java-extended-client-lib</artifactId>
<version>2.0.2</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.13.2.2</version>
</dependency>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>bom</artifactId>
Expand All @@ -63,6 +73,14 @@
</dependencyManagement>

<dependencies>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>amazon-sqs-java-extended-client-lib</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
Expand All @@ -71,6 +89,10 @@
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
</dependency>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>s3</artifactId>
</dependency>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>sqs</artifactId>
Expand Down
37 changes: 33 additions & 4 deletions aws/sqs/java/aws-sqs/src/main/java/com/github/agebhar1/App.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package com.github.agebhar1;

import com.amazon.sqs.javamessaging.AmazonSQSExtendedClient;
import com.amazon.sqs.javamessaging.ExtendedClientConfiguration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import software.amazon.awssdk.auth.credentials.ProfileCredentialsProvider;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.s3.S3Client;
import software.amazon.awssdk.services.sqs.SqsAsyncClient;
import software.amazon.awssdk.services.sqs.SqsClient;
import software.amazon.awssdk.services.sqs.model.SqsException;
Expand All @@ -13,6 +16,8 @@
import java.time.Instant;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class App {

Expand All @@ -21,14 +26,16 @@ public class App {
private final static String Queue = "";
private final static Logger logger = LoggerFactory.getLogger(App.class);

private final static String Bucket = "";

public static void main(String[] args) throws URISyntaxException {
async(args);
largeMsg(args);
}

public static void async(String[] args) throws URISyntaxException {

final var asyncSqsClient = SqsAsyncClient.builder()
.credentialsProvider(ProfileCredentialsProvider.create(""))
.credentialsProvider(ProfileCredentialsProvider.create())
.region(Region.EU_CENTRAL_1)
.build();

Expand All @@ -41,16 +48,38 @@ public static void async(String[] args) throws URISyntaxException {
public static void sync(String[] args) throws URISyntaxException {

final var sqsClient = SqsClient.builder()
.credentialsProvider(ProfileCredentialsProvider.create(""))
.credentialsProvider(ProfileCredentialsProvider.create())
.region(Region.EU_CENTRAL_1)
.build();

var message = "Hello SQS! " + Instant.now();

sendMessage(sqsClient, new URI(Queue), message);
sendMessage(sqsClient, new URI(Queue), message + "B");
receiveMessages(sqsClient, new URI(Queue));
}

public static void largeMsg(String[] args) throws URISyntaxException {

var s3 = S3Client.builder()
.credentialsProvider(ProfileCredentialsProvider.create())
.region(Region.EU_CENTRAL_1)
.build();

final var sqsClient = SqsClient.builder()
.credentialsProvider(ProfileCredentialsProvider.create())
.region(Region.EU_CENTRAL_1)
.build();

var cfg = new ExtendedClientConfiguration()
.withPayloadSupportEnabled(s3, Bucket);
var xtd = new AmazonSQSExtendedClient(sqsClient, cfg);

var message = Stream.generate(() -> "A").limit(256 * 1024).collect(Collectors.joining());

sendMessage(xtd, new URI(Queue), message + "B");
receiveMessages(xtd, new URI(Queue));
}

private static void sendMessage(final SqsClient sqsClient, final URI queue, final String message) {
logger.info("Try to send message async to SQS: {}.", queue);
try {
Expand Down

0 comments on commit fd12d48

Please sign in to comment.