英文:
AWS SQS polling
问题
I don't understand the need to configure short and long polling directly on the queue. Say I create an sqs queue and I want to check the queue for messages once every hour with java. Then I just need to create a method annotated with @Scheduled(fixedRate = 3600000) and in the method I call sqsClient.receiveMessage and that's it. If I want short polling then I can just reduce the fixedRate to call my method every 5 seconds for example.
我不理解为什么需要直接在队列上配置短轮询和长轮询。比如,我创建了一个 SQS 队列,我想每小时用 Java 检查队列中的消息。然后,我只需要创建一个带有 @Scheduled(fixedRate = 3600000) 注解的方法,在该方法中调用 sqsClient.receiveMessage 就可以了。如果我想要短轮询,我可以将 fixedRate 缩短,例如每 5 秒调用一次我的方法。
I already read:
> waitTimeSeconds(): The duration (in seconds) for which the call waits
> for a message to arrive in the queue before returning.
>
> When passing a value for waitTimeSeconds (maximum of 20 seconds), the
> call will block while there are no messages available in the queue.
> However, if there is a message (or a message comes during that time
> period), it will immediately return with messages.
我已经阅读过:
> waitTimeSeconds():调用在返回之前等待消息到达队列的持续时间(以秒为单位)。
>
> 当传递 waitTimeSeconds 的值(最长为 20 秒)时,如果队列中没有可用的消息,调用将会阻塞。然而,如果在这段时间内有消息到达(或者在此期间有消息到达),它将立即返回带有消息。
What is it, another polling configuration within my polling configuration with @Scheduled? I don't get it. Also the max value is 20 seconds and I really don't need to check my queue that frequently. So do I just set Receive message wait time to 1 so I get the specificities of long polling (check all servers for messages) and ignore its existence because I don't need it? What is the usecase of it?
这是什么意思,是我的 @Scheduled 轮询配置中的另一种轮询配置吗?我不明白。而且最大值是 20 秒,我确实不需要那么频繁地检查我的队列。所以我只需将接收消息等待时间设置为 1,以获得长轮询的特性(检查所有服务器的消息),并忽略它的存在,因为我不需要它吗?它的用例是什么?
英文:
I don't understand the need to configure short and long polling directly on the queue.
Say I create an sqs queue and I want to check the queue for messages once every hour with java.
Then I just need to create a method annotated with @Scheduled(fixedRate = 3600000) and in the method I call sqsClient.receiveMessage and that's it.
If I want short polling then I can just reduce the fixedRate to call my method every 5 seconds for example.
I already read:
> waitTimeSeconds(): The duration (in seconds) for which the call waits
> for a message to arrive in the queue before returning.
>
> When passing a value for waitTimeSeconds (maximum of 20 seconds), the
> call will block while there are no messages available in the queue.
> However, if there is a message (or a message comes during that time
> period), it will immediately return with messages.
What is it, another polling configuration within my polling configuration with @Scheduled ? I don't get it. Also the max value is 20 seconds and I really don't need to check my queue that frequently.
So do I just set Receive message wait time to 1 so I get the specificities of long polling (check all servers for messages) and ignore its existence because I don't need it ?
What is the usecase of it ?
答案1
得分: 3
如果您的需求是每小时检查消息,则 waitTimeSeconds()
对您来说不相关。
通常在高流量情况下使用,其中需要连续获取消息。为此,编写一个'消费者'来持续轮询队列。为了减少调用次数,可以指定最多等待 20 秒。
通过指定等待时间,它表示:“如果队列中没有消息,请等待 20 秒然后再对此 API 调用提供响应。但是,如果有消息可用,请立即返回。”
用例是一个希望在消息进入队列时能够快速响应的系统。
英文:
If your requirement is to check for messages every hour, then waitTimeSeconds()
is not relevant for you.
It is normally used in high-volume situations where messages are continuously wanted. For this, a 'consumer' is written that keeps polling the queue. To minimise the number of calls, a Wait Time of up to 20 seconds can be specified.
By specifying a Wait Time it is saying: "If there are no messages in the queue, wait 20 seconds before providing a response to this API call. However, please return immediately if a message becomes available."
The use-case would be for a system that wants to respond very quickly when a message enters the queue.
答案2
得分: 0
短轮询是在客户端希望尽快获取/处理每条消息(低延迟)时使用的。长轮询是当AWS等待X秒,然后轮询请求返回数据时使用的。这种方法很少使用,因为需要等待超时才能处理消息。理论上,这可能会在队列完全加载的情况下产生更高的吞吐量,但这种情况相当罕见。
英文:
Short polling, is used when 'the client' wants to get/process every message as fast as possible (low latency).
Long polling is used when AWS wait for X seconds, before the poll request returns data. This is rarely used, as it required a timeout to occur before the messages are processed. Theoretically, this may yield higher throughput, but only in scenarios where the queue is fully loaded, which is quite rare.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论