Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Caused by: java.util.concurrent.CompletionException: io.awspring.cloud.sqs.QueueAttributesResolvingException: Error resolving attributes for queue <queue_name>.fifo with strategy CREATE and queueAttributesNames [] #1283

Open
ohadab opened this issue Nov 26, 2024 · 3 comments
Labels
component: sqs SQS integration related issue status: waiting-for-feedback Waiting for feedback from issuer

Comments

@ohadab
Copy link

ohadab commented Nov 26, 2024

Type: Bug

Component:
SQS

Describe the bug
using package io.awspring.cloud:spring-cloud-aws-sqs:3.2.1
and using @SqsListener(value = "queue-messages.fifo")

i'm getting exception:
Caused by: java.util.concurrent.CompletionException: io.awspring.cloud.sqs.QueueAttributesResolvingException: Error resolving attributes for queue queue-messages.fifo with strategy CREATE and queueAttributesNames []
.....
at java.base/java.util.concurrent.CompletableFuture.completeExceptionally(CompletableFuture.java:2194)
at software.amazon.awssdk.core.internal.http.pipeline.stages.AsyncApiCallMetricCollectionStage.lambda$execute$0(AsyncApiCallMetricCollectionStage.java:56)
at java.base/java.util.concurrent.CompletableFuture.uniWhenComplete(CompletableFuture.java:863)
at java.base/java.util.concurrent.CompletableFuture$UniWhenComplete.tryFire(CompletableFuture.java:841)
at java.base/java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:510)
at java.base/java.util.concurrent.CompletableFuture.completeExceptionally(CompletableFuture.java:2194)
at software.amazon.awssdk.core.internal.http.pipeline.stages.AsyncApiCallTimeoutTrackingStage.lambda$execute$2(AsyncApiCallTimeoutTrackingStage.java:67)
.....
Caused by: software.amazon.awssdk.services.sqs.model.SqsException: The action CreateQueue is not valid for this endpoint. (Service: Sqs, Status Code: 400, Request ID: <req_id>
)
Sample
@SqsListener(queueNames = {"queue-messages.fifo"})
public void handleMessage(QueueMessageEvent event) {

@maciejwalkowiak
Copy link
Contributor

Error messages like that - either are self explanatory - or are related with your infrastructure/IAM permissions. If you believe this is in any way caused by framework, please provide a minimum sample that reproduces this issue.

@maciejwalkowiak maciejwalkowiak added the status: waiting-for-feedback Waiting for feedback from issuer label Nov 26, 2024
@ohadab
Copy link
Author

ohadab commented Nov 27, 2024

@maciejwalkowiak
I Tought i did give a good code sample. but i'll explain again

To isolate the issue, I created a minimal reproducible example using version 3.2.1 of io.awspring.cloud:spring-cloud-aws-sqs.
Despite ensuring proper IAM permissions and confirming the existence of the FIFO queue (example-queue.fifo) in the correct region, the error persists when attempting to use the @SqsListener.

Here’s the reduced code sample that reproduces the issue:
pom.xml:
<dependency> <groupId>io.awspring.cloud</groupId> <artifactId>spring-cloud-aws-sqs</artifactId> <version>3.2.1</version> </dependency>

listener class:
`import io.awspring.cloud.sqs.annotation.SqsListener;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

@service
@slf4j
public class ExampleSqsListener {

@SqsListener(value = "example-queue.fifo", acknowledgementMode = "ALWAYS")
public void handleMessage(String message) {
    log.info("Received message: {}", message);
}

}`

error i got:
Caused by: java.util.concurrent.CompletionException: io.awspring.cloud.sqs.QueueAttributesResolvingException: Error resolving attributes for queue example-queue.fifo with strategy CREATE and queueAttributesNames [] ... Caused by: software.amazon.awssdk.services.sqs.model.SqsException: The action CreateQueue is not valid for this endpoint.

The @SqsListener should connect to the specified FIFO queue (example-queue.fifo) and process messages without attempting to recreate the queue.

note when adding createQueue permission to my user it successfully connected to the existing queue (without creating a new queue)

note: I noticed that when putting full SQS url in the @SqsListener(value = "https://sqs.eu-north-1.amazonaws.com/account-id/example-queue.fifo") it does connect successfully to queue and does not try to create queue

@tomazfernandes
Copy link
Contributor

Hi @ohadab.

The only condition the framework tries to create the queue is if it gets a QueueDoesNotExistException when trying to resolve the queue name.

So, for some reason, it's not finding the queue in your setup.

If you could provide a minimal sample that reproduces the issue we could take a look at it.

You can also add a breakpoint in the QueueAttributesResolver class to try to figure out why it's not finding the queue:

private CompletableFuture<String> doResolveQueueUrl() {
GetQueueUrlRequest.Builder getQueueUrlRequestBuilder = GetQueueUrlRequest.builder();
Arn arn = getQueueArnFromUrl();
if (arn != null) {
Assert.isTrue(arn.accountId().isPresent(), "accountId is missing from arn");
getQueueUrlRequestBuilder.queueName(arn.resourceAsString()).queueOwnerAWSAccountId(arn.accountId().get());
}
else {
getQueueUrlRequestBuilder.queueName(this.queueName);
}
return CompletableFutures.exceptionallyCompose(this.sqsAsyncClient
.getQueueUrl(getQueueUrlRequestBuilder.build()).thenApply(GetQueueUrlResponse::queueUrl),
this::handleException);
}
private CompletableFuture<String> handleException(Throwable t) {
return t.getCause() instanceof QueueDoesNotExistException
&& QueueNotFoundStrategy.CREATE.equals(this.queueNotFoundStrategy)
? createQueue()
: CompletableFutures.failedFuture(t);
}

Let me know if that works for you, thanks.

@tomazfernandes tomazfernandes added the component: sqs SQS integration related issue label Jan 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: sqs SQS integration related issue status: waiting-for-feedback Waiting for feedback from issuer
Projects
None yet
Development

No branches or pull requests

3 participants