Spring Aws SQS don't connect to localstack

Viewed 1778

I'm trying to list an SQS queue using Spring AWS, but It is throwing this message exception.

2021-09-30 10:41:15.273 WARN 25992 --- [ main] i.a.c.m.l.SimpleMessageListenerContainer : Ignoring queue with name 'EVENTS_DEV': The queue does not exist.; nested exception is com.amazonaws.services.sqs.model.QueueDoesNotExistException: The specified queue EVENTS_DEV does not exist for this wsdl version. (Service: AmazonSQS; Status Code: 404; Error Code: AWS.SimpleQueueService.NonExistentQueue; Request ID: IKNNYB2ICCTDT6DXQ15RAP5JCY92NVG1H0LZK69WJWMBXZ1YIFKI; Proxy: null)

If I use was cli to get the queue attributes the queue is there

aws --endpoint http://localhost:4566 sqs get-queue-attributes --queue-url  http://localhost:4566/000000000000/EVENTS_DEV
{
    "Attributes": {
        "ApproximateNumberOfMessages": "0",
        "ApproximateNumberOfMessagesDelayed": "0",
        "ApproximateNumberOfMessagesNotVisible": "0",
        "CreatedTimestamp": "1633006230.73685",
        "DelaySeconds": "0",
        "LastModifiedTimestamp": "1633006230.73685",
        "MaximumMessageSize": "262144",
        "MessageRetentionPeriod": "345600",
        "QueueArn": "arn:aws:sqs:sa-east-1:000000000000:EVENTS_DEV",
        "ReceiveMessageWaitTimeSeconds": "0",
        "VisibilityTimeout": "30"
    }
}

Here is my listener code

@Component
public class Listener {

    @SqsListener(value = "${aws.queues.event}", deletionPolicy = SqsMessageDeletionPolicy.NEVER)
    public void listen(String message, Acknowledgment acknowledgment) throws ExecutionException, InterruptedException {
        System.out.printf("Message received %s%n", message );
        acknowledgment.acknowledge().get();
    }
}

And here is my configuration

@Configuration
public class AWSConfig {
    @Bean
    public QueueMessagingTemplate queueMessagingTemplate(AmazonSQSAsync amazonSQSAsync) {
        return new QueueMessagingTemplate(amazonSQSAsync);
    }

    @Bean
    public NotificationMessagingTemplate notificationMessagingTemplate(
            AmazonSNS amazonSNS) {
        return new NotificationMessagingTemplate(amazonSNS);
    }
}

Finally my properties file

cloud.aws.sns.endpoint=http://localhost:4566
cloud.aws.sns.region=sa-east-1
cloud.aws.sqs.endpoint=http://localhost:4566
cloud.aws.sqs.region=sa-east-1
cloud.aws.credentials.instanceProfile=false
cloud.aws.credentials.useDefaultAwsCredentialsChain=false
cloud.aws.stack.auto=false

aws.queues.event=EVENTS_DEV
1 Answers

To resolve it you should make sure that the queue was created before listener initialization.

Related