0
package com.example.aws.Springbootsqs.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.aws.messaging.core.QueueMessagingTemplate;
import org.springframework.cloud.aws.messaging.listener.annotation.SqsListener;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class SQSController {
    
    Logger logger =LoggerFactory.getLogger(SQSController.class);
    
    @Autowired
    private QueueMessagingTemplate queueMessagingTemplate;
    
    @Value("${cloud.aws.end-point.uri}")
    private String endPoint;

    
    @GetMapping("/put/{msg}")
    public void putMessagesToQueue(@PathVariable("msg") String message) {
        queueMessagingTemplate
        .send(endPoint, MessageBuilder
                .withPayload(message)
                .build());
        
    }
    
    @SqsListener("sqs-queue")
    public void loadMessagesFromQueue(String message) {
        logger.info(message);
    
    }
    
    
}

I am okay with pushing the messages to SQS but at the same time when i am reading and printing the messages the method is not being called and it is not printing anything from SQS and no error on console.

Any help will be useful. Thanks in advance.

  • Do you see any messages on your queue? See if this helps you https://stackoverflow.com/questions/43805823/sqslistener-not-receiving-messages – JCompetence May 12 '23 at 07:10
  • code is publishing the messages to queue and i can see in dashboard but not reading it back and ther eis nothing on console. it seems loadMessagesFromQueue method is not being called – Chanchal Kuckmar May 12 '23 at 08:21

0 Answers0