-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
107 lines (97 loc) · 5.18 KB
/
Program.cs
File metadata and controls
107 lines (97 loc) · 5.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
using Amazon.SimpleNotificationService;
using Amazon.SQS;
using Messages;
using MQContract;
using MQContract.AmazonSNQS;
#pragma warning disable S1075 // URIs should not be hardcoded
//This is a sample program with a localhost connection so this is necessary
const string ServiceURL = "http://localhost:4566";
#pragma warning restore S1075 // URIs should not be hardcoded
const string QueueAttributeName = "QueueArn";
var mapper = new ChannelMapper();
mapper.AddQueryResponseMap("Greeting.Response", "Greeting_Response");
var credentials = new Amazon.Runtime.BasicAWSCredentials("test", "test");
var config = new AmazonSQSConfig { ServiceURL = ServiceURL };
var snsConfig = new AmazonSimpleNotificationServiceConfig { ServiceURL = ServiceURL };
var serviceConnection = new Connection(snsClientConfiguration: (credentials, snsConfig), sqsClientConfiguration: (credentials, config));
var arrivalsSNSResponse = await serviceConnection.SNSClient!.CreateTopicAsync("Arrivals");
var storedArrivalsSNSResponse = await serviceConnection.SNSClient!.CreateTopicAsync("StoredArrivals");
var greetingSNSResponse = await serviceConnection.SNSClient!.CreateTopicAsync("Greeting");
var greetingResponseSNSResponse = await serviceConnection.SNSClient!.CreateTopicAsync("Greeting_Response");
var arrivalsSQSResponse = await serviceConnection.SQSClient!.CreateQueueAsync("Arrivals");
var queueArn = (await serviceConnection.SQSClient!.GetQueueAttributesAsync(arrivalsSQSResponse.QueueUrl, [QueueAttributeName])).QueueARN;
await serviceConnection.SQSClient!.SetQueueAttributesAsync(arrivalsSQSResponse.QueueUrl, new() {
{ "Policy",$@"{{
""Version"": ""2012-10-17"",
""Statement"": [
{{
""Effect"": ""Allow"",
""Principal"": {{ ""Service"": ""sns.amazonaws.com"" }},
""Action"": ""sqs:SendMessage"",
""Resource"": ""{queueArn}"",
""Condition"": {{
""ArnEquals"": {{ ""aws:SourceArn"": ""{arrivalsSNSResponse.TopicArn}"" }}
}}
}}
]
}}"}
});
await serviceConnection.SNSClient.SubscribeAsync(arrivalsSNSResponse.TopicArn, "sqs", queueArn);
var storedArrivalsSQSResponse = await serviceConnection.SQSClient!.CreateQueueAsync("StoredArrivals");
queueArn = (await serviceConnection.SQSClient!.GetQueueAttributesAsync(storedArrivalsSQSResponse.QueueUrl, [QueueAttributeName])).QueueARN;
await serviceConnection.SQSClient!.SetQueueAttributesAsync(storedArrivalsSQSResponse.QueueUrl, new() {
{ "Policy",$@"{{
""Version"": ""2012-10-17"",
""Statement"": [
{{
""Effect"": ""Allow"",
""Principal"": {{ ""Service"": ""sns.amazonaws.com"" }},
""Action"": ""sqs:SendMessage"",
""Resource"": ""{queueArn}"",
""Condition"": {{
""ArnEquals"": {{ ""aws:SourceArn"": ""{storedArrivalsSNSResponse.TopicArn}"" }}
}}
}}
]
}}"}
});
await serviceConnection.SNSClient.SubscribeAsync(storedArrivalsSNSResponse.TopicArn, "sqs", queueArn);
var greetingSQSResponse = await serviceConnection.SQSClient!.CreateQueueAsync("Greeting");
queueArn = (await serviceConnection.SQSClient!.GetQueueAttributesAsync(greetingSQSResponse.QueueUrl, [QueueAttributeName])).QueueARN;
await serviceConnection.SQSClient!.SetQueueAttributesAsync(greetingSQSResponse.QueueUrl, new() {
{ "Policy",$@"{{
""Version"": ""2012-10-17"",
""Statement"": [
{{
""Effect"": ""Allow"",
""Principal"": {{ ""Service"": ""sns.amazonaws.com"" }},
""Action"": ""sqs:SendMessage"",
""Resource"": ""{queueArn}"",
""Condition"": {{
""ArnEquals"": {{ ""aws:SourceArn"": ""{greetingSNSResponse.TopicArn}"" }}
}}
}}
]
}}"}
});
await serviceConnection.SNSClient.SubscribeAsync(greetingSNSResponse.TopicArn, "sqs", queueArn);
var greetingResponseSQSResponse = await serviceConnection.SQSClient!.CreateQueueAsync("Greeting_Response");
queueArn = (await serviceConnection.SQSClient!.GetQueueAttributesAsync(greetingResponseSQSResponse.QueueUrl, [QueueAttributeName])).QueueARN;
await serviceConnection.SQSClient!.SetQueueAttributesAsync(greetingResponseSQSResponse.QueueUrl, new() {
{ "Policy",$@"{{
""Version"": ""2012-10-17"",
""Statement"": [
{{
""Effect"": ""Allow"",
""Principal"": {{ ""Service"": ""sns.amazonaws.com"" }},
""Action"": ""sqs:SendMessage"",
""Resource"": ""{queueArn}"",
""Condition"": {{
""ArnEquals"": {{ ""aws:SourceArn"": ""{greetingResponseSNSResponse.TopicArn}"" }}
}}
}}
]
}}"}
});
await serviceConnection.SNSClient.SubscribeAsync(greetingResponseSNSResponse.TopicArn, "sqs", queueArn);
await SampleExecution.ExecuteSample(serviceConnection, "AmazonSNQS", mapper);