1

I'm unable to attach a @SqsListener in a spring boot application. It throws AWS.SimpleQueueService.NonExistentQueue exception.

I've gone through the question: Specified queue does not exist and as far as I know, all the configurations are correct.

@Component
public class SQSListenerImpl{
    @SqsListener(value = Constants.SQS_REQUEST_QUEUE, deletionPolicy = SqsMessageDeletionPolicy.NEVER)
    public void listen(String taskJson, Acknowledgment acknowledgment, @Headers Map<String, String> headers) throws ExecutionException, InterruptedException {
        //stuff
    }

    @PostConstruct
    private void init(){
        final AmazonSQS sqs = AmazonSQSClientBuilder.defaultClient();
        LOGGER.info("Listing all queues in your account.\n");
        for (final String queueUrl : sqs.listQueues().getQueueUrls()) {
            LOGGER.info("  QueueUrl: " + queueUrl);
        }
    }
}

application.properties

cloud.aws.stack.auto=false
cloud.aws.region.static=ap-southeast-1
logging.level.root=INFO

Logs from above code:

[requestId: MainThread] [INFO] [SQSListenerImpl] [main]   QueueUrl: https://sqs.ap-southeast-1.amazonaws.com/xxxxx/hello-world
[requestId: MainThread] [INFO] [SQSListenerImpl] [main]   QueueUrl: https://sqs.ap-southeast-1.amazonaws.com/xxxxx/some-name2
[requestId: MainThread] [INFO] [SQSListenerImpl] [main]   QueueUrl: https://sqs.ap-southeast-1.amazonaws.com/xxxxx/some-name3
[requestId: MainThread] [WARN] [SimpleMessageListenerContainer] [main] Ignoring queue with name 'hello-world': The queue does not exist.; nested exception is com.amazonaws.services.sqs.model.QueueDoesNotExistException: The specified queue does not exist for this wsdl version. (Service: AmazonSQS; Status Code: 400; Error Code: AWS.SimpleQueueService.NonExistentQueue; Request ID: 3c0108aa-7611-528f-ac69-5eb01fasb9f3)
[requestId: MainThread] [INFO] [Http11NioProtocol] [main] Starting ProtocolHandler ["http-nio-8080"]
[requestId: MainThread] [INFO] [TomcatWebServer] [main] Tomcat started on port(s): 8080 (http) with context path ''
[requestId: MainThread] [INFO] [Startup] [main] Started Startup in 11.391 seconds (JVM running for 12.426)

Aws credentials used are under ~/.aws/ directory.

Now my question is, if sqs.listQueues() can see the queue then why can't @SqsListener? Am I missing something or doing something wrong?

hemant6488
  • 277
  • 3
  • 11

4 Answers4

4

I tried with SpringBoot Aws clound like you and got same error. Then i used the full http url as queue name and got access denied error

@SqsListener(value = "https://sqs.ap-southeast-1.amazonaws.com/xxxxx/hello-world")

So in the end, i end up using AWS SDK directly to get message from SQS

sendon1982
  • 9,982
  • 61
  • 44
2

Here's what I'm doing with Spring Cloud.

Using SPEL I'm attaching a value from my application.properties to the Annotation @SqsListener like this

@SqsListener(value = "#{queueConfiguration.getQueue()}", deletionPolicy = SqsMessageDeletionPolicy.ON_SUCCESS)

One thing to note, make sure you use the full HTTPS path for the queue.

For all local development, I'm using "localstack" and using a local implementation of SQS but the same code applies as it gets deploy in ECS. The other piece to note is that the role or instance needs to be able to Receive Messages via IAM to make this happen.

Benjamen
  • 65
  • 1
  • 5
0

Using full URL worked for me.

@SqsListener("https://sqs.ap-south-1.amazonaws.com/xxxxxxxxx/queue-name")
maddy10
  • 11
  • 2
0

Using below code work for me

@SqsListener(value="https://sqs.us-west-1.amazonaws.com/xxxxx/queue-name")
Procrastinator
  • 2,526
  • 30
  • 27
  • 36