Search code examples
amazon-sqs

SqsListner not listening to messages


I have below application.properties for connection:

cloud.aws.credentials.instanceProfile=true
cloud.aws.credentials.useDefaultAwsCredentialsChain=true
cloud.aws.region.static=us-east-2
cloud.aws.stack.auto=false

I have written listener with SqsListner and running my application with below dependencies

 <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-aws-messaging</artifactId>
            <version>1.2.4.RELEASE</version>
        </dependency>
 <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
            <version>1.4.3.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-aws-messaging</artifactId>
            <version>2.1.2.RELEASE</version>
        </dependency>

But somehow my listener is not listening to messages (I am doing this in the existing code base).

I tried creating a separate spring boot application with only the listener in it, which is working fine. But the same thing is not working when added to existing code

and Listener code is as below:

@SqsListener(value = "test-queue",deletionPolicy = ON_SUCCESS)
public void receiveMessage(String message,
    @Header(X_REQUEST_ID) String xRequestId,
    @Header(X_SESSION_ID) String xSessionId) {
    LOGGER.info("message received is: {}", message);

    }
}

Solution

  • By mistake I had overriden AmazonSQSAsync bean

    public AmazonSQSAsync amazonSQSClient() {
            return new AmazonSQSAsyncClient();
        }
    

    which caused ignoring the aws properties I added. And hence SqsListner was not working as there is no way to explicitly specify aws properties including credentials to SqsListner. I removed the manual bean creation part and it started working smoothly as Bean is automatically created now and picking up the correct properties.