SQSlistener not receiving messages
Asked Answered
W

5

6

I am able to send messages to SQS queue from my springboot but not able to receive using sqslistener annotation, can someone help?

public void send(String message) {


    queueMessagingTemplate.convertAndSend("test-queue", MessageBuilder.withPayload(message).build());
}

@SqsListener(value = "test-queue", deletionPolicy = SqsMessageDeletionPolicy.NEVER)
public void receive(String message)
{
    System.out.println("message: " + message);
}

I have verified send by goign to AWS console, i can see my messages in queue, but they are not coming to receive method. config:

@Bean
public AmazonSQSAsyncClient amazonSQSAsyncClient()
{

    AmazonSQSAsyncClient amazonSQSAsyncClient= new AmazonSQSAsyncClient(amazonAWSCredentials());

    if (!StringUtils.isEmpty(amazonSqsEndpoint)) {
        amazonSQSAsyncClient.setEndpoint(amazonSqsEndpoint);

    }

}

@Bean
public SimpleMessageListenerContainerFactory simpleMessageListenerContainerFactory() {
    SimpleMessageListenerContainerFactory msgListenerContainerFactory = new SimpleMessageListenerContainerFactory();
    msgListenerContainerFactory.setAmazonSqs(amazonSQSAsyncClient());
    return msgListenerContainerFactory;
}

@Bean
public QueueMessagingTemplate queueMessagingTemplate(AmazonSQSAsync amazonSqs) {
    return new QueueMessagingTemplate(amazonSQSAsyncClient());
}

@Bean
public BasicAWSCredentials amazonAWSCredentials() {
    return new BasicAWSCredentials(amazonAWSAccessKey, amazonAWSSecretKey);
}
Whenas answered 5/5, 2017 at 13:8 Comment(2)
"Does not work" is simply not enough information for anyone to help you. Have you turned on DEBUG logging? What do you see?Pea
Hi, thats the strange part, there is no error, once i send the message there is nothing printed, message goes and sits in the queue and listener doesnt get the messages at all!Whenas
W
2

Turns out i had a typo in the queue names in SQS console and my code, my bad.

Whenas answered 11/5, 2017 at 9:4 Comment(0)
R
6

In my case i was missing an annotation @EnableSqs in config class

Rigid answered 4/7, 2022 at 16:59 Comment(0)
W
2

Turns out i had a typo in the queue names in SQS console and my code, my bad.

Whenas answered 11/5, 2017 at 9:4 Comment(0)
C
2

Though it is late, it may help someone. In my case, I used gradle with these configuration

  implementation "io.awspring.cloud:spring-cloud-starter-aws-messaging:2.3.0"
  implementation "io.awspring.cloud:spring-cloud-aws-dependencies:2.3.0"

It doesn't work , below works perfectly for me:

compile "io.awspring.cloud:spring-cloud-starter-aws-messaging:2.3.0"
compile "io.awspring.cloud:spring-cloud-aws-dependencies:2.3.0"
Citric answered 10/7, 2021 at 17:49 Comment(1)
I had the same issue, it was working fine in mvn project but when I migrated it to gradle project it stopped working.Quickfreeze
P
1

In my case, the wrong region is specified. For some reason, sending didn't complain & pushed the message to the queue, but the listener is not getting called. Fixing the region in the application.yml file solved the issue.

Placate answered 22/4, 2021 at 18:36 Comment(0)
V
0

In my case QueueMessageHandler bean wasn't initialized.

In the documentation they are using maven dependency:

<dependency>
     <groupId>io.awspring.cloud</groupId>
     <artifactId>spring-cloud-aws-messaging</artifactId>
     <version>{spring-cloud-version}</version>
</dependency>

But in my case I'm using gradle, and also require dependency:

implementation(platform("io.awspring.cloud:spring-cloud-aws-dependencies:2.4.2"))
implementation("io.awspring.cloud:spring-cloud-aws-messaging")
implementation("io.awspring.cloud:spring-cloud-aws-autoconfigure")

Or you could define QueueMessageHandler in your own config file

  @Bean
  public QueueMessageHandler queueMessageHandler(QueueMessageHandlerFactory factory) {
    return factory.createQueueMessageHandler();
  }
Vesperal answered 4/11, 2022 at 13:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.