AWS.SimpleQueueService.NonExistentQueue Exception thrown when Accessing
Existing SQS queue
I am relatively new to AWS SQS services. I have written some code to wrap
the Amazon SQS api.
I am able perform basic functionality with created queues, but despite
that (in fact I have been using this code for ever with no problem, and I
am creating JUnit tests as a formality), I am failing my JUnit test
because of an error that makes little sense to me.
I have created a queue names SerenaQForTest using the AWS Management
console. When I look at the AWS Console I can see that the queue I have
created is listed. I have set the permissions on the queue to open for
everyone. I am coding in Java.
When I try to interact with the queue, I get an AmazonServiceException
with 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 Queue
exists. ERR: AmazonServiceException. Error code:
AWS.SimpleQueueService.NonExistentQueue
From that you can see that the function is able to grab the queue URL and
that a match is found. But it still throws an exception.
Any one have any ideas why this is happening? I call exists() every time I
need to throw something on or take something off of the queue so its
actually failing all of my JUnit tests but for the same reasons.
Thanks in advance!!!
Nice blog! Keep update and share AWS Online Course
ReplyDelete