Amazon Simple Notification Service AWSSDK C# - S.O.S

前端 未结 1 340
温柔的废话
温柔的废话 2020-12-29 04:44

I am trying to publish with Amazon\'s AWSSDK for C# and the Simple Notification Service.

There are no samples that come with the SDK and there are no samples anywher

相关标签:
1条回答
  • 2020-12-29 05:15

    Here is a sample that creates a topic, sets a topic display name, subscribes an email address to the topic, sends a message and deletes the topic. Note that there are two spots where you should wait/check your email before continuing. Client is the client instance, topicName is an arbitrary topic name.

    // Create topic
    string topicArn = client.CreateTopic(new CreateTopicRequest
    {
        Name = topicName
    }).CreateTopicResult.TopicArn;
    
    // Set display name to a friendly value
    client.SetTopicAttributes(new SetTopicAttributesRequest
    {
        TopicArn = topicArn,
        AttributeName = "DisplayName",
        AttributeValue = "StackOverflow Sample Notifications"
    });
    
    // Subscribe an endpoint - in this case, an email address
    client.Subscribe(new SubscribeRequest
    {
        TopicArn = topicArn,
        Protocol = "email",
        Endpoint = "sample@example.com"
    });
    
    // When using email, recipient must confirm subscription
    Console.WriteLine("Please check your email and press enter when you are subscribed...");
    Console.ReadLine();
    
    // Publish message
    client.Publish(new PublishRequest
    {
        Subject = "Test",
        Message = "Testing testing 1 2 3",
        TopicArn = topicArn
    });
    
    // Verify email receieved
    Console.WriteLine("Please check your email and press enter when you receive the message...");
    Console.ReadLine();
    
    // Delete topic
    client.DeleteTopic(new DeleteTopicRequest
    {
        TopicArn = topicArn
    });
    
    0 讨论(0)
提交回复
热议问题