【问题标题】:How to send SQS message asynchronously in python?如何在python中异步发送SQS消息?
【发布时间】:2018-03-30 23:21:24
【问题描述】:

这是我现在的 Python 代码:

sqs = boto3.resource('sqs')
queue = sqs.get_queue_by_name(Queue='test')
msg = 'hello world'
for i in range(0,1000):
    queue.send_message(MessageBody = msg)
    print("Message Sent")

这里是 Node.js 版本:

var sqs = new AWS.SQS({apiVersion: '2012-11-05'});
var params = {
    MessageBody: 'hello world',
    QueueUrl: // Queue URL here
};
for(var i = 0; i < 1000; i++){
    sqs.sendMessage(params, function(err,data){
        if(err){
            throw err;
        } else {
            console.log("Message Sent");
        }
    })
}

我的问题是使用 Python 脚本发送 1000 条消息需要更长的时间,因为它是同步运行的,而 Node.js 是异步运行的。我到处寻找,似乎找不到任何在 Python 中异步发送消息的方法。将不胜感激。

【问题讨论】:

    标签: python node.js amazon-web-services asynchronous amazon-sqs


    【解决方案1】:

    boto3 库不支持异步调用。有一个库支持 S3,并在 SQS 上进行了一些测试,称为 aiobotocore。这些链接包含更多信息:

    aiobotocore

    Support asyncio

    【讨论】:

    • 谢谢。我会调查这些。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-04-05
    • 1970-01-01
    • 2019-05-31
    • 1970-01-01
    • 2013-02-03
    • 2010-12-12
    相关资源
    最近更新 更多