如何在.net中使用过滤器策略创建SNS订阅?

ruyhziif  于 2023-05-30  发布在  .NET
关注(0)|答案(1)|浏览(125)

你能帮帮我吗我试图通过代码使用过滤器策略在. net中创建一个SNS订阅。我的主题具有以下订阅筛选器策略(使用MessageAttribute):
enter image description here
我尝试配置如下:

public async Task CreateSubscriptionAsync()
    {
        using var snsClient = new AmazonSimpleNotificationServiceClient(_amazonSimpleNotificationServiceConfig);

        _ = await snsClient.SubscribeAsync(new SubscribeRequest
        {
            Protocol = "sqs",
            Endpoint = _sqsSettings.Queues!.First(queue => !queue.Consume).Url,
            TopicArn = _snsSettings.Topic!.Arn,
            Attributes = new Dictionary<string, string>() { { "MessageType", "OrderReceived" } }
        });
    }

但我收到以下错误:
Amazon.SimpleNotificationService.Model.InvalidParameterException:AttributeName。
你能帮帮我吗?

4szc88ey

4szc88ey1#

做的人,按照答案:

public async Task CreateSubscriptionAsync()
    {
        using var snsClient = new AmazonSimpleNotificationServiceClient(_amazonSimpleNotificationServiceConfig);

        _ = await snsClient.SubscribeAsync(new SubscribeRequest
        {
            Protocol = "sqs",
            Endpoint = _sqsSettings.Queues!.First(queue => !queue.Consume).Url,
            TopicArn = _snsSettings.Topic!.Arn,
            Attributes = new Dictionary<string, string>() { { "FilterPolicy", "{\"MessageType\":[\"OrderReceived\"]}" } }
        });
    }

相关问题