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

Spring Boot 3.2.2 @SqsListener Not listening to the Queue #1028

Closed
WoodenCode00 opened this issue Jan 23, 2024 · 6 comments
Closed

Spring Boot 3.2.2 @SqsListener Not listening to the Queue #1028

WoodenCode00 opened this issue Jan 23, 2024 · 6 comments
Labels
component: sqs SQS integration related issue status: waiting-for-feedback Waiting for feedback from issuer

Comments

@WoodenCode00
Copy link

WoodenCode00 commented Jan 23, 2024

Type: Bug

Component: SQS

Describe the bug
After upgrading from Spring Boot 2.7.18 to 3.2.2 the @SqsListener annotation doesn't listen to the SQS queue. I made some experimentations, for example, I added @PostConstruct method to the class with a simple logger, and I can see that the log doesn't get printed. Interesting that after adding a @Scheduled(fixedRate = 5000) on the method in this class, all of a sudden the log message from PostConstruct comes out and SqsListener method starts to consume the messages.

Another fact, the below log statement is not printed, though I can see it after adding @Scheduled method:
2024-01-19 17:40:48.546 [lifecycle-thread-1] INFO io.awspring.cloud.sqs.listener.AbstractMessageListenerContainer.start - Container io.awspring.cloud.sqs.sqsListenerEndpointContainer#0 started

Sample

@Slf4j
@Component
@RequiredArgsConstructor
@FieldDefaults(level = AccessLevel.PRIVATE, makeFinal = true)
public class MySqsConsumer  {

  @PostConstruct
  public void init() {
    var bean = applicationContext.getBean(SqsListenerAnnotationBeanPostProcessor.class);
    log.info("Loaded SqsListenerAnnotationBeanPostProcessor: {}", bean);
  }

  @SqsListener("https://sqs.us-east-1.amazonaws.com/account-id/my-queue")
   public void consume(String message) {
     log.info("Message: {}", message);
  }
}

UPDATE: versions used:

 <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.2.2</version>
        <relativePath/>
    </parent>

          <dependency>
                <groupId>io.awspring.cloud</groupId>
                <artifactId>spring-cloud-aws-dependencies</artifactId>
                <version>3.1.0</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>

UPDATE: output of bean resolutions - all looks normal, though the queue is not getting polled:

 ============================
 CONDITIONS EVALUATION REPORT
 ============================


   SqsAutoConfiguration matched:
      - @ConditionalOnClass found required classes 'software.amazon.awssdk.services.sqs.SqsAsyncClient', 'io.awspring.cloud.sqs.config.SqsBootstrapConfiguration' (OnClassCondition)
      - @ConditionalOnProperty (spring.cloud.aws.sqs.enabled=true) matched (OnPropertyCondition)

   SqsAutoConfiguration#defaultSqsListenerContainerFactory matched:
      - @ConditionalOnMissingBean (types: io.awspring.cloud.sqs.config.SqsMessageListenerContainerFactory; SearchStrategy: all) did not find any beans (OnBeanCondition)

   SqsAutoConfiguration#sqsAsyncClient matched:
      - @ConditionalOnMissingBean (types: software.amazon.awssdk.services.sqs.SqsAsyncClient; SearchStrategy: all) did not find any beans (OnBeanCondition)

   SqsAutoConfiguration#sqsTemplate matched:
      - @ConditionalOnMissingBean (types: io.awspring.cloud.sqs.operations.SqsTemplate; SearchStrategy: all) did not find any beans (OnBeanCondition)
@tomazfernandes
Copy link
Contributor

Hi @WoodenCode00, would you be able to create and share a sample application that reproduces the issue without the @PostConstruct annotation?

Thanks.

@tomazfernandes tomazfernandes added the component: sqs SQS integration related issue label Jan 28, 2024
@WoodenCode00
Copy link
Author

Let me see... Interesting that in the new clean project the @SqsListener works.
Trying to reproduce the problem in the new project...

@tomazfernandes tomazfernandes added the status: waiting-for-feedback Waiting for feedback from issuer label Jan 30, 2024
@WoodenCode00
Copy link
Author

I couldn't reproduce the issue in a new project. As a workaround, I refactored the code to create a bean of MessageListenerContainer in @Configuration class. This way the container is able to listen to the queue.

@tomazfernandes
Copy link
Contributor

@WoodenCode00 since it seems you solved your problem, I'll close this issue.

We can reopen it if you'd like and feel free to provide more details on your configuration if you want to investigate this further.

Thanks.

@fsamir
Copy link

fsamir commented Nov 20, 2024

I had the same issue and found the root cause here: https://stackoverflow.com/questions/75181017/aws-sqslistener-not-working-with-spring-cloud-using-springboot-3

In short, use io.awspring.cloud.sqs.annotation.SqsListener to listen the messages instead of io.awspring.cloud.messaging.listener.annotation.SqsListener.

@WoodenCode00
Copy link
Author

@fsamir thanks for your comment. I checked my old code, I did use the io.awspring.cloud.sqs.annotation.SqsListener annotation, still didn't work. Maybe you got a different flavor of the problem.

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