Amazon SQS 超过 2GB 的数据

Amazon SQS more than 2GB data

正在使用 SQS 对来自客户端的一些上传进行排队。我遇到以下错误:

com.amazonaws.services.sqs.model.AmazonSQSException: One or more parameters are invalid. Reason: Message must be shorter than 262144 bytes. (Service: AmazonSQS; Status Code: 400; Error Code: InvalidParameterValue; Request ID:

我正在使用扩展客户端库。以下是我用来发送消息的代码:

MessageAttributeValue msgAttr = new MessageAttributeValue();
byte [] byteArr=attachment.getBytes();
ByteBuffer buf = ByteBuffer.wrap(byteArr);
msgAttr.setBinaryValue(buf);
msgAttr.setDataType("Binary");
smr.addMessageAttributesEntry("attachment", msgAttr);

根据 Amazon SQS 的 Limits Related to Messages 文档:

Message size
The minimum message size is 1 byte (1 character). The maximum is 262,144 bytes (256 KB).

To send messages larger than 256 KB, you can use the Amazon SQS Extended Client Library for Java. This library allows you to send an Amazon SQS message that contains a reference to a message payload in Amazon S3. The maximum payload size is 2 GB.

库基本上将数据存储在 Amazon S3 中,然后将引用插入到 Amazon SQS 消息中。

无论出于何种原因,图书馆对附件强制执行 2GB 的限制。您可以尝试 修改代码 以处理更大的文件,或者您可以 编写自己的代码 将对象存储在 Amazon S3 中并简单地在 Amazon SQS 消息中包含对 amazon S3 对象的引用。