AWS.SimpleQueueService.NonExistentQueue exception when accessing an existing SQS queue

I am relatively new to AWS SQS. I wrote some code to wrap the Amazon SQS api.

I can perform basic functions with the created queues, but despite this (in fact, I use this code permanently without problems, and I create JUnit tests as a formality), I fail in my JUnit testing due to an error that does not makes no sense to me.

I created the SerenaQForTest queue names using the AWS management console. When I look at the AWS console, I see that the queue I specified is indicated. I set queue permissions for each. I am coding in Java.

When I try to interact with the queue, I get an AmazonServiceException with the error code AWS.SimpleQueueService.NonExistentQueueerror.

Here is my code.

In the Junit class:

/** * Prefix for queues used to run junit tests. */ private static final String TESTQ = "SerenaForTest"; /** * Ensures that the queue exists. */ @Test public void testExists() { System.out.println("JUnit Test EXISTS."); CloudSQS cloudsqs = new CloudSQS(); // this queue does exist and i can see it through the aws management console in sqs assertTrue(cloudsqs.exists(TESTQ)); // this queue does not exist. assertTrue(cloudsqs.exists("thisQDoesNotExist") == false); } 

and exists () is defined as follows:

 /** * Determines if the queue exists or not. * * @param qName * , name of the queue to determine existence of. * @return boolean, true if the queue exists; false otherwise. */ public boolean exists(final String qName) { boolean retVal = false; try { // create a request for the url of qName GetQueueUrlRequest getQueueUrlRequest = new GetQueueUrlRequest(qName); String addy = sqs.getQueueUrl(getQueueUrlRequest).getQueueUrl(); System.out.println(qName + " url : " + addy); if (addy != null) { // get all queues on sqs ListQueuesResult queues = sqs.listQueues(); // for each url, for (String url : queues.getQueueUrls()) { // System.out.println("Comparing " + addy + " and " + url); if (url.equalsIgnoreCase(addy)) { System.out.println("Queue exists."); retVal = true; break; } } } else { System.out.println("Queue " + qName + " does not exist."); } } catch (AmazonServiceException ase) { System.err.println("ERR: AmazonServiceException. Error code: " + ase.getErrorCode()); } catch (AmazonClientException ace) { System.err.println("ERR: AmazonClientException."); ace.printStackTrace(); } catch (Exception e) { System.err.println("ERR: Regular Old Error."); e.printStackTrace(); } return retVal; } 

Console output:


JUnit Test EXISTS. SerenaForTest URL: https://sqs.us-west-2.amazonaws.com/079023477467/SerenaForTest The queue exists. ERR: AmazonServiceException. Error Code: AWS.SimpleQueueService.NonExistentQueue

Here is the stack:

AmazonServiceException: Status code: 400, AWS: AmazonSQS, AWS Request ID: a2809a40-223f-5c4d-b369-d0c3301a8e4e, AWS Error code: AWS.SimpleQueueService.NonExistentQueue, AWS Error message: The specified queue does not exist for this. at com.amazonaws.http.AmazonHttpClient.handleErrorResponse (AmazonHttpClient.java:644) at com.amazonaws.http.AmazonHttpClient.executeHelper (AmazonHttpClient.javahaps38) at com.amazonaws.http.Ahex1.90 ) at com.amazonaws.services.sqs.AmazonSQSClient.invoke (AmazonSQSClient.java:875) at com.amazonaws.services.sqs.AmazonSQSClient.getQueueUrl (AmazonSQSClient.java data64) in com.tutelatechnologies.SQLiteConverterQoud. exists (CloudSQS.javahaps01) in com.tutelatechnologies.SQLiteConverter.cloud.CloudSQSTest.testExists (CloudSQSTest.java:169) at sun.reflect.NativeMethodAccessorImpl.invoke0 (native method) at sun.reflect.NativeMethodAccessorplpl.ccessplpl.ccessplpl.ccessplpl.ccessplpl.ccessplpl.ccessplpl.accessorploplccessplot.ccessmodelccessplot java: 57) at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43) in java.lang.reflect.Method.invoke (Method.java:601) on org.junit.runners.model.FrameworkMethod $ 1.runReflective FrameworkMethod.java:45 ) at org.junit.internal.runners.model.ReflectiveCallable.run (ReflectiveCallable.java:15) at org.junit.runners.model.FrameworkMethod.invokeExplosively (FrameworkMethod.java:42) at org.junit.internal.runners. statements.InvokeMethod.evaluate (InvokeMethod.java:20) at org.junit.internal.runners.statements.RunBefores.evaluate (RunBefores.java:28) at org.junit.internal.runners.statements.RunAfters.evaluate (RunAfters. java: 30) on org.junit.runners.ParentRunner.runLeaf (ParentRunner.java:263) on org.junit.runners.BlockJUnit4ClassRunner.runChild (BlockJUnit4ClassRunner.java:ununRunnersRlockersBlocknerJlocknerJlocknerBlockRunnerBLlockJL .java: 47) at org.junit.runners.ParentRunner $ 3.run (ParentRunner.java:231) at org.junit.runners.ParentRunner $ 1.schedule (ParentRunner.java:60) at org.junit.runners.ParentRunner. runChildren (ParentRunner.java:229) at org.junit.runners.ParentRunner.access $ 000 (ParentRunner.java:50) at org.junit.runners.ParentRu nner $ 2.value (ParentRunner.java:222) on org.junit.internal.runners.statements.RunBefores.evaluate (RunBefores.java:28) on org.junit.internal.runners.statements.RunAfters.evaluate (RunAfters.java : 30) on org.junit.runners.ParentRunner.run (ParentRunner.java data 00) on org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run (JUnit4TestReference.java:50) at org.eclipse.jdt. internal.junit.runner.TestExecution.run (TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests (RemoteTestRunner.java:467) at org.eclipse.jdt.internal.junit. runner.RemoteTestRunner.runTests (RemoteTestRunner.java:683) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run (RemoteTestRunner.javahaps90) at org.eclipse.jdt.internal.junemrnernernernernernernernernernernernernernernerner main (RemoteTestRunner.java:197)

From this, you can see that the function is able to grab the queue URL and find a match. But that still rules out.

Does anyone have any idea why this is happening? I call exists () every time I need to drop something or do something from the queue, so it doesn’t actually run all my JUnit tests, but for the same reasons.

Thanks in advance!

+6
source share
3 answers

I came across the same problem. The solution is pretty simple after reading Java docs more thoroughly :) Just set client.setEndPoint(...) when creating SQSClient

 sqsClient = new AmazonSQSClient( credentials ); sqsClient.setEndpoint("sqs.eu-west-1.amazonaws.com"); 

Endpoint Values ​​Found in AWS Link

+5
source

Are you sure that the queue you created is in the same region where your Java SQS client is going? The default scope in the AWS SDK for Java is US-East-1. You can check your queue area by looking at the management console in the upper right corner.

+4
source

I believe listQueues() will fail if you use credentials that do not have permission for all queues (at least that was the problem at some point).

0
source

Source: https://habr.com/ru/post/951431/


All Articles