繁体   English   中英

@SqsListener 不工作但 AmazonSqs 客户端工作

[英]@SqsListener doesn't work but AmazonSqs client work

我的 SQS 侦听器找不到名称为 url 的队列。
但是 AmazonSqsAsync 客户端可以找到队列列表和队列 url。
我不明白为什么只有@SqsListener 找不到队列。
你能给我一些我错过的知识吗?


这是我的代码、application-local.yml 和错误消息。 我正在使用 localstack 运行 sqs

  1. 错误信息
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. 应用程序本地.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 我将值与队列名称和队列网址一起使用,但两者都不起作用。
@Component
public class AvailabilitySqsListener {

    @SqsListener(value = "${availability.queue.name}", deletionPolicy = SqsMessageDeletionPolicy.NO_REDRIVE)
    public void onMessage(@Payload AvailabilityMessage message) {
        doSomething();
    }
}
  1. Sqs配置
@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. AmazonSqsAsync 客户端的成功案例
// 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}

仅供参考,充满了我的控制台日志

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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