SQS消息始终处于运行状态 [英] SQS Message always stays inflight

查看:163
本文介绍了SQS消息始终处于运行状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码从SQS队列中检索消息.我正在使用AmazonSQSBufferedAsyncClient从Queue检索消息.固定的延迟SingleThreadedExecutor每5分钟唤醒一次,调用receiveMessage.队列中启用了长轮询

I have the following code retrieving messages from a SQS queue. I am using a AmazonSQSBufferedAsyncClient to retrieve the message from Queue. A fixed delay SingleThreadedExecutor wakes up every 5 mins calling receiveMessage. Long polling is enabled in the Queue

@Service
public class AmazonQueueService
    implements QueueService<String> {

    @Autowired
    private AmazonSQSBufferedAsyncClient sqsAsyncClient;

    @Value("${aws.sqs.queueUrl}")
    private String queueUrl;

    @Override
    public List<Message<String>> receiveMessage() {
        ReceiveMessageRequest receiveMessageRequest = new ReceiveMessageRequest(queueUrl);
        ReceiveMessageResult result = sqsAsyncClient.receiveMessage(receiveMessageRequest);

        LOG.debug("Size=" + result.getMessages().size());

        return Lists.transform(result.getMessages(), ......);
    }

    .....
}

问题是,当我检查AWS控制台时,该消息始终在运行中,但在应用程序中从未收到(大小始终打印为0).看起来AmazonSQSBufferedAsyncClient正在从队列中读取消息,但未在receiveMessage调用中返回.

The problem is when I check AWS console, the message is always in-flight, but it is never received in the application (Size is always printed as 0) . Looks like the AmazonSQSBufferedAsyncClient is reading the message from queue but not returning in the receiveMessage call.

有什么想法吗?

推荐答案

最后弄清楚了这一点.该问题通过队列可见性超时(2分钟)和ScheduledExecutor延迟(5分钟)的组合来体现.

Finally figured this out. The problem manifests with the combination of queue visibility timeout (2 mins) and the scheduledExecutor delay (5 mins).

将可见性超时时间增加到15分钟即可解决此问题.

Increasing the visibility timeout to 15 mins solved the problem.

我的理论是-> AmazonSQSBufferedAsyncClient检索消息并将其保留在缓冲区中,以等待receiveMessage调用.由于执行程序延迟为5分钟,因此消息的可见性在调用receiveMessage之前超时,并且消息返回到队列中.看起来该消息几乎是立即从队列中拾取的.现在,无论出于何种原因,对receiveMessage的调用都不会接收到该消息.我猜想,增加超时可以使receiveMessage调用有机会在超时事件之前发生,从而解决了这个问题.

My theory is -> The AmazonSQSBufferedAsyncClient retrieves message and keeps it in the buffer waiting for receiveMessage call. As the executor delay is 5 mins, the visibility of the message times out befor receiveMessage is called and the message is returned to the queue. It also looks like the message is picked from the queue almost immediately. And now for whatever reason a call to receiveMessage does not receive the message. Increasing the timeout which gave a chance for the receiveMessage call to happen before a timeout event, solved the problem, I guess.

还有其他可能的解释吗?

Any other possible explanation?

这篇关于SQS消息始终处于运行状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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