2017-10-19 157 views
0

这里是我的Python代码现在:如何在python中异步发送SQS消息?

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中异步发送消息。洞察力将不胜感激。

回答

0

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

aiobotocore

Support asyncio

+0

谢谢。我会研究这些。 – Matt