softwaremill / elasticmq

In-memory message queue with an Amazon SQS-compatible interface. Runs stand-alone or embedded.
https://softwaremill.com/open-source/
Apache License 2.0
2.46k stars 193 forks source link

Cannot create Queue with AWS SDK. #983

Closed adamZakar closed 2 months ago

adamZakar commented 3 months ago

Hi,

We are using aws sdk 2.0. with the following setup:

  static {
   int port = SQSRestServerBuilder.withDynamicPort().start().waitUntilStarted().localAddress().getPort();
 }
    @Bean
    public SqsClient provideSqsClient() {
        AwsCredentialsProvider credentialsProvider =
            StaticCredentialsProvider.create(AwsBasicCredentials.create("1234", "1234"));
        return SqsClient.builder()
            .credentialsProvider(credentialsProvider)
            .region(Region.US_EAST_1)
            .endpointOverride(URI.create(format("http://localhost:%d", port))).build();
    }
    @Bean
    public String provideSqsDependencyDeploymentUrl(SqsClient sqsClient) {
        return sqsClient.createQueue(builder -> builder.queueName("test")).queueUrl();
    }

It used to work but recently it's been failing with Caused by: software.amazon.awssdk.services.sqs.model.SqsException: Service returned HTTP status code 400 (Service: Sqs, Status Code: 400, Request ID: null). Any idea why it is failing?

micossow commented 3 months ago

@adamZakar are you sure that a queue test did not exist at the moment the code was running? Can you attach logs from ElasticMQ?

deepkimchi commented 2 months ago

We are encountering a similar issue. I am uncertain if this is an AWS SDK issue or Elasticmq issue. I am using the following setup for the SQS client and have started receiving a 400 error after upgrading the AWS SDK v2 version from 2.21 to 2.25.18.

        SqsAsyncClient.builder()
            .credentialsProvider(AnonymousCredentialsProvider.create())
            .overrideConfiguration(
                ClientOverrideConfiguration.builder()
                    .putHeader("Host", "localhost:9324")
                    .build()
            )
            .endpointOverride(URI("http://localhost:9324"))
            .region(Region.of("local"))
            .build()
micossow commented 2 months ago

@deepkimchi I can't reproduce the issue with the following steps:

  1. Start the latest ElasticMQ version (1.5.8) via docker:
    docker run -p 9324:9324 --rm softwaremill/elasticmq-native
  2. Setup SQS client using AWS SDK 2.25.18 using your code
  3. Create queue:
    client.createQueue(CreateQueueRequest.builder().queueName("testQueue1").build()).get()

    And it works. Any idea what's missing?

adamZakar commented 2 months ago

Only logs that's are related to ElasticMQ.

16:39:51.374 [elasticmq-akka.actor.default-dispatcher-4] INFO akka.event.slf4j.Slf4jLogger - Slf4jLogger started 16:39:51.878 [elasticmq-akka.actor.default-dispatcher-4] INFO o.e.rest.sqs.TheSQSRestServerBuilder - Started SQS rest server, bind address :60435, visible server address http://localhost:60435

We use the in memory version of it. Can you try to initiate the client the way we did it?

We are using this version of elastic mq: https://mvnrepository.com/artifact/org.elasticmq/elasticmq-server_2.13/1.2.1 we are using the latest version of AWS SDK 2.0

micossow commented 2 months ago

Version 1.2.1 does not support AWS SDK 2.0. Please upgrade to latest.

adamZakar commented 2 months ago

It solved the issue thanks. closing the ticket.