Java 访问现有 SQS 队列时抛出 AWS.SimpleQueueService.NonExistentQueue 异常
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18157167/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
AWS.SimpleQueueService.NonExistentQueue Exception thrown when Accessing Existing SQS queue
提问by miss.serena
I am relatively new to AWS SQS services. I have written some code to wrap the Amazon SQS api.
我对 AWS SQS 服务比较陌生。我编写了一些代码来包装 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.
我能够使用创建的队列执行基本功能,但尽管如此(事实上,我一直在使用这段代码,没有任何问题,我正在创建 JUnit 测试作为一种形式),我的 JUnit 测试失败了,因为一个错误对我来说毫无意义。
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.
我使用 AWS 管理控制台创建了一个名为 SerenaQForTest 的队列。当我查看 AWS 控制台时,我可以看到我创建的队列已列出。我已将队列的权限设置为对所有人开放。我正在用 Java 编码。
When I try to interact with the queue, I get an AmazonServiceException with error code AWS.SimpleQueueService.NonExistentQueueerror.
当我尝试与队列交互时,我收到错误代码为 AWS.SimpleQueueService.NonExistentQueueerror 的 AmazonServiceException。
Here is my code.
这是我的代码。
In the Junit Class:
在 Junit 类中:
/**
* 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:
和exists()定义如下:
/**
* 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/SerenaForTestQueue exists. ERR: AmazonServiceException. Error code: AWS.SimpleQueueService.NonExistentQueue
JUnit 测试存在。SerenaForTest 网址:https://sqs.us-west-2.amazonaws.com/079023477467/SerenaForTest 队列存在。错误:亚马逊服务异常。错误代码:AWS.SimpleQueueService.NonExistentQueue
Here is the stacktrace:
这是堆栈跟踪:
AmazonServiceException: Status Code: 400, AWS Service: 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 wsdl version. at com.amazonaws.http.AmazonHttpClient.handleErrorResponse(AmazonHttpClient.java:644) at com.amazonaws.http.AmazonHttpClient.executeHelper(AmazonHttpClient.java:338) at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:190) at com.amazonaws.services.sqs.AmazonSQSClient.invoke(AmazonSQSClient.java:875) at com.amazonaws.services.sqs.AmazonSQSClient.getQueueUrl(AmazonSQSClient.java:364) at com.tutelatechnologies.SQLiteConverter.cloud.CloudSQS.exists(CloudSQS.java:301) at com.tutelatechnologies.SQLiteConverter.cloud.CloudSQSTest.testExists(CloudSQSTest.java:169) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:601) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(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) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.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.ParentRunner$2.evaluate(ParentRunner.java:222) at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28) at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:30) at org.junit.runners.ParentRunner.run(ParentRunner.java:300) at 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.java:390) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
AmazonServiceException:状态代码:400,AWS 服务:AmazonSQS,AWS 请求 ID:a2809a40-223f-5c4d-b369-d0c3301a8e4e,AWS 错误代码:AWS.SimpleQueueService.NonExistentQueue,AWS 错误消息:此 wsdl 版本不存在指定的队列. 在 com.amazonaws.http.AmazonHttpClient.handleErrorResponse(AmazonHttpClient.java:644) 在 com.amazonaws.http.AmazonHttpClient.executeHelper(AmazonHttpClient.java:338) 在 com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:190) ) 在 com.amazonaws.services.sqs.AmazonSQSClient.invoke(AmazonSQSClient.java:875) 在 com.amazonaws.services.sqs.AmazonSQSClient.getQueueUrl(AmazonSQSClient.java:364) 在 com.tutelatechnologies.SQLiteConverter.cloud.CloudS在 com.tutelatetechnologies.SQLiteConverter.cloud.CloudSQSTest.testExists(CloudSQSTest.java:
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.
从中您可以看到该函数能够获取队列 URL 并找到匹配项。但它仍然抛出异常。
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.
任何人都知道为什么会发生这种情况?每次我需要向队列中扔东西或从队列中取出东西时,我都会调用exists(),因此它实际上使我的所有JUnit 测试都失败了,但出于相同的原因。
Thanks in advance!!!
提前致谢!!!
回答by Rob
I believe that listQueues()
will fail if you are using credentials that don't have permission for all of the queues (at least this was an issue at some point).
我相信listQueues()
如果您使用的凭据没有对所有队列的许可(至少在某些时候这是一个问题),那将会失败。
回答by Wade Matveyenko
Are you sure that the queue you created is in the same region that your Java SQS client is going to? The default region in the AWS SDK for Java is US-East-1. You can verify your queue's region by looking at the management console in the top right.
您确定您创建的队列与您的 Java SQS 客户端所在的区域位于同一区域吗?适用于 Java 的 AWS 开发工具包中的默认区域是 US-East-1。您可以通过查看右上角的管理控制台来验证队列的区域。
回答by Srikar Appalaraju
Stumbled on the same problem. Solution is pretty simple after reading the Java docs more carefully :)
Simply set client.setEndPoint(...)
when creating your SQSClient
偶然发现了同样的问题。更仔细地阅读 Java 文档后,解决方案非常简单:)client.setEndPoint(...)
在创建 SQSClient 时只需设置
sqsClient = new AmazonSQSClient( credentials );
sqsClient.setEndpoint("sqs.eu-west-1.amazonaws.com");
Endpoint values found at AWS Link
在AWS Link 中找到的端点值