@SqsListener Not consuming the messages in the queue

2.1k Views Asked by At

I'm using my spring boot code to connect to an AWS SQS service. Right now I'm using Localstack but the problem remained even in the AWS console. I'm able to send the messages to the queue but my sqsListener is not reading and logging the messages.

@PostMapping("/send_message")
    public EmployeeModel sendMessage(@RequestBody EmployeeModel employee) {

        try {
            ObjectMapper mapper = new ObjectMapper();
            String jsonString = mapper.writeValueAsString(employee);
            queueMessagingTemplate.send(endPoint, MessageBuilder.withPayload(jsonString).build());
            logger.info("Message sent successfully  " + jsonString);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return employee;
    }

    @SqsListener(value = {"http://localhost:4566/000000000000/employeeTest"}, deletionPolicy = SqsMessageDeletionPolicy.ON_SUCCESS)
    public void receiveMessage(String stringJson) {

        logger.info("Message Received using SQS Listener " + stringJson);
        //System.out.println(stringJson);

    }

These are the dependencies I'm using with gradle.

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    
    implementation platform('com.amazonaws:aws-java-sdk-bom:1.11.1000')
    implementation 'org.springframework.cloud:spring-cloud-aws-core:2.2.6.RELEASE'

    implementation 'org.springframework.cloud:spring-cloud-aws-messaging:2.2.6.RELEASE'

    
    runtimeOnly 'mysql:mysql-connector-java'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

I'm not getting any runtime error or any error of any sort. It's just when I've sent a message, the sqs listener doesn't consume the message.

1

There are 1 best solutions below

1
On

You need to update the below dependencies for starting consuming messages.

Update the below dependency.

implementation 'org.springframework.cloud:spring-cloud-aws-messaging'
to
org.springframework.cloud:spring-cloud-starter-aws-messaging