Amazon Simple Notification Service AWSSDK C# - S.O.S(Amazon Simple Notification Service AWSSDK C# - S.O.S)
问题描述
我正在尝试使用 Amazon 的 AWSSDK for C# 和简单通知服务进行发布.
I am trying to publish with Amazon's AWSSDK for C# and the Simple Notification Service.
没有随 SDK 一起提供的示例,在 Google 搜索 2 小时后,我在网络上的任何地方都找不到示例.我想出了这个,但它抛出了一个异常,产生的信息不超过单个字符串TopicARN"-没有内部异常-nuffin!
如果有人使用 AWSSDK 通过 C# 成功发送了带有 SNS
的消息,我希望看到即使是最基本的工作示例.我正在使用最新的 SDK 1.5x
There are no samples that come with the SDK and there are no samples anywhere on the web I could find after 2 hours of Googling. I came up with this but it is throwing an exception that yields no more information than the single string, "TopicARN" - no inner exception - nuffin!
If anyone has successfully sent a message with SNS
via C# using the AWSSDK I would love to see even the most rudimentary working example. I am using the latest SDK 1.5x
代码如下:
string resourceName = "arn:aws:sns:us-east-1:xxxxxxxxxxxx:StackOverFlowStub";
AmazonSimpleNotificationServiceClient snsclient = new AmazonSimpleNotificationServiceClient(accesskey,secretkey);
AddPermissionRequest permissionRequest = new AddPermissionRequest()
.WithActionNames("Publish")
.WithActionNames(accesskey)
.WithActionNames("PrincipleAllowControl")
.WithActionNames(resourceName);
snsclient.AddPermission(permissionRequest);
PublishRequest pr = new PublishRequest();
pr.WithMessage("Test Msg");
pr.WithTopicArn(resourceName);
pr.WithSubject("Test Subject");
snsclient.Publish(pr);
推荐答案
这是一个创建主题、设置主题显示名称、订阅主题的电子邮件地址、发送消息和删除主题的示例.请注意,在继续之前,您应该在两个地方等待/检查您的电子邮件.Client
是客户端实例,topicName
是任意主题名称.
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
});
这篇关于Amazon Simple Notification Service AWSSDK C# - S.O.S的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Amazon Simple Notification Service AWSSDK C# - S.O.S
基础教程推荐
- MS Visual Studio .NET 的替代品 2022-01-01
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30
- rabbitmq 的 REST API 2022-01-01
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01
- c# Math.Sqrt 实现 2022-01-01
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01
- SSE 浮点算术是否可重现? 2022-01-01
- 将 XML 转换为通用列表 2022-01-01
- 如何激活MC67中的红灯 2022-01-01