首页 > 解决方案 > AWS SNS 发布:无法为 Node.js 发布 FIFO 消息

问题描述

发布消息的功能


 this.sns = new SNS({ apiVersion: '2010-03-31', region: <region> });

    async publishMessage() {
        try {
            const params = {
            MessageGroupId: 'test',
            MessageDeduplicationId: uuidv4(),
            Message: 'test',
            TopicArn: 'arn:aws:sns:<region>:<accountID>:item-dev-topic.fifo',
        };

            const res = await this.sns.listTopics().promise();
            // Works : this returns the topic which I plan to use

            const response = await this.sns.publish(params).promise();
            // Fails : this line gives error saying multiple invalid param (MessageGroupId, MessageDeduplicationId) 

            console.log(response);
            return res;
        } 

       catch (error) {
            throw new Error(error);
        }
    }

错误:说多个无效参数(MessageGroupId,MessageDeduplicationId) 当我删除此参数时,它说这些参数丢失,当我添加这些参数时,它说无效参数。

观察:

  1. 这适用于不是 Fifo 的 SNS 主题
  2. 列表主题适用于 Fifo 和标准 SNS 主题,它包括我所需的 SNS 主题

标签: amazon-web-servicesamazon-sqsamazon-sns

解决方案


将 AWS 开发工具包升级到最新版本修复了这个重大问题

出现错误的 SDK 版本:v2.744.0

升级到v2.784.0解决了上述问题


推荐阅读