gpt4 book ai didi

java - SQS 可见性超时会锁定整个队列,而不仅仅是特定的消息

转载 作者:行者123 更新时间:2023-11-30 02:19:01 25 4
gpt4 key购买 nike

我正忙于尝试 SQS。根据我的理解,可见性超时会使消息在可见性超时时间内对其他消费者不可用。但根据我的经验,情况似乎并非如此。可见性超时似乎导致该队列中的所有消息都不可用。

我有代码证实了这一点:

        SendMessageRequest messageRequest = new SendMessageRequest()
.withMessageBody("first one")
.withMessageDeduplicationId(UUID.randomUUID().toString())
.withQueueUrl(queueAddress)
.withMessageGroupId("test1");

sqs.sendMessage(messageRequest);

messageRequest = new SendMessageRequest()
.withMessageBody("second one")
.withMessageDeduplicationId(UUID.randomUUID().toString())
.withQueueUrl(queueAddress)
.withMessageGroupId("test1");

sqs.sendMessage(messageRequest);

ReceiveMessageRequest receiveMessageRequest = new ReceiveMessageRequest(queueAddress);

new Thread(() -> {
System.out.println("t1");
List<Message> messages = sqs.receiveMessage(receiveMessageRequest
.withMaxNumberOfMessages(1)
.withMessageAttributeNames("All")
.withVisibilityTimeout(5)
.withWaitTimeSeconds(1)
).getMessages();
System.out.println(messages.get(0).getBody());
}).start();

new Thread(() -> {
System.out.println("t2");
List<Message> messages = sqs.receiveMessage(receiveMessageRequest
.withMaxNumberOfMessages(1)
.withMessageAttributeNames("All")
.withVisibilityTimeout(5)
.withWaitTimeSeconds(1)
).getMessages();
System.out.println(messages.get(0).getBody());
}).start();

发生的情况是第二个线程抛出 IndexOutOfBoundsException。这是因为没有可用的消息。这证实了可见性超时会影响整个队列,而不仅仅是消息。

不幸的是,这似乎与亚马逊的文档不符。

如果有人对为什么会出现这种情况有任何见解,或者如果我误用了 SQS SDK,请告诉我:)

最佳答案

嗯,看起来我看不懂 documentation正确)::

When you receive a message with a message group ID, no more messages for the same message group ID are returned unless you delete the message or it becomes visible.

关于java - SQS 可见性超时会锁定整个队列,而不仅仅是特定的消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47392243/

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