简体   繁体   中英

@SqsListener doesn't work but AmazonSqs client work

My SQS Listener cannot find queue with name and url.
But AmazonSqsAsync Client can find list of queues and queue url.
I can't understand why only @SqsListener cannot find queue.
Could you give me some knowledge what I missed?


Here's my code, application-local.yml and Error message. I'm running sqs with localstack

  1. Error message
SimpleMessageListenerContainer : Ignoring queue with name 'test-availability-queue': The queue does not exist.; nested exception is com.amazonaws.services.sqs.model.QueueDoesNotExistException: AWS.SimpleQueueService.NonExistentQueue; see the SQS docs. (Service: AmazonSQS; Status Code: 400; Error Code: AWS.SimpleQueueService.NonExistentQueue; Request ID: 00000000-0000-0000-0000-000000000000; Proxy: null)
  1. application-local.yml
cloud:
  aws:
    region:
      auto: false
      static: ap-northeast-2
    credentials:
      access-key: aws_access_key_id
      secret-key: aws_secret_access_key
    sqs:
      endpoint: http://localhost:4566

availability:
  queue:
    name: test-availability-queue
  1. SqsListener I used value with queue-name and queue-url but both didn't work.
@Component
public class AvailabilitySqsListener {

    @SqsListener(value = "${availability.queue.name}", deletionPolicy = SqsMessageDeletionPolicy.NO_REDRIVE)
    public void onMessage(@Payload AvailabilityMessage message) {
        doSomething();
    }
}
  1. Sqs Configuration
@Configuration
public class SqsConfiguration {
    private static final String AWS_ENDPOINT = "${cloud.aws.sqs.endpoint}";
    private static final String AWS_REGION = "${cloud.aws.region.static}";

    @Bean
    public AwsClientBuilder.EndpointConfiguration endpointConfiguration(
            @Value(AWS_ENDPOINT) String endpoint,
            @Value(AWS_REGION) String region) {
        return new AwsClientBuilder.EndpointConfiguration(endpoint, region);
    }
    @Bean
    @Primary
    public AmazonSQSAsync amazonSQSAsync(final AwsClientBuilder.EndpointConfiguration endpointConfiguration) {
        String endpoint = endpointConfiguration.getServiceEndpoint();

        if (endpoint == null || endpoint.isEmpty()) {
            return AmazonSQSAsyncClientBuilder.standard()
                    .withRegion(endpointConfiguration.getSigningRegion())
                    .withCredentials(new DefaultAWSCredentialsProviderChain())
                    .build();
        }
        return AmazonSQSAsyncClientBuilder.standard()
                .withEndpointConfiguration(endpointConfiguration)
                .withCredentials(new DefaultAWSCredentialsProviderChain())
                .build();
    }

    @Bean
    public QueueMessagingTemplate queueMessagingTemplate(
            AmazonSQSAsync amazonSQSAsync,
            MessageConverter messageConverter,
            ResourceIdResolver resourceIdResolver) {
        return new QueueMessagingTemplate(amazonSQSAsync, resourceIdResolver, messageConverter);
    }

    @Bean
    public MessageConverter messageConverter(ObjectMapper objectMapper) {
        MappingJackson2MessageConverter converter = new MappingJackson2MessageConverter();
        converter.setObjectMapper(objectMapper);
        converter.setSerializedPayloadClass(String.class);
        return converter;
    }
}
  1. Success case with AmazonSqsAsync client
// When I called this API
    @GetMapping("/test")
    public void test() {
        System.out.println(amazonSQSAsync.listQueues());
        System.out.println(amazonSQSAsync.getQueueUrl("test-availability-queue"));
    }
# response
{QueueUrls: [http://localhost:4566/queue/test-availability-queue],}
{QueueUrl: http://localhost:4566/queue/test-availability-queue}

FYI, full of my console logs

2021-11-20 16:26:18.297  INFO 34014 --- [  restartedMain] c.d.s.v.m.LogVendorMonitorApplication    : The following profiles are active: local
2021-11-20 16:26:18.342  INFO 34014 --- [  restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
2021-11-20 16:26:18.343  INFO 34014 --- [  restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG'
2021-11-20 16:26:19.206  INFO 34014 --- [  restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Multiple Spring Data modules found, entering strict repository configuration mode!
2021-11-20 16:26:19.208  INFO 34014 --- [  restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data Redis repositories in DEFAULT mode.
2021-11-20 16:26:19.260  INFO 34014 --- [  restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 43 ms. Found 1 Redis repository interfaces.
2021-11-20 16:26:19.400  INFO 34014 --- [  restartedMain] o.s.cloud.context.scope.GenericScope     : BeanFactory id=d7c2eb3d-42ea-35c3-8d4c-ab542b183924
2021-11-20 16:26:19.447  INFO 34014 --- [  restartedMain] trationDelegate$BeanPostProcessorChecker : Bean 'credentialsProvider' of type [com.amazonaws.auth.AWSCredentialsProviderChain] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2021-11-20 16:26:19.836  INFO 34014 --- [  restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2021-11-20 16:26:19.843  INFO 34014 --- [  restartedMain] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2021-11-20 16:26:19.843  INFO 34014 --- [  restartedMain] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.52]
2021-11-20 16:26:19.908  INFO 34014 --- [  restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2021-11-20 16:26:19.908  INFO 34014 --- [  restartedMain] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1565 ms
2021-11-20 16:26:20.326  INFO 34014 --- [  restartedMain] o.s.b.d.a.OptionalLiveReloadServer       : LiveReload server is running on port 35729
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.amazonaws.util.XpathUtils (file:/Users/a202107057/.m2/repository/com/amazonaws/aws-java-sdk-core/1.11.951/aws-java-sdk-core-1.11.951.jar) to method com.sun.org.apache.xpath.internal.XPathContext.getDTMManager()
WARNING: Please consider reporting this to the maintainers of com.amazonaws.util.XpathUtils
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
2021-11-20 16:26:21.436  WARN 34014 --- [  restartedMain] i.a.c.m.l.SimpleMessageListenerContainer : Ignoring queue with name 'test-availability-queue': The queue does not exist.; nested exception is com.amazonaws.services.sqs.model.QueueDoesNotExistException: AWS.SimpleQueueService.NonExistentQueue; see the SQS docs. (Service: AmazonSQS; Status Code: 400; Error Code: AWS.SimpleQueueService.NonExistentQueue; Request ID: 00000000-0000-0000-0000-000000000000; Proxy: null)
2021-11-20 16:26:21.588  INFO 34014 --- [  restartedMain] o.s.b.a.e.web.EndpointLinksResolver      : Exposing 4 endpoint(s) beneath base path ''
2021-11-20 16:26:21.655  INFO 34014 --- [  restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
2021-11-20 16:26:21.672  INFO 34014 --- [  restartedMain] c.d.s.v.m.LogVendorMonitorApplication    : Started LogVendorMonitorApplication in 3.724 seconds (JVM running for 4.378)
2021-11-20 16:26:24.822  INFO 34014 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring DispatcherServlet 'dispatcherServlet'
2021-11-20 16:26:24.823  INFO 34014 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Initializing Servlet 'dispatcherServlet'
2021-11-20 16:26:24.824  INFO 34014 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Completed initialization in 1 ms

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM