我很难收集包含这三个元素的元组:
let create_task = |msg| {
// We need to keep the message_id to report failures to SQS
// and the receipt_handle to delete the processed messages from SQS.
let SqsMessageObj {
message_id,
body,
receipt_handle,
..
} = msg;
let span = tracing::span!(tracing::Level::INFO, "Handling SQS msg", message_id);
let task = async {
let item = serde_json::from_value(body)?;
f(item, app_config).await
};
(
message_id.unwrap_or_default(),
receipt_handle.unwrap_or_default(),
task,
)
};
print!("{:?}", event.payload);
let (ids, receipts, tasks) = event.payload.records.into_iter().map(create_task).collect();
这是基于使用 Rust lambda 进行高级 SQS 批处理的 AWS-labs 示例代码。
我已经尝试过this thread的解决方案,但似乎我得到了一个嵌套的元组。有什么线索吗?
unzip()
与嵌套元组一起使用:
let create_task = |msg| {
// We need to keep the message_id to report failures to SQS
let SqsMessageObj {
message_id,
body,
message_attributes,
receipt_handle,
..
} = msg;
let span = tracing::span!(tracing::Level::INFO, "Handling SQS msg", message_id);
let task = async {
let item = serde_json::from_value(body)?;
f(item, app_config).await
};
(
(
message_id.unwrap_or_default(),
receipt_handle.unwrap_or_default(),
),
task,
)
};
print!("{:?}", event.payload);
let ((ids, receipts), tasks) = event.payload.records.into_iter().map(create_task).unzip();