sqs在接收消息时没有给我MessageAttributes

时间:2018-02-22 12:35:09

标签: node.js amazon-sqs

我已经编写了以下API来接收消息:

app.get('/receive', function(req, res) {
    var params = {
        QueueUrl: queueUrl,
        VisibilityTimeout: 600
    };

    sqs.receiveMessage(params, function(err, data) {
        if (err) {
            res.send(err);
        } else {
            console.log('data is ' + JSON.stringify(data));
            res.send(data);
        }
    });
});

我得到的回应如下:

{
    "ResponseMetadata": {
        "RequestId": "id"
    },
    "Messages": [
        {
            "MessageId": "id",
            "ReceiptHandle": "handle",
            "MD5OfBody": "body",
            "Body": "body"
        }
    ]
}

API的发送消息格式如下所示:

 let params = {
                       MessageBody: object,
                       QueueUrl: process.env.queueUrl,
                        MessageAttributes:{
                           "Title":{
                               DataType:'String',
                               StringValue:'Item Id Array',
                           }
                        },
                       DelaySeconds: 0
                   }
                   sqs.send(params, (err, data) => {
                       console.log('------------the send message data is------------',err,data);
                   });

1 个答案:

答案 0 :(得分:2)

您必须告诉SQS您希望在传递给params函数的参数中接收哪些属性。

因此,在/receive路由中,var params = { QueueUrl: queueUrl, VisibilityTimeout: 600, MessageAttributeNames: ["All"], }; 路由中的func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { let storyboard = UIStoryboard(name: "YourStoryBoardName", bundle: nil) let controller = storyboard.instantiateViewController(withIdentifier: "pdfDisplayViewController") as! pdfDisplayViewController self.navigationController?.pushViewController(controller, animated: false) self.navigationController?.navigationBar.isHidden = true } 定义可能如下所示:

this.person = this.formBuilder.group({
      name:[],
      age:[]
      customAttributes: this.formBuilder.group({

      }

有关详细信息,请查看以下链接:

  1. JavaScript SQS Example
  2. “调用receiveMessage操作”示例AWS JavaScript SDK doc
  3. AWS SQS API doc
  4. 中的“MessageAttributeName.N”参数