gpt4 book ai didi

java - AWS Java SDK : AbortedException on call to AmazonSQSClient. 接收消息

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:31:36 24 4
gpt4 key购买 nike

我们正在尝试从 EC2 实例上运行的 Java 程序读取 Amazon SQS 队列。有时,我们会收到 com.amazonaws.AbortedException。我们的代码如下所示:

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。

我们使用的是 SDK 版本 1.11.77。

如有任何帮助,我们将不胜感激。谢谢。

最佳答案

虽然 AbortedException 上的 javadoc是稀疏的,它是 AmazonClientExceptionRuntimeException 的子类(不必声明)。此外,AWS Exception handling docs是这样说的:

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.

AbortedException 通常在 SDK 处理 InterruptedException 时抛出(即:the thread was signalled to stop doing work)。不过,出于您的目的,您可能只想重试该操作。

(如果您是执行显式 Thread.interrupt 的人,那么这取决于您如何继续 - 要么将其视为停止工作的信号,或者只是重试操作)

关于java - AWS Java SDK : AbortedException on call to AmazonSQSClient. 接收消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51050268/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com