Motiva-AI / clj-sqs-extended

Client library for AWS SQS with support for large messages, up to 2GB. This is a Clojure wrapper for https://github.com/awslabs/amazon-sqs-java-extended-client-lib
MIT License
3 stars 0 forks source link

Running the former sqs-utils and the SQS Extended Library with Localstack #3

Closed ghost closed 4 years ago

ghost commented 4 years ago

To have the old sqs-utils work with Localstack, the only modification that would be necessary is to change the port where the mockup services are running to 4566

project.clj

  - :env {:sqs-endpoint "http://localhost:9324"
  + :env {:sqs-endpoint "http://localhost:4566"

To have the official working example use the Localstack mockup services, the following modifications in the source code are necessary. Except for those, no special configuration steps were required at the Localstack side.

WATCHOUT:

The S3 client needs to be constructed with specified endpoint

final AmazonS3 s3 =
  AmazonS3ClientBuilder.standard()
    .withPathStyleAccessEnabled(true)
    .withEndpointConfiguration(new EndpointConfiguration("http://localhost:4566", "ap-northeast-1"))
    .build();

The SQS client needs to be constructed in a similar way

final AmazonSQS sqsExtended =
  new AmazonSQSExtendedClient(AmazonSQSClientBuilder.standard()
    .withEndpointConfiguration(new EndpointConfiguration("http://localhost:4566/", "ap-northeast-1"))
    .build(), extendedClientConfig);

The official working example seems not to be made for running under Java 11 (javax missing there) and the above modifications also require some more AWS classes not included in the vanilla version. For this initial proof-of-concept step, the easiest way to have all those dependencies in place was to just directly add

<dependency>
  <groupId>com.amazonaws</groupId>
  <artifactId>aws-java-sdk-core</artifactId>
  <version>${aws-java-sdk.version}</version>
</dependency>
<dependency>
  <groupId>javax.xml.bind</groupId>
  <artifactId>jaxb-api</artifactId>
  <version>2.3.1</version>
</dependency>

to the pom.xml of the amazon-sqs-java-extended-client-lib repository and (re)build it with

mvn assembly:assembly -DdescriptorId=jar-with-dependencies package

The working example then runs fine with Localstack when invoked with

java -cp "amazon-sqs-java-extended-client-lib-1.0.2-jar-with-dependencies.jar" SQSExtendedClientExample.java