使用C#将json消息发布到AWS SNS主题

时间:2018-03-27 12:34:40

标签: amazon-web-services aws-sdk amazon-sns

我正在尝试使用AWS SDk从我的C#应用​​程序发布Json消息到AWS SNS主题。其[在此处输入图像描述] [1]以字符串格式填充消息并且未填充消息属性字段。

代码示例如下:

        var snsClient = new AmazonSimpleNotificationServiceClient(accessId, secretrkey, RegionEndpoint.USEast1);
        PublishRequest publishReq = new PublishRequest()
        {
            TargetArn = topicARN,
            MessageStructure = "json",
            Message = JsonConvert.SerializeObject(message)
        };
        var msgAttributes = new Dictionary<string, MessageAttributeValue>();
        var msgAttribute = new MessageAttributeValue();
        msgAttribute.DataType = "String";
        msgAttribute.StringValue = "123";
        msgAttributes.Add("Objectcd", msgAttribute);
        publishReq.MessageAttributes = msgAttributes;
        PublishResponse response = snsClient.Publish(publishReq);

0 个答案:

没有答案