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

Error resolving attributes for queue with strategy CREATE and queueAttributesNames #1022

Closed
Divyrajput123 opened this issue Jan 17, 2024 · 20 comments
Labels
component: sqs SQS integration related issue status: waiting-for-feedback Waiting for feedback from issuer

Comments

@Divyrajput123
Copy link

I am trying to run my spring boot 3.0.8 application in local, while running the app is failing with following reason
Caused by: java.util.concurrent.CompletionException: io.awspring.cloud.sqs.QueueAttributesResolvingException: Error resolving attributes for queue myqueue with strategy CREATE and queueAttributesNames []

@SqsListener(value = "myqueue")
public void mylistener(@Payload String payload, @Headers Map<String, Object> headers) {

}

I am using the below dependencies,
implementation platform("io.awspring.cloud:spring-cloud-aws-dependencies:3.0.1")
implementation 'io.awspring.cloud:spring-cloud-aws-starter-sqs'
implementation 'io.awspring.cloud:spring-cloud-aws-starter-sns'

@ilveann
Copy link

ilveann commented Jan 20, 2024

Hi @Divyrajput123

At first, if you do not need to create sqs\sns automatically you can create the template like this with QueueNotFoundStrategy.FAIL:

@Bean
    public SqsTemplate sqsTemplate(SqsAsyncClient sqsAsyncClient) {
        return SqsTemplate.builder()
                .sqsAsyncClient(sqsAsyncClient)
                .configure(o -> o.queueNotFoundStrategy(QueueNotFoundStrategy.FAIL))
                .build();
    }

I had the same error with the same version of aws libraries, and after debugging I realized that it was an auth error, but QueueAttributesResolvingException intercepts it.

Try to test it with a localstack and provide just one credential provider, for example like this:

@Bean
    SqsAsyncClient sqsAsyncClient(SqsProperties properties) {
        return SqsAsyncClient.builder()
                .credentialsProvider(EnvironmentVariableCredentialsProvider.create())
                .region(Region.of(properties.getRegion()))
                .endpointOverride(URI.create(properties.getEndpoint()))
                .build();
    }

Credential env variables should be provided for application before lunch:
AWS_ACCESS_KEY_ID=test
AWS_SECRET_ACCESS_KEY=test

SQS should be created before as well:
aws sqs create-queue --queue-name sqs-local.fifo --attributes FifoQueue=true --endpoint-url http://localhost:4566/ --region=eu-west-1

In case the same error appears try to debug EnvironmentVariableCredentialsProvider and make sure that envs in place and the localstak url is correct.

@tomazfernandes
Copy link
Contributor

@Divyrajput123 , can you share the full stacktrace of the issue?

Thanks.

@tomazfernandes tomazfernandes added component: sqs SQS integration related issue status: waiting-for-feedback Waiting for feedback from issuer labels Jan 28, 2024
@tomazfernandes
Copy link
Contributor

@Divyrajput123 , I'll close this issue due to lack of feedback.

This is probably related to an issue when auto creating FIFO queues that has already been fixed but since I don't have a stack trace or more info I can't guarantee.

We can reopen if necessary.

@webranch-pl
Copy link

Yeah, there is still a problem with fifo queue and CREATE strategy...

@webranch-pl
Copy link

webranch-pl commented Mar 19, 2024

In version 3.1.1 I have problem with standard and fifo queue. :/ In version 3.1.0 it works but only for standard queue.

org.springframework.context.ApplicationContextException: Failed to start bean 'io.awspring.cloud.messaging.internalEndpointRegistryBeanName'
	at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:291) ~[spring-context-6.1.4.jar:6.1.4]
	at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:471) ~[spring-context-6.1.4.jar:6.1.4]
	at java.base/java.lang.Iterable.forEach(Iterable.java:75) ~[na:na]
	at org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:260) ~[spring-context-6.1.4.jar:6.1.4]
	at org.springframework.context.support.DefaultLifecycleProcessor.onRefresh(DefaultLifecycleProcessor.java:205) ~[spring-context-6.1.4.jar:6.1.4]
	at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:978) ~[spring-context-6.1.4.jar:6.1.4]
	at org.springframework.context.support.AbstractApplicationContext.__refresh(AbstractApplicationContext.java:627) ~[spring-context-6.1.4.jar:6.1.4]
	at org.springframework.context.support.AbstractApplicationContext.jrLockAndRefresh(AbstractApplicationContext.java:41002) ~[spring-context-6.1.4.jar:6.1.4]
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:42008) ~[spring-context-6.1.4.jar:6.1.4]
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:146) ~[spring-boot-3.2.3.jar:3.2.3]
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:754) ~[spring-boot-3.2.3.jar:3.2.3]
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:456) ~[spring-boot-3.2.3.jar:3.2.3]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:334) ~[spring-boot-3.2.3.jar:3.2.3]
	at org.springframework.boot.builder.SpringApplicationBuilder.run(SpringApplicationBuilder.java:149) ~[spring-boot-3.2.3.jar:3.2.3]
	at x.main(CmsApplication.java:15) ~[classes/:na]
Caused by: java.util.concurrent.CompletionException: io.awspring.cloud.sqs.QueueAttributesResolvingException: Error resolving attributes for queue queue-wonderful-hamilton-2.fifo with strategy CREATE and queueAttributesNames []
	at java.base/java.util.concurrent.CompletableFuture.encodeRelay(CompletableFuture.java:368) ~[na:na]
	at java.base/java.util.concurrent.CompletableFuture.completeRelay(CompletableFuture.java:377) ~[na:na]
	at java.base/java.util.concurrent.CompletableFuture$UniCompose.tryFire(CompletableFuture.java:1152) ~[na:na]
	at java.base/java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:510) ~[na:na]
	at java.base/java.util.concurrent.CompletableFuture.completeExceptionally(CompletableFuture.java:2162) ~[na:na]
	at software.amazon.awssdk.utils.CompletableFutureUtils.lambda$forwardExceptionTo$0(CompletableFutureUtils.java:79) ~[utils-2.21.46.jar:na]
	at java.base/java.util.concurrent.CompletableFuture.uniWhenComplete(CompletableFuture.java:863) ~[na:na]
	at java.base/java.util.concurrent.CompletableFuture$UniWhenComplete.tryFire(CompletableFuture.java:841) ~[na:na]
	at java.base/java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:510) ~[na:na]
	at java.base/java.util.concurrent.CompletableFuture.completeExceptionally(CompletableFuture.java:2162) ~[na:na]
	at software.amazon.awssdk.core.internal.http.pipeline.stages.AsyncApiCallMetricCollectionStage.lambda$execute$0(AsyncApiCallMetricCollectionStage.java:56) ~[sdk-core-2.21.46.jar:na]
	at java.base/java.util.concurrent.CompletableFuture.uniWhenComplete(CompletableFuture.java:863) ~[na:na]
	at java.base/java.util.concurrent.CompletableFuture$UniWhenComplete.tryFire(CompletableFuture.java:841) ~[na:na]
	at java.base/java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:510) ~[na:na]
	at java.base/java.util.concurrent.CompletableFuture.completeExceptionally(CompletableFuture.java:2162) ~[na:na]
	at software.amazon.awssdk.core.internal.http.pipeline.stages.AsyncApiCallTimeoutTrackingStage.lambda$execute$2(AsyncApiCallTimeoutTrackingStage.java:67) ~[sdk-core-2.21.46.jar:na]
	at java.base/java.util.concurrent.CompletableFuture.uniWhenComplete(CompletableFuture.java:863) ~[na:na]
	at java.base/java.util.concurrent.CompletableFuture$UniWhenComplete.tryFire(CompletableFuture.java:841) ~[na:na]
	at java.base/java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:510) ~[na:na]
	at java.base/java.util.concurrent.CompletableFuture.completeExceptionally(CompletableFuture.java:2162) ~[na:na]
	at software.amazon.awssdk.utils.CompletableFutureUtils.lambda$forwardExceptionTo$0(CompletableFutureUtils.java:79) ~[utils-2.21.46.jar:na]
	at java.base/java.util.concurrent.CompletableFuture.uniWhenComplete(CompletableFuture.java:863) ~[na:na]
	at java.base/java.util.concurrent.CompletableFuture$UniWhenComplete.tryFire(CompletableFuture.java:841) ~[na:na]
	at java.base/java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:510) ~[na:na]
	at java.base/java.util.concurrent.CompletableFuture.completeExceptionally(CompletableFuture.java:2162) ~[na:na]
	at software.amazon.awssdk.core.internal.http.pipeline.stages.AsyncRetryableStage$RetryingExecutor.maybeAttemptExecute(AsyncRetryableStage.java:103) ~[sdk-core-2.21.46.jar:na]
	at software.amazon.awssdk.core.internal.http.pipeline.stages.AsyncRetryableStage$RetryingExecutor.maybeRetryExecute(AsyncRetryableStage.java:184) ~[sdk-core-2.21.46.jar:na]
	at software.amazon.awssdk.core.internal.http.pipeline.stages.AsyncRetryableStage$RetryingExecutor.lambda$attemptExecute$1(AsyncRetryableStage.java:170) ~[sdk-core-2.21.46.jar:na]
	at java.base/java.util.concurrent.CompletableFuture.uniWhenComplete(CompletableFuture.java:863) ~[na:na]
	at java.base/java.util.concurrent.CompletableFuture$UniWhenComplete.tryFire(CompletableFuture.java:841) ~[na:na]
	at java.base/java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:510) ~[na:na]
	at java.base/java.util.concurrent.CompletableFuture.complete(CompletableFuture.java:2147) ~[na:na]
	at software.amazon.awssdk.core.internal.http.pipeline.stages.MakeAsyncHttpRequestStage.lambda$execute$0(MakeAsyncHttpRequestStage.java:110) ~[sdk-core-2.21.46.jar:na]
	at java.base/java.util.concurrent.CompletableFuture.uniWhenComplete(CompletableFuture.java:863) ~[na:na]
	at java.base/java.util.concurrent.CompletableFuture$UniWhenComplete.tryFire(CompletableFuture.java:841) ~[na:na]
	at java.base/java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:510) ~[na:na]
	at java.base/java.util.concurrent.CompletableFuture.complete(CompletableFuture.java:2147) ~[na:na]
	at software.amazon.awssdk.core.internal.http.pipeline.stages.MakeAsyncHttpRequestStage.completeResponseFuture(MakeAsyncHttpRequestStage.java:253) ~[sdk-core-2.21.46.jar:na]
	at software.amazon.awssdk.core.internal.http.pipeline.stages.MakeAsyncHttpRequestStage.lambda$executeHttpRequest$3(MakeAsyncHttpRequestStage.java:167) ~[sdk-core-2.21.46.jar:na]
	at java.base/java.util.concurrent.CompletableFuture.uniHandle(CompletableFuture.java:934) ~[na:na]
	at java.base/java.util.concurrent.CompletableFuture$UniHandle.tryFire(CompletableFuture.java:911) ~[na:na]
	at java.base/java.util.concurrent.CompletableFuture$Completion.run(CompletableFuture.java:482) ~[na:na]
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136) ~[na:na]
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635) ~[na:na]
	at java.base/java.lang.Thread.run(Thread.java:833) ~[na:na]
Caused by: io.awspring.cloud.sqs.QueueAttributesResolvingException: Error resolving attributes for queue queue-wonderful-hamilton-2.fifo with strategy CREATE and queueAttributesNames []
	at io.awspring.cloud.sqs.QueueAttributesResolver.wrapException(QueueAttributesResolver.java:90) ~[spring-cloud-aws-sqs-3.1.1.jar:3.1.1]
	at java.base/java.util.concurrent.CompletableFuture.uniExceptionally(CompletableFuture.java:990) ~[na:na]
	at java.base/java.util.concurrent.CompletableFuture$UniExceptionally.tryFire(CompletableFuture.java:974) ~[na:na]
	... 42 common frames omitted
Caused by: software.amazon.awssdk.services.sqs.model.SqsException: Service returned HTTP status code 307 (Service: Sqs, Status Code: 307, Request ID: null)
	at software.amazon.awssdk.services.sqs.model.SqsException$BuilderImpl.build(SqsException.java:104) ~[sqs-2.21.46.jar:na]
	at software.amazon.awssdk.services.sqs.model.SqsException$BuilderImpl.build(SqsException.java:58) ~[sqs-2.21.46.jar:na]
	at software.amazon.awssdk.protocols.json.internal.unmarshall.AwsJsonProtocolErrorUnmarshaller.unmarshall(AwsJsonProtocolErrorUnmarshaller.java:92) ~[aws-json-protocol-2.21.46.jar:na]
	at software.amazon.awssdk.protocols.json.internal.unmarshall.AwsJsonProtocolErrorUnmarshaller.handle(AwsJsonProtocolErrorUnmarshaller.java:66) ~[aws-json-protocol-2.21.46.jar:na]
	at software.amazon.awssdk.protocols.json.internal.unmarshall.AwsJsonProtocolErrorUnmarshaller.handle(AwsJsonProtocolErrorUnmarshaller.java:41) ~[aws-json-protocol-2.21.46.jar:na]
	at software.amazon.awssdk.core.http.MetricCollectingHttpResponseHandler.lambda$handle$0(MetricCollectingHttpResponseHandler.java:52) ~[sdk-core-2.21.46.jar:na]
	at software.amazon.awssdk.core.internal.util.MetricUtils.measureDurationUnsafe(MetricUtils.java:99) ~[sdk-core-2.21.46.jar:na]
	at software.amazon.awssdk.core.internal.util.MetricUtils.measureDurationUnsafe(MetricUtils.java:92) ~[sdk-core-2.21.46.jar:na]
	at software.amazon.awssdk.core.http.MetricCollectingHttpResponseHandler.handle(MetricCollectingHttpResponseHandler.java:52) ~[sdk-core-2.21.46.jar:na]
	at software.amazon.awssdk.core.internal.http.async.AsyncResponseHandler.lambda$prepare$0(AsyncResponseHandler.java:92) ~[sdk-core-2.21.46.jar:na]
	at java.base/java.util.concurrent.CompletableFuture$UniCompose.tryFire(CompletableFuture.java:1150) ~[na:na]
	at java.base/java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:510) ~[na:na]
	at java.base/java.util.concurrent.CompletableFuture.complete(CompletableFuture.java:2147) ~[na:na]
	at software.amazon.awssdk.core.internal.http.async.AsyncResponseHandler$BaosSubscriber.onComplete(AsyncResponseHandler.java:135) ~[sdk-core-2.21.46.jar:na]
	at software.amazon.awssdk.core.internal.metrics.BytesReadTrackingPublisher$BytesReadTracker.onComplete(BytesReadTrackingPublisher.java:74) ~[sdk-core-2.21.46.jar:na]
	at software.amazon.awssdk.http.nio.netty.internal.ResponseHandler$DataCountingPublisher$1.onComplete(ResponseHandler.java:519) ~[netty-nio-client-2.21.46.jar:na]
	at software.amazon.awssdk.http.nio.netty.internal.ResponseHandler$FullResponseContentPublisher$1.request(ResponseHandler.java:454) ~[netty-nio-client-2.21.46.jar:na]
	at software.amazon.awssdk.core.internal.http.async.AsyncResponseHandler$BaosSubscriber.onSubscribe(AsyncResponseHandler.java:113) ~[sdk-core-2.21.46.jar:na]
	at software.amazon.awssdk.core.internal.metrics.BytesReadTrackingPublisher$BytesReadTracker.onSubscribe(BytesReadTrackingPublisher.java:58) ~[sdk-core-2.21.46.jar:na]
	at software.amazon.awssdk.http.nio.netty.internal.ResponseHandler$DataCountingPublisher$1.onSubscribe(ResponseHandler.java:498) ~[netty-nio-client-2.21.46.jar:na]
	at software.amazon.awssdk.http.nio.netty.internal.ResponseHandler$FullResponseContentPublisher.subscribe(ResponseHandler.java:443) ~[netty-nio-client-2.21.46.jar:na]
	at software.amazon.awssdk.http.nio.netty.internal.ResponseHandler$DataCountingPublisher.subscribe(ResponseHandler.java:495) ~[netty-nio-client-2.21.46.jar:na]
	at software.amazon.awssdk.core.internal.metrics.BytesReadTrackingPublisher.subscribe(BytesReadTrackingPublisher.java:40) ~[sdk-core-2.21.46.jar:na]
	at software.amazon.awssdk.core.internal.http.async.AsyncResponseHandler.onStream(AsyncResponseHandler.java:71) ~[sdk-core-2.21.46.jar:na]
	at software.amazon.awssdk.core.internal.http.async.CombinedResponseAsyncHttpResponseHandler.onStream(CombinedResponseAsyncHttpResponseHandler.java:88) ~[sdk-core-2.21.46.jar:na]
	at software.amazon.awssdk.core.internal.http.async.AsyncAfterTransmissionInterceptorCallingResponseHandler.onStream(AsyncAfterTransmissionInterceptorCallingResponseHandler.java:86) ~[sdk-core-2.21.46.jar:na]
	at software.amazon.awssdk.core.internal.http.async.FilterTransformingAsyncHttpResponseHandler.onStream(FilterTransformingAsyncHttpResponseHandler.java:49) ~[sdk-core-2.21.46.jar:na]
	at software.amazon.awssdk.core.internal.http.pipeline.stages.MakeAsyncHttpRequestStage$ReadMetricsTrackingResponseHandler.onStream(MakeAsyncHttpRequestStage.java:313) ~[sdk-core-2.21.46.jar:na]
	at software.amazon.awssdk.http.nio.netty.internal.ResponseHandler.channelRead0(ResponseHandler.java:122) ~[netty-nio-client-2.21.46.jar:na]
	at software.amazon.awssdk.http.nio.netty.internal.ResponseHandler.channelRead0(ResponseHandler.java:75) ~[netty-nio-client-2.21.46.jar:na]
	at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:99) ~[netty-transport-4.1.107.Final.jar:4.1.107.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:444) ~[netty-transport-4.1.107.Final.jar:4.1.107.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420) ~[netty-transport-4.1.107.Final.jar:4.1.107.Final]
	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412) ~[netty-transport-4.1.107.Final.jar:4.1.107.Final]
	at software.amazon.awssdk.http.nio.netty.internal.nrs.HttpStreamsHandler.channelRead(HttpStreamsHandler.java:167) ~[netty-nio-client-2.21.46.jar:na]
	at software.amazon.awssdk.http.nio.netty.internal.nrs.HttpStreamsClientHandler.channelRead(HttpStreamsClientHandler.java:173) ~[netty-nio-client-2.21.46.jar:na]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:442) ~[netty-transport-4.1.107.Final.jar:4.1.107.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420) ~[netty-transport-4.1.107.Final.jar:4.1.107.Final]
	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412) ~[netty-transport-4.1.107.Final.jar:4.1.107.Final]
	at io.netty.handler.logging.LoggingHandler.channelRead(LoggingHandler.java:280) ~[netty-handler-4.1.107.Final.jar:4.1.107.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:442) ~[netty-transport-4.1.107.Final.jar:4.1.107.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420) ~[netty-transport-4.1.107.Final.jar:4.1.107.Final]
	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412) ~[netty-transport-4.1.107.Final.jar:4.1.107.Final]
	at io.netty.handler.timeout.IdleStateHandler.channelRead(IdleStateHandler.java:289) ~[netty-handler-4.1.107.Final.jar:4.1.107.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:442) ~[netty-transport-4.1.107.Final.jar:4.1.107.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420) ~[netty-transport-4.1.107.Final.jar:4.1.107.Final]
	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412) ~[netty-transport-4.1.107.Final.jar:4.1.107.Final]
	at io.netty.channel.CombinedChannelDuplexHandler$DelegatingChannelHandlerContext.fireChannelRead(CombinedChannelDuplexHandler.java:436) ~[netty-transport-4.1.107.Final.jar:4.1.107.Final]
	at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:346) ~[netty-codec-4.1.107.Final.jar:4.1.107.Final]
	at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:318) ~[netty-codec-4.1.107.Final.jar:4.1.107.Final]
	at io.netty.channel.CombinedChannelDuplexHandler.channelRead(CombinedChannelDuplexHandler.java:251) ~[netty-transport-4.1.107.Final.jar:4.1.107.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:442) ~[netty-transport-4.1.107.Final.jar:4.1.107.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420) ~[netty-transport-4.1.107.Final.jar:4.1.107.Final]
	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412) ~[netty-transport-4.1.107.Final.jar:4.1.107.Final]
	at io.netty.handler.ssl.SslHandler.unwrap(SslHandler.java:1475) ~[netty-handler-4.1.107.Final.jar:4.1.107.Final]
	at io.netty.handler.ssl.SslHandler.decodeJdkCompatible(SslHandler.java:1338) ~[netty-handler-4.1.107.Final.jar:4.1.107.Final]
	at io.netty.handler.ssl.SslHandler.decode(SslHandler.java:1387) ~[netty-handler-4.1.107.Final.jar:4.1.107.Final]
	at io.netty.handler.codec.ByteToMessageDecoder.decodeRemovalReentryProtection(ByteToMessageDecoder.java:529) ~[netty-codec-4.1.107.Final.jar:4.1.107.Final]
	at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:468) ~[netty-codec-4.1.107.Final.jar:4.1.107.Final]
	at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:290) ~[netty-codec-4.1.107.Final.jar:4.1.107.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:444) ~[netty-transport-4.1.107.Final.jar:4.1.107.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420) ~[netty-transport-4.1.107.Final.jar:4.1.107.Final]
	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412) ~[netty-transport-4.1.107.Final.jar:4.1.107.Final]
	at io.netty.handler.timeout.IdleStateHandler.channelRead(IdleStateHandler.java:289) ~[netty-handler-4.1.107.Final.jar:4.1.107.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:442) ~[netty-transport-4.1.107.Final.jar:4.1.107.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420) ~[netty-transport-4.1.107.Final.jar:4.1.107.Final]
	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412) ~[netty-transport-4.1.107.Final.jar:4.1.107.Final]
	at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410) ~[netty-transport-4.1.107.Final.jar:4.1.107.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:440) ~[netty-transport-4.1.107.Final.jar:4.1.107.Final]
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420) ~[netty-transport-4.1.107.Final.jar:4.1.107.Final]
	at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919) ~[netty-transport-4.1.107.Final.jar:4.1.107.Final]
	at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:166) ~[netty-transport-4.1.107.Final.jar:4.1.107.Final]
	at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:788) ~[netty-transport-4.1.107.Final.jar:4.1.107.Final]
	at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:724) ~[netty-transport-4.1.107.Final.jar:4.1.107.Final]
	at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:650) ~[netty-transport-4.1.107.Final.jar:4.1.107.Final]
	at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:562) ~[netty-transport-4.1.107.Final.jar:4.1.107.Final]
	at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997) ~[netty-common-4.1.107.Final.jar:4.1.107.Final]
	at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) ~[netty-common-4.1.107.Final.jar:4.1.107.Final]
	... 1 common frames omitted

My code looks like:

@Bean
    public SqsAsyncClient sqsAsyncClient(QueueIntegrationProperties queueProps) {
        return SqsAsyncClient.builder()
		.credentialsProvider(StaticCredentialsProvider.create(AwsBasicCredentials.create(authUsername, authPassword)))
		.endpointOverride(URI.create(endpointOverride))
		.region(Region.of(regionCode)).build();
    }

    @Bean
    public SqsTemplate sqsTemplate(SqsAsyncClient sqsAsyncClient) {
        return SqsTemplate.builder()
                .sqsAsyncClient(sqsAsyncClient)
                .build();
    }
	
	@SqsListener("queue-wonderful-hamilton")
    public void signupEventHandler(SignupEvent event) {
        log.info("Event received: {}", event);
    }

@tomazfernandes
Copy link
Contributor

Hmm, that's weird.

The only resource I could find for Http Status 307 on AWS was this one for S3, which points to a resource being created in a region and accessed from another region before it propagates in 24h: https://repost.aws/knowledge-center/s3-http-307-response

Rings any bells?

If you can create a sample project that reproduces the issue I'd be happy to take a look.

@webranch-pl
Copy link

It is definitely wird in this case. ;) But like I said, I've only changed the vesrion of spring-cloud-aws and experimenting with .fifo suffix. Sometimes it works, sometimes not. I will check it on clean AWS resources, because I am using Scaleway, so maybe here is problem...? I will let you know, thanks!

@ahileseverquote
Copy link

Hitting this same issue, too - looks specific to fifo queues.

@tomazfernandes
Copy link
Contributor

Hey @ahileseverquote, did you try it in 3.1.1?

@tomazfernandes
Copy link
Contributor

Hey @webranch-pl, can you send me the link to the open issues about this you mentioned?

It would also be helpful if you would be able to create a sample project that reproduces the issue with minimal code as I asked.

Keep in mind this is a community project, none of us are paid to be here looking into these issues :)

@webranch-pl
Copy link

@tomazfernandes, I confirmed that problem was due to using Scaleway more than AWS and I think it is already resolved in version 3.1.1. Thank you for your assist! I am going to continue testing yuor project! Great work! ;)

@tomazfernandes
Copy link
Contributor

Awesome news @webranch-pl, thanks for looking into this and reporting back.

If anyone else still has any issues after upgrading to 3.1.1 please let me know.

@FlxGschlr
Copy link

FlxGschlr commented Mar 21, 2024

I had a similar issue with 3.1.1 because of an old version of the docker image localstack/localstack (we use localstack in our integration tests). It worked with 3.1.0 but didn't with 3.1.1. Just an FYI, maybe this helps someone.

@abhimanyuPatil
Copy link

I am facing same issue.
In .aws/config, I have set

[profile localstack]

region=us-east-1
output=json
endpoint_url = http://localhost:4566

and In .aws/credentials, I have

[localstack]
aws_access_key_id=test
aws_secret_access_key=test

Here is the error
Caused by: io.awspring.cloud.sqs.QueueAttributesResolvingException: Error resolving attributes for queue http://sqs.us-east-1.localhost.localstack.cloud:4566/000000000000/merchant-upload.fifo with strategy CREATE and queueAttributesNames [ContentBasedDeduplication] Caused by: software.amazon.awssdk.core.exception.SdkClientException: Unable to load credentials from system settings. Access key must be specified either via environment variable (AWS_ACCESS_KEY_ID) or system property (aws.accessKeyId).

Here is my SqsClientConfig

@Configuration
public class SQSClientConfiguration {
    @Bean
    public SqsAsyncClient sqsAsyncClient() {
        return SqsAsyncClient.builder()
            .credentialsProvider(EnvironmentVariableCredentialsProvider.create())
            .region(Region.of("us-east-1"))
            .endpointOverride(URI.create("http://sqs.us-east-1.localhost.localstack.cloud:4566/000000000000/merchant-upload.fifo"))
            .build();
    }
}

@maciejwalkowiak
Copy link
Contributor

@abhimanyuPatil this is a different issue. In your case, SDK is not able to resolve credentials. Since you're using EnvironmentVariableCredentialsProvider, it expects environment variables. I recommend looking into official AWS SDK v2 for Java docs or Spring Cloud AWS#Credentials docs in case you decide to use auto-configured client.

@rddch
Copy link

rddch commented May 30, 2024

Hello! Could you help me resolve this issue

I use image: localstack/localstack:3.4.0
and spring-cloud-aws.version 3.1.1

I've created 2 pairs of queue

"http://sqs.eu-west-2.localhost.localstack.cloud:4566/000000000000/stag-offline-payments-service-sms-forwardings.fifo",
"http://sqs.eu-west-2.localhost.localstack.cloud:4566/000000000000/stage-offlien-payments-service-sms-responses.fifo",
"http://sqs.eu-west-2.localhost.localstack.cloud:4566/000000000000/stag-offline-payments-service-sms-forwardings",
"http://sqs.eu-west-2.localhost.localstack.cloud:4566/000000000000/stage-offlien-payments-service-sms-responses"

when I try ti start docker-compose file with my app I'm getting

Caused by: java.util.concurrent.CompletionException: io.awspring.cloud.sqs.QueueAttributesResolvingException: Error resolving attributes for queue stage-offlien-payments-service-sms-responses with strategy CREATE and queueAttributesNames []
2024-05-30T21:34:26.850543001Z at java.util.concurrent.CompletableFuture.encodeRelay(Unknown Source) ~[?:?]
2024-05-30T21:34:26.850545126Z at java.util.concurrent.CompletableFuture.completeRelay(Unknown Source) ~[?:?]
2024-05-30T21:34:26.850547043Z at java.util.concurrent.CompletableFuture$UniCompose.tryFire(Unknown Source) ~[?:?]
2024-05-30T21:34:26.850549043Z at java.util.concurrent.CompletableFuture.postComplete(Unknown Source) ~[?:?]
2024-05-30T21:34:26.850550959Z at java.util.concurrent.CompletableFuture.completeExceptionally(Unknown Source) ~[?:?]
2024-05-30T21:34:26.850552751Z at software.amazon.awssdk.utils.CompletableFutureUtils.lambda$forwardExceptionTo$0(CompletableFutureUtils.java:79) ~[utils-2.20.63.jar!/:?]
2024-05-30T21:34:26.850554709Z at java.util.concurrent.CompletableFuture.uniWhenComplete(Unknown Source) ~[?:?]
2024-05-30T21:34:26.850556709Z at java.util.concurrent.CompletableFuture$UniWhenComplete.tryFire(Unknown Source) ~[?:?]
2024-05-30T21:34:26.850561709Z at java.util.concurrent.CompletableFuture.postComplete(Unknown Source) ~[?:?]
2024-05-30T21:34:26.850563834Z at java.util.concurrent.CompletableFuture.completeExceptionally(Unknown Source) ~[?:?]
2024-05-30T21:34:26.850566459Z at software.amazon.awssdk.core.internal.http.pipeline.stages.AsyncApiCallMetricCollectionStage.lambda$execute$0(AsyncApiCallMetricCollectionStage.java:54) ~[sdk-core-2.20.63.jar!/:?]
2024-05-30T21:34:26.850618709Z at java.util.concurrent.CompletableFuture.uniWhenComplete(Unknown Source) ~[?:?]
2024-05-30T21:34:26.850633209Z at java.util.concurrent.CompletableFuture$UniWhenComplete.tryFire(Unknown Source) ~[?:?]
2024-05-30T21:34:26.850635501Z at java.util.concurrent.CompletableFuture.postComplete(Unknown Source) ~[?:?]
2024-05-30T21:34:26.850637501Z at java.util.concurrent.CompletableFuture.completeExceptionally(Unknown Source) ~[?:?]
2024-05-30T21:34:26.850639626Z at software.amazon.awssdk.core.internal.http.pipeline.stages.AsyncApiCallTimeoutTrackingStage.lambda$execute$2(AsyncApiCallTimeoutTrackingStage.java:67) ~[sdk-core-2.20.63.jar!/:?]
2024-05-30T21:34:26.850641876Z at java.util.concurrent.CompletableFuture.uniWhenComplete(Unknown Source) ~[?:?]
2024-05-30T21:34:26.850643709Z at java.util.concurrent.CompletableFuture$UniWhenComplete.tryFire(Unknown Source) ~[?:?]
2024-05-30T21:34:26.850645668Z at java.util.concurrent.CompletableFuture.postComplete(Unknown Source) ~[?:?]
2024-05-30T21:34:26.850647626Z at java.util.concurrent.CompletableFuture.completeExceptionally(Unknown Source) ~[?:?]
2024-05-30T21:34:26.850649626Z at software.amazon.awssdk.utils.CompletableFutureUtils.lambda$forwardExceptionTo$0(CompletableFutureUtils.java:79) ~[utils-2.20.63.jar!/:?]
2024-05-30T21:34:26.850651709Z at java.util.concurrent.CompletableFuture.uniWhenComplete(Unknown Source) ~[?:?]
2024-05-30T21:34:26.850653668Z at java.util.concurrent.CompletableFuture$UniWhenComplete.tryFire(Unknown Source) ~[?:?]
2024-05-30T21:34:26.850655626Z at java.util.concurrent.CompletableFuture.postComplete(Unknown Source) ~[?:?]
2024-05-30T21:34:26.850657584Z at java.util.concurrent.CompletableFuture.completeExceptionally(Unknown Source) ~[?:?]
2024-05-30T21:34:26.850659709Z at software.amazon.awssdk.core.internal.http.pipeline.stages.AsyncRetryableStage$RetryingExecutor.maybeAttemptExecute(AsyncRetryableStage.java:103) ~[sdk-core-2.20.63.jar!/:?]
2024-05-30T21:34:26.850661793Z at software.amazon.awssdk.core.internal.http.pipeline.stages.AsyncRetryableStage$RetryingExecutor.maybeRetryExecute(AsyncRetryableStage.java:184) ~[sdk-core-2.20.63.jar!/:?]
2024-05-30T21:34:26.850663918Z at software.amazon.awssdk.core.internal.http.pipeline.stages.AsyncRetryableStage$RetryingExecutor.lambda$attemptExecute$1(AsyncRetryableStage.java:159) ~[sdk-core-2.20.63.jar!/:?]
2024-05-30T21:34:26.850666001Z at java.util.concurrent.CompletableFuture.uniWhenComplete(Unknown Source) ~[?:?]
2024-05-30T21:34:26.850667918Z at java.util.concurrent.CompletableFuture$UniWhenComplete.tryFire(Unknown Source) ~[?:?]
2024-05-30T21:34:26.850673376Z at java.util.concurrent.CompletableFuture.postComplete(Unknown Source) ~[?:?]
2024-05-30T21:34:26.850701918Z at java.util.concurrent.CompletableFuture.completeExceptionally(Unknown Source) ~[?:?]
2024-05-30T21:34:26.850705334Z at software.amazon.awssdk.utils.CompletableFutureUtils.lambda$forwardExceptionTo$0(CompletableFutureUtils.java:79) ~[utils-2.20.63.jar!/:?]
2024-05-30T21:34:26.850707418Z at java.util.concurrent.CompletableFuture.uniWhenComplete(Unknown Source) ~[?:?]
2024-05-30T21:34:26.850715334Z at java.util.concurrent.CompletableFuture$UniWhenComplete.tryFire(Unknown Source) ~[?:?]
2024-05-30T21:34:26.850717709Z at java.util.concurrent.CompletableFuture.postComplete(Unknown Source) ~[?:?]
2024-05-30T21:34:26.850719501Z at java.util.concurrent.CompletableFuture.completeExceptionally(Unknown Source) ~[?:?]
2024-05-30T21:34:26.850721459Z at software.amazon.awssdk.core.internal.http.pipeline.stages.MakeAsyncHttpRequestStage.lambda$null$0(MakeAsyncHttpRequestStage.java:103) ~[sdk-core-2.20.63.jar!/:?]
2024-05-30T21:34:26.850723501Z at java.util.concurrent.CompletableFuture.uniWhenComplete(Unknown Source) ~[?:?]
2024-05-30T21:34:26.850725501Z at java.util.concurrent.CompletableFuture$UniWhenComplete.tryFire(Unknown Source) ~[?:?]
2024-05-30T21:34:26.850727459Z at java.util.concurrent.CompletableFuture.postComplete(Unknown Source) ~[?:?]
2024-05-30T21:34:26.850729418Z at java.util.concurrent.CompletableFuture.completeExceptionally(Unknown Source) ~[?:?]
2024-05-30T21:34:26.850731376Z at software.amazon.awssdk.core.internal.http.pipeline.stages.MakeAsyncHttpRequestStage.lambda$executeHttpRequest$3(MakeAsyncHttpRequestStage.java:165) ~[sdk-core-2.20.63.jar!/:?]
2024-05-30T21:34:26.850733501Z at java.util.concurrent.CompletableFuture.uniWhenComplete(Unknown Source) ~[?:?]
2024-05-30T21:34:26.850735418Z at java.util.concurrent.CompletableFuture$UniWhenComplete.tryFire(Unknown Source) ~[?:?]
2024-05-30T21:34:26.850737376Z at java.util.concurrent.CompletableFuture$Completion.run(Unknown Source) ~[?:?]
2024-05-30T21:34:26.850739293Z at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) ~[?:?]
2024-05-30T21:34:26.850742251Z at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) ~[?:?]
2024-05-30T21:34:26.850744501Z at java.lang.Thread.run(Unknown Source) ~[?:?]
2024-05-30T21:34:26.850746459Z C

@nilesh-chordia
Copy link

nilesh-chordia commented Aug 8, 2024

@rddch , same issue I am facing, is it resolved for you ??

@shirishreseaugroup
Copy link

I am also facing the same issue

@maciejwalkowiak
Copy link
Contributor

@shirishreseaugroup @nilesh-chordia @rddch can you provide a sample that reproduces this issue?

@SHM157
Copy link

SHM157 commented Oct 13, 2024

I have the same issue after upgrading to Spring Boot 3.2.2
The issue I faced when trying to make an integration test

This is the stack trace

at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:180)
	at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:130)
	at org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener.postProcessFields(MockitoTestExecutionListener.java:110)
	at org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener.injectFields(MockitoTestExecutionListener.java:94)
	at org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener.prepareTestInstance(MockitoTestExecutionListener.java:61)
	at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:260)
	at org.springframework.test.context.junit.jupiter.SpringExtension.postProcessTestInstance(SpringExtension.java:163)
	at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)
	at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:179)
	at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1625)
	at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)
	at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
	at java.base/java.util.stream.StreamSpliterators$WrappingSpliterator.forEachRemaining(StreamSpliterators.java:310)
	at java.base/java.util.stream.Streams$ConcatSpliterator.forEachRemaining(Streams.java:735)
	at java.base/java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:762)
	at java.base/java.util.Optional.orElseGet(Optional.java:364)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
Caused by: org.springframework.context.ApplicationContextException: Failed to start bean 'io.awspring.cloud.messaging.internalEndpointRegistryBeanName'
	at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:287)
	at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:467)
	at java.base/java.lang.Iterable.forEach(Iterable.java:75)
	at org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:256)
	at org.springframework.context.support.DefaultLifecycleProcessor.onRefresh(DefaultLifecycleProcessor.java:201)
	at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:978)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:627)
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:146)
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:754)
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:456)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:334)
	at org.springframework.boot.test.context.SpringBootContextLoader.lambda$loadContext$3(SpringBootContextLoader.java:137)
	at org.springframework.util.function.ThrowingSupplier.get(ThrowingSupplier.java:58)
	at org.springframework.util.function.ThrowingSupplier.get(ThrowingSupplier.java:46)
	at org.springframework.boot.SpringApplication.withHook(SpringApplication.java:1454)
	at org.springframework.boot.test.context.SpringBootContextLoader$ContextLoaderHook.run(SpringBootContextLoader.java:552)
	at org.springframework.boot.test.context.SpringBootContextLoader.loadContext(SpringBootContextLoader.java:137)
	at org.springframework.boot.test.context.SpringBootContextLoader.loadContext(SpringBootContextLoader.java:108)
	at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:225)
	at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:152)
	... 16 more
Caused by: java.util.concurrent.CompletionException: io.awspring.cloud.sqs.QueueAttributesResolvingException: Error resolving attributes for queue bp-bill-download-queue with strategy CREATE and queueAttributesNames []
	at java.base/java.util.concurrent.CompletableFuture.encodeRelay(CompletableFuture.java:368)
	at java.base/java.util.concurrent.CompletableFuture.completeRelay(CompletableFuture.java:377)
	at java.base/java.util.concurrent.CompletableFuture$UniCompose.tryFire(CompletableFuture.java:1152)
	at java.base/java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:510)
	at java.base/java.util.concurrent.CompletableFuture.completeExceptionally(CompletableFuture.java:2162)
	at software.amazon.awssdk.utils.CompletableFutureUtils.lambda$forwardExceptionTo$0(CompletableFutureUtils.java:79)
	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:2162)
	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:2162)
	at software.amazon.awssdk.core.internal.http.pipeline.stages.AsyncApiCallTimeoutTrackingStage.lambda$execute$2(AsyncApiCallTimeoutTrackingStage.java:67)
	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:2162)
	at software.amazon.awssdk.utils.CompletableFutureUtils.lambda$forwardExceptionTo$0(CompletableFutureUtils.java:79)
	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:2162)
	at software.amazon.awssdk.core.internal.http.pipeline.stages.AsyncRetryableStage$RetryingExecutor.maybeAttemptExecute(AsyncRetryableStage.java:103)
	at software.amazon.awssdk.core.internal.http.pipeline.stages.AsyncRetryableStage$RetryingExecutor.maybeRetryExecute(AsyncRetryableStage.java:184)
	at software.amazon.awssdk.core.internal.http.pipeline.stages.AsyncRetryableStage$RetryingExecutor.lambda$attemptExecute$1(AsyncRetryableStage.java:170)
	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.complete(CompletableFuture.java:2147)
	at software.amazon.awssdk.core.internal.http.pipeline.stages.MakeAsyncHttpRequestStage.lambda$execute$0(MakeAsyncHttpRequestStage.java:110)
	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.complete(CompletableFuture.java:2147)
	at software.amazon.awssdk.core.internal.http.pipeline.stages.MakeAsyncHttpRequestStage.completeResponseFuture(MakeAsyncHttpRequestStage.java:253)
	at software.amazon.awssdk.core.internal.http.pipeline.stages.MakeAsyncHttpRequestStage.lambda$executeHttpRequest$3(MakeAsyncHttpRequestStage.java:167)
	at java.base/java.util.concurrent.CompletableFuture.uniHandle(CompletableFuture.java:934)
	at java.base/java.util.concurrent.CompletableFuture$UniHandle.tryFire(CompletableFuture.java:911)
	at java.base/java.util.concurrent.CompletableFuture$Completion.run(CompletableFuture.java:482)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
	at java.base/java.lang.Thread.run(Thread.java:840)
Caused by: io.awspring.cloud.sqs.QueueAttributesResolvingException: Error resolving attributes for queue bp-bill-download-queue with strategy CREATE and queueAttributesNames []
	at io.awspring.cloud.sqs.QueueAttributesResolver.wrapException(QueueAttributesResolver.java:90)
	at java.base/java.util.concurrent.CompletableFuture.uniExceptionally(CompletableFuture.java:990)
	at java.base/java.util.concurrent.CompletableFuture$UniExceptionally.tryFire(CompletableFuture.java:974)
	... 42 more
Caused by: software.amazon.awssdk.services.sqs.model.SqsException: Service returned HTTP status code 400 (Service: Sqs, Status Code: 400, Request ID: null)
	at software.amazon.awssdk.services.sqs.model.SqsException$BuilderImpl.build(SqsException.java:104)
	at software.amazon.awssdk.services.sqs.model.SqsException$BuilderImpl.build(SqsException.java:58)
	at software.amazon.awssdk.protocols.json.internal.unmarshall.AwsJsonProtocolErrorUnmarshaller.unmarshall(AwsJsonProtocolErrorUnmarshaller.java:92)
	at software.amazon.awssdk.protocols.json.internal.unmarshall.AwsJsonProtocolErrorUnmarshaller.handle(AwsJsonProtocolErrorUnmarshaller.java:66)
	at software.amazon.awssdk.protocols.json.internal.unmarshall.AwsJsonProtocolErrorUnmarshaller.handle(AwsJsonProtocolErrorUnmarshaller.java:41)
	at software.amazon.awssdk.core.http.MetricCollectingHttpResponseHandler.lambda$handle$0(MetricCollectingHttpResponseHandler.java:52)
	at software.amazon.awssdk.core.internal.util.MetricUtils.measureDurationUnsafe(MetricUtils.java:99)
	at software.amazon.awssdk.core.internal.util.MetricUtils.measureDurationUnsafe(MetricUtils.java:92)
	at software.amazon.awssdk.core.http.MetricCollectingHttpResponseHandler.handle(MetricCollectingHttpResponseHandler.java:52)
	at software.amazon.awssdk.core.internal.http.async.AsyncResponseHandler.lambda$prepare$0(AsyncResponseHandler.java:92)
	at java.base/java.util.concurrent.CompletableFuture$UniCompose.tryFire(CompletableFuture.java:1150)
	at java.base/java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:510)
	at java.base/java.util.concurrent.CompletableFuture.complete(CompletableFuture.java:2147)
	at software.amazon.awssdk.core.internal.http.async.AsyncResponseHandler$BaosSubscriber.onComplete(AsyncResponseHandler.java:135)
	at software.amazon.awssdk.core.internal.metrics.BytesReadTrackingPublisher$BytesReadTracker.onComplete(BytesReadTrackingPublisher.java:74)
	at software.amazon.awssdk.http.nio.netty.internal.ResponseHandler$DataCountingPublisher$1.onComplete(ResponseHandler.java:519)
	at software.amazon.awssdk.http.nio.netty.internal.ResponseHandler.runAndLogError(ResponseHandler.java:254)
	at software.amazon.awssdk.http.nio.netty.internal.ResponseHandler.access$600(ResponseHandler.java:77)
	at software.amazon.awssdk.http.nio.netty.internal.ResponseHandler$PublisherAdapter$1.onComplete(ResponseHandler.java:375)
	at software.amazon.awssdk.http.nio.netty.internal.nrs.HandlerPublisher.publishMessage(HandlerPublisher.java:402)
	at software.amazon.awssdk.http.nio.netty.internal.nrs.HandlerPublisher.flushBuffer(HandlerPublisher.java:338)
	at software.amazon.awssdk.http.nio.netty.internal.nrs.HandlerPublisher.receivedDemand(HandlerPublisher.java:291)
	at software.amazon.awssdk.http.nio.netty.internal.nrs.HandlerPublisher.access$200(HandlerPublisher.java:61)
	at software.amazon.awssdk.http.nio.netty.internal.nrs.HandlerPublisher$ChannelSubscription$1.run(HandlerPublisher.java:495)
	at io.netty.util.concurrent.AbstractEventExecutor.runTask(AbstractEventExecutor.java:173)
	at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:166)
	at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:470)
	at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:566)
	at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997)
	at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
	... 1 more

and This is the configuration

@TestConfiguration
public class SQSTestConfig implements ApplicationContextInitializer<ConfigurableApplicationContext> {

	@Value("${spring.cloud.aws.sqs.endpoint}")
	private String sqsUrl;

	@Value("${spring.cloud.aws.region.static}")
	private String region;

	@Value("${aws.sqs.demo-queue}")
	private String sourceQueueName;

	@Value("${aws.sqs.demo-dlq}")
	private String deadLetterQueueName;

	private SQSRestServer server;
	
@PostConstruct
	public void init() {
		initSQS();
	}

	@PreDestroy
	public void preDestroy() {
		server.stopAndWait();
	}

	@Bean
	SqsAsyncClient sqsAsyncClient() {
		return SqsAsyncClient.builder().region(Region.of(region)).endpointOverride(URI.create(sqsUrl))
				.credentialsProvider(StaticCredentialsProvider.create(AwsBasicCredentials.create("x", "x"))).build();
	}

	// Initialize SQS
	private void initSQS() {
		try {
			SqsAsyncClient sqs = SqsAsyncClient.builder().region(Region.of(region)).endpointOverride(URI.create(sqsUrl))
					.credentialsProvider(StaticCredentialsProvider.create(AwsBasicCredentials.create("x", "x")))
					.build();

			if (server == null) {

				// Start Server
				server = SQSRestServerBuilder.withPort(new URL(sqsUrl).getPort()).start();

				createSQSQueueWithDLQ(sqs, sourceQueueName, deadLetterQueueName);
			}
		} catch (InterruptedException | ExecutionException e) {
			Throwable cause = e.getCause();
			if (cause instanceof SqsException) {
				SqsException sqsEx = (SqsException) cause;
				System.err.println("Error message: " + sqsEx.awsErrorDetails().errorMessage());
				System.err.println("Error code: " + sqsEx.awsErrorDetails().errorCode());
			} else {
				e.printStackTrace();
			}

		} catch (Exception e) {
			throw new RuntimeException("Failed SQS initialization", e);
		}
	}

	private void createSQSQueueWithDLQ(SqsAsyncClient sqs, String queueName, String dlqName)
			throws InterruptedException, ExecutionException {

		// Create Main normal queue
		String queueUrl = sqs.createQueue(CreateQueueRequest.builder().queueName(queueName).build()).get().queueUrl();
		System.out.println("Queue created with URL: " + queueUrl);

		// Create Dead Letter Queue (DLQ) for normal queue
		String dlqQueueUrl = sqs.createQueue(CreateQueueRequest.builder().queueName(dlqName).build()).get().queueUrl();
		System.out.println("DLQ created with URL: " + dlqQueueUrl);

		// Get DLQ ARN
		String dlqArn = sqs
				.getQueueAttributes(GetQueueAttributesRequest.builder().queueUrl(dlqQueueUrl)
						.attributeNames(QueueAttributeName.QUEUE_ARN).build())
				.get().attributes().get(QueueAttributeName.QUEUE_ARN);
	}

	// Set sqs info properties for @Value injection, specially the port
	private void setUrlProperty(ConfigurableApplicationContext context) {
		try {

			// Generate random free port
			ServerSocket serverSocket = new ServerSocket(0);
			int port = serverSocket.getLocalPort();
			serverSocket.close();

			// Assign config properties with dynamic port and already configured
			// application.yaml properties
			ConfigurableEnvironment environment = context.getEnvironment();
			String oldEndpoint = environment.getProperty("spring.cloud.aws.sqs.endpoint");
			String newUrl = Objects.requireNonNull(oldEndpoint).replace("5235", String.valueOf(port));
			sqsUrl = newUrl;

			// Put the new url as property in the context/environment
			Properties props = new Properties();
			props.put("spring.cloud.aws.sqs.endpoint", newUrl);
			environment.getPropertySources().addFirst(new PropertiesPropertySource("whatever", props));
		} catch (IOException e) {
			e.printStackTrace();
			throw new RuntimeException("Failed to get random port", e);
		}
	}

	@Override
	public void initialize(@NonNull ConfigurableApplicationContext applicationContext) {
		setUrlProperty(applicationContext);
	}

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