Amazon SNS到SQS - 使用.NET SDK确认订阅

时间:2014-10-15 20:44:44

标签: .net amazon-sqs amazon-ses amazon-sns aws-sdk

我尝试设置Amazon Ses通知以转到我的SQS队列。 我按照说明如何创建SQS队列,然后是SNS主题,并订阅一个到另一个。

然而,在管理控制台中,订阅出现了"待确认"。

我使用.NET AWS SDK,如何确认订阅?或者甚至更好,我为什么要确认? documentation

  

如果队列的所有者创建订阅,则订阅   自动确认,订阅应该是有效的   几乎立即。

我使用我的AWS凭据作为所有者的所有API调用,所以我不明白为什么我需要确认,但我怎么能这样呢?

    private static string CreateBounceTopicAndQueue(IAmazonSQS sqsClient, IAmazonSimpleNotificationService snsClient)
    {
        // 1. Create an Amazon SQS queue named ses-bounces-queue.
        CreateQueueResponse createQueueResponse = sqsClient.CreateQueue(new CreateQueueRequest()
        {
            QueueName = AppGlobal.SesBouncesQueue,
            Attributes = new Dictionary<string, string>() {
                { "ReceiveMessageWaitTimeSeconds", "20" }
            }
        });
        string queueUrl = createQueueResponse.QueueUrl;

        // 2. Create an Amazon SNS topic named ses-bounces-topic
        CreateTopicResponse createTopicResponse = snsClient.CreateTopic(new CreateTopicRequest
        {
            Name = AppGlobal.SesBouncesTopic
        });
        string topicArn = createTopicResponse.TopicArn;

        // 3. Configure the Amazon SNS topic to publish to the SQS queue
        var response =  snsClient.Subscribe(new SubscribeRequest
        {
            TopicArn = topicArn,
            Endpoint = queueUrl,
            Protocol = "https"
        });

        return queueUrl;
    }

1 个答案:

答案 0 :(得分:1)

通过使用队列URL创建https订阅,您不会将SQS队列订阅到SNS主题。

您使用队列的 ARN (非Web端点)作为端点创建“ sqs ”(非https)协议订阅。


protocol
Type: System.String
The protocol you want to use. 
...
sqs -- delivery of JSON-encoded message to an Amazon SQS queue

endpoint
Type: System.String
The endpoint that you want to receive notifications. Endpoints vary by protocol...

For the sqs protocol, the endpoint is the ARN of an Amazon SQS queue

http://docs.aws.amazon.com/sdkfornet/latest/apidocs/items/MSNS_SNSSubscribe_String_String_StringNET4_5.html