aws / aws-sdk-java

The official AWS SDK for Java 1.x (In Maintenance Mode, End-of-Life on 12/31/2025). The AWS SDK for Java 2.x is available here: https://github.com/aws/aws-sdk-java-v2/
https://aws.amazon.com/sdkforjava
Apache License 2.0
4.13k stars 2.83k forks source link

Updating aws-java-sdk-sqs from 1.12.583 to 1.12.584 breaks @JmsListener #3061

Closed soeren-glimm-insurfox closed 12 months ago

soeren-glimm-insurfox commented 1 year ago

Describe the bug

During startup, I get an AmazonSQSException. When reverting to 583, the application starts successfully

Expected Behavior

No exception occurs

Current Behavior

2023-11-27T14:12:50.623+01:00  INFO 21091 --- [           main] org.example.Main                         : Started Main in 1.509 seconds (process running for 2.031)
2023-11-27T14:12:51.455+01:00 ERROR 21091 --- [ntContainer#0-1] c.a.s.j.AmazonSQSMessagingClientWrapper  : AmazonServiceException: getQueueUrl. RequestId: null
HTTPStatusCode: 500 AmazonErrorCode: null

com.amazonaws.services.sqs.model.AmazonSQSException: null (Service: AmazonSQS; Status Code: 500; Error Code: null; Request ID: null; Proxy: null)
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.handleErrorResponse(AmazonHttpClient.java:1879) ~[aws-java-sdk-core-1.12.584.jar:na]
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.handleServiceErrorResponse(AmazonHttpClient.java:1418) ~[aws-java-sdk-core-1.12.584.jar:na]
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeOneRequest(AmazonHttpClient.java:1387) ~[aws-java-sdk-core-1.12.584.jar:na]
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeHelper(AmazonHttpClient.java:1157) ~[aws-java-sdk-core-1.12.584.jar:na]
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.doExecute(AmazonHttpClient.java:814) ~[aws-java-sdk-core-1.12.584.jar:na]
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeWithTimer(AmazonHttpClient.java:781) ~[aws-java-sdk-core-1.12.584.jar:na]
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.execute(AmazonHttpClient.java:755) ~[aws-java-sdk-core-1.12.584.jar:na]
    at com.amazonaws.http.AmazonHttpClient$RequestExecutor.access$500(AmazonHttpClient.java:715) ~[aws-java-sdk-core-1.12.584.jar:na]
    at com.amazonaws.http.AmazonHttpClient$RequestExecutionBuilderImpl.execute(AmazonHttpClient.java:697) ~[aws-java-sdk-core-1.12.584.jar:na]
    at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:561) ~[aws-java-sdk-core-1.12.584.jar:na]
    at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:541) ~[aws-java-sdk-core-1.12.584.jar:na]
    at com.amazonaws.services.sqs.AmazonSQSClient.doInvoke(AmazonSQSClient.java:3331) ~[aws-java-sdk-sqs-1.12.584.jar:na]
    at com.amazonaws.services.sqs.AmazonSQSClient.invoke(AmazonSQSClient.java:3297) ~[aws-java-sdk-sqs-1.12.584.jar:na]
    at com.amazonaws.services.sqs.AmazonSQSClient.invoke(AmazonSQSClient.java:3286) ~[aws-java-sdk-sqs-1.12.584.jar:na]
    at com.amazonaws.services.sqs.AmazonSQSClient.executeGetQueueUrl(AmazonSQSClient.java:1651) ~[aws-java-sdk-sqs-1.12.584.jar:na]
    at com.amazonaws.services.sqs.AmazonSQSClient.getQueueUrl(AmazonSQSClient.java:1620) ~[aws-java-sdk-sqs-1.12.584.jar:na]
    at com.amazon.sqs.javamessaging.AmazonSQSMessagingClientWrapper.getQueueUrl(AmazonSQSMessagingClientWrapper.java:287) ~[amazon-sqs-java-messaging-lib-1.2.0.jar:na]
    at com.amazon.sqs.javamessaging.AmazonSQSMessagingClientWrapper.getQueueUrl(AmazonSQSMessagingClientWrapper.java:258) ~[amazon-sqs-java-messaging-lib-1.2.0.jar:na]
    at com.amazon.sqs.javamessaging.SQSSession.createQueue(SQSSession.java:647) ~[amazon-sqs-java-messaging-lib-1.2.0.jar:na]
    at org.springframework.jms.support.destination.DynamicDestinationResolver.resolveQueue(DynamicDestinationResolver.java:85) ~[spring-jms-6.0.13.jar:6.0.13]
    at org.springframework.jms.support.destination.DynamicDestinationResolver.resolveDestinationName(DynamicDestinationResolver.java:59) ~[spring-jms-6.0.13.jar:6.0.13]
    at org.springframework.jms.support.destination.JmsDestinationAccessor.resolveDestinationName(JmsDestinationAccessor.java:115) ~[spring-jms-6.0.13.jar:6.0.13]
    at org.springframework.jms.listener.AbstractPollingMessageListenerContainer.createListenerConsumer(AbstractPollingMessageListenerContainer.java:222) ~[spring-jms-6.0.13.jar:6.0.13]
    at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.initResourcesIfNecessary(DefaultMessageListenerContainer.java:1266) ~[spring-jms-6.0.13.jar:6.0.13]
    at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.invokeListener(DefaultMessageListenerContainer.java:1238) ~[spring-jms-6.0.13.jar:6.0.13]
    at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.executeOngoingLoop(DefaultMessageListenerContainer.java:1229) ~[spring-jms-6.0.13.jar:6.0.13]
    at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.run(DefaultMessageListenerContainer.java:1122) ~[spring-jms-6.0.13.jar:6.0.13]
    at java.base/java.lang.Thread.run(Thread.java:833) ~[na:na]

2023-11-27T14:12:51.461+01:00  INFO 21091 --- [ntContainer#0-1] c.amazon.sqs.javamessaging.SQSSession    : Shutting down SessionCallBackScheduler executor
2023-11-27T14:12:56.462+01:00  WARN 21091 --- [ntContainer#0-1] o.s.j.l.DefaultMessageListenerContainer  : Setup of JMS message listener invoker failed for destination 'queue' - trying to recover. Cause: AmazonServiceException: getQueueUrl. RequestId: null

Reproduction Steps

EventListener.java:

package org.example;

import jakarta.jms.Message;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.stereotype.Component;

@Component
public class EventListener  {
    @JmsListener(destination = "queue", containerFactory = "jmsListenerContainerFactory")
    public void onMessage(Message message) {

    }
}

AWSConfig.java:

package org.example;

import com.amazon.sqs.javamessaging.ProviderConfiguration;
import com.amazon.sqs.javamessaging.SQSConnectionFactory;
import com.amazonaws.auth.AWSStaticCredentialsProvider;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.client.builder.AwsClientBuilder;
import com.amazonaws.services.sqs.AmazonSQSAsync;
import com.amazonaws.services.sqs.AmazonSQSAsyncClientBuilder;
import jakarta.jms.ConnectionFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jms.config.DefaultJmsListenerContainerFactory;
import org.springframework.jms.config.JmsListenerContainerFactory;

@Configuration
public class AWSConfig {

    @Bean
    public AmazonSQSAsync amazonSQSAsync() {
        final AmazonSQSAsyncClientBuilder sqsClientBuilder = AmazonSQSAsyncClientBuilder.standard().withEndpointConfiguration(getEndpointConfiguration());

        return sqsClientBuilder.withCredentials(getCredentialsProvider()).build();
    }

    @Bean
    public ConnectionFactory connectionFactory(final AmazonSQSAsync amazonSQSAsync) {
        final ProviderConfiguration providerConfiguration = new ProviderConfiguration();
        providerConfiguration.setNumberOfMessagesToPrefetch(10);

        return new SQSConnectionFactory(providerConfiguration, amazonSQSAsync);
    }

    @Bean
    public JmsListenerContainerFactory<?> jmsListenerContainerFactory(final ConnectionFactory connectionFactory) {
        final var jmsListenerContainerFactory = new DefaultJmsListenerContainerFactory();
        jmsListenerContainerFactory.setConnectionFactory(connectionFactory);
        return jmsListenerContainerFactory;
    }

    private AWSStaticCredentialsProvider getCredentialsProvider() {
        return new AWSStaticCredentialsProvider(new BasicAWSCredentials("testUser", "testAccessKey"));
    }

    private AwsClientBuilder.EndpointConfiguration getEndpointConfiguration() {
        return new AwsClientBuilder.EndpointConfiguration("http://127.0.0.1:4566", "us-east-1");
    }
}

Main.java:

package org.example;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class Main {
    public static void main(String[] args) {
        SpringApplication.run(Main.class, args);
    }
}

build.gradle:

plugins {
    id 'org.springframework.boot' version '3.1.5'
    id 'io.spring.dependency-management' version '1.1.4'
    id 'java'
}

group = 'org.example'
version = '1.0-SNAPSHOT'

repositories {
    mavenCentral()
}

dependencyManagement {
    imports {
        mavenBom "com.amazonaws:aws-java-sdk-bom:1.12.584"
    }
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter'
    implementation 'com.amazonaws:amazon-sqs-java-messaging-lib:1.2.0'
    implementation 'org.springframework:spring-jms'

    compileOnly 'jakarta.jms:jakarta.jms-api'
}

Possible Solution

No response

Additional Information/Context

I'm using localstack 1.4 to test locally.

AWS Java SDK version used

1.12.584

JDK version used

java 17.0.4 2022-07-19 LTS Java(TM) SE Runtime Environment (build 17.0.4+11-LTS-179) Java HotSpot(TM) 64-Bit Server VM (build 17.0.4+11-LTS-179, mixed mode, sharing)

Operating System and version

MacOS 13.5

debora-ito commented 12 months ago

Hi @soeren-glimm-insurfox,

The SQS service model changed to JSON protocol in version 1.12.585. Localstack needed to accommodate this change on their side so you'll need to upgrade to their latest version, here's a link to their feature - https://github.com/localstack/localstack/issues/8267#issuecomment-1806421471

To avoid this error, you need to use the latest Localstack version localstack/localstack:latest OR pin the Java SDK version to <= 1.12.583.

I can't say in detail how the SQS protocol change impacts amazon-sqs-java-messaging-lib and Spring JmsListener, those libraries are not maintained by us, you'll need to reach out to the respective maintainers.

soeren-glimm-insurfox commented 12 months ago

Thanks

github-actions[bot] commented 12 months ago

COMMENT VISIBILITY WARNING

Comments on closed issues are hard for our team to see. If you need more assistance, please open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.