AWS Java SDK:调用AmazonSQSClient.receiveMessage时出现AbortedException [英] AWS Java SDK: AbortedException on call to AmazonSQSClient.receiveMessage

查看:405
本文介绍了AWS Java SDK:调用AmazonSQSClient.receiveMessage时出现AbortedException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正试图从EC2实例上运行的Java程序的Amazon SQS队列中读取.有时,我们会得到一个com.amazonaws.AbortedException.我们的代码如下:

We are trying to read from an Amazon SQS Queue from a Java program running on an EC2 instance. On occasion, we get a com.amazonaws.AbortedException. Our code looks like this:

AmazonSQSClient sqs = new AmazonSQSClient(myCredentials);
ReceiveMessageRequest request = new ReceiveMessageRequest()
            .withWaitTimeSeconds(20)
            .withMaxNumberOfMessages(1)
            .withQueueUrl(queueUrl);
ReceiveMessageResult result = sqs.receiveMessage(request);

我们的堆栈跟踪如下:

com.amazonaws.AbortedException: 
at com.amazonaws.internal.SdkFilterInputStream.abortIfNeeded(SdkFilterInputStream.java:51)
at com.amazonaws.internal.SdkFilterInputStream.read(SdkFilterInputStream.java:65)
at com.amazonaws.event.ProgressInputStream.read(ProgressInputStream.java:159)
at com.sun.org.apache.xerces.internal.impl.XMLEntityManager$RewindableInputStream.read(XMLEntityManager.java:2890)
at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.setupCurrentEntity(XMLEntityManager.java:674)
at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.startEntity(XMLEntityManager.java:1304)
at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.startDocumentEntity(XMLEntityManager.java:1255)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.setInputSource(XMLDocumentScannerImpl.java:253)
at com.sun.org.apache.xerces.internal.impl.XMLStreamReaderImpl.setInputSource(XMLStreamReaderImpl.java:199)
at com.sun.org.apache.xerces.internal.impl.XMLStreamReaderImpl.<init>(XMLStreamReaderImpl.java:184)
at com.sun.xml.internal.stream.XMLInputFactoryImpl.getXMLStreamReaderImpl(XMLInputFactoryImpl.java:277)
at com.sun.xml.internal.stream.XMLInputFactoryImpl.createXMLStreamReader(XMLInputFactoryImpl.java:129)
at com.sun.xml.internal.stream.XMLInputFactoryImpl.createXMLEventReader(XMLInputFactoryImpl.java:78)
at com.amazonaws.http.StaxResponseHandler.handle(StaxResponseHandler.java:91)
at com.amazonaws.http.StaxResponseHandler.handle(StaxResponseHandler.java:43)
at com.amazonaws.http.response.AwsResponseHandlerAdapter.handle(AwsResponseHandlerAdapter.java:70)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.handleResponse(AmazonHttpClient.java:1501)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeOneRequest(AmazonHttpClient.java:1222)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeHelper(AmazonHttpClient.java:1035)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.doExecute(AmazonHttpClient.java:747)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeWithTimer(AmazonHttpClient.java:721)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.execute(AmazonHttpClient.java:704)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.access$500(AmazonHttpClient.java:672)
at com.amazonaws.http.AmazonHttpClient$RequestExecutionBuilderImpl.execute(AmazonHttpClient.java:654)
at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:518)
at com.amazonaws.services.sqs.AmazonSQSClient.doInvoke(AmazonSQSClient.java:1663)
at com.amazonaws.services.sqs.AmazonSQSClient.invoke(AmazonSQSClient.java:1639)
at com.amazonaws.services.sqs.AmazonSQSClient.receiveMessage(AmazonSQSClient.java:1269)
at <our code>

com.amazonaws.services.sqs.AmazonSQSClient的文档没有告诉我们期望AbortedException.

The documentation for com.amazonaws.services.sqs.AmazonSQSClient does not tell us to expect an AbortedException.

我们正在使用SDK版本1.11.77.

We are using SDK version 1.11.77.

任何帮助将不胜感激.谢谢.

Any help would be appreciated. Thanks.

推荐答案

尽管 AWS异常处理docs 这样说:

Though the javadoc on AbortedException is sparse, it is a subclass of AmazonClientException & RuntimeException (which do not have to be declared). Also, the AWS Exception handling docs says this:

AmazonClientException表示在尝试向AWS发送请求或尝试从AWS解析响应时,Java客户端代码内部发生问题.通常,AmazonClientException比AmazonServiceException更为严重,它表示一个主要问题,该问题阻止客户端对AWS服务进行服务调用.例如,当您尝试在一个客户端上调用操作时,如果没有网络连接可用,则适用于Java的AWS开发工具包将引发AmazonClientException.

AmazonClientException indicates that a problem occurred inside the Java client code, either while trying to send a request to AWS or while trying to parse a response from AWS. An AmazonClientException is generally more severe than an AmazonServiceException, and indicates a major problem that is preventing the client from making service calls to AWS services. For example, the AWS SDK for Java throws an AmazonClientException if no network connection is available when you try to call an operation on one of the clients.

当SDK处理InterruptedException时,通常会抛出

AbortedException(即:

AbortedException is generally thrown when the SDK handles an InterruptedException (ie: the thread was signalled to stop doing work). For your purposes though, you probably just want to retry the operation.

(如果您是执行显式Thread.interrupt导致这种情况的人,则取决于您要如何进行-将其视为停止工作的信号,或者只是重试该操作)

(If you're the one doing the explicit Thread.interrupt to cause this though, then it's up to you on how you want to proceed - either treat it as a signal to stop work, or just retry the operation)

这篇关于AWS Java SDK:调用AmazonSQSClient.receiveMessage时出现AbortedException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆