如何从aws sqs fifo队列中读取消息?

时间:2019-06-25 17:15:06

标签: node.js amazon-web-services amazon-sqs aws-sdk-nodejs

我正在尝试使用javascript SDK从SQS Fifo队列中读取信息,
我正在使用AWS SQS SDK的receiveMessage方法进行操作,
但这样做时出现错误。

以下是我正在运行的代码段-

let AWS = require('aws-sdk');
let util = require('util');
AWS.config.update({region: 'us-east-1'});

let test = async() => {
    let sqs = new AWS.SQS();

    let params = {
        QueueUrl: 'sqs.us-east-1.amazonaws.com/awsAccountId/sqsQueueName.fifo'
    };

    let sqsReceiveMessage = util.promisify(sqs.receiveMessage).bind(sqs);
    let messages = await sqsReceiveMessage(params);
    console.log(messages);
};
test();

我遇到以下错误-

(node:13221) UnhandledPromiseRejectionWarning: InvalidAddress: The address sqs.us-east-1.amazonaws.com/awsAccountId/sqsQueueName.fifo is not valid for this endpoint.

以下是SQS队列URL,我正在尝试阅读- enter image description here

我正在使用以下内容作为参考-
1. https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/SQS.html#receiveMessage-property
2. https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/SQS.html#receiveMessage-property
3. https://www.reddit.com/r/aws/comments/5mclde/sqs_cli_aws_sqs_getqueueurl_returns_different_url/
4. https://www.bogotobogo.com/DevOps/AWS/aws-Amazon-SQS-Simple-Queue-Service-with-NodeJS-AWS-SDK.php

1 个答案:

答案 0 :(得分:0)

您是否尝试过在队列名称前使用http://?我不使用node.js,但是在C#中,我给了它完整的URL,包括http://