@@ -20,22 +20,53 @@ public static async Task Main()
20
20
{
21
21
IAmazonSimpleNotificationService client = new AmazonSimpleNotificationServiceClient ( ) ;
22
22
23
- var subscriptions = await GetSubscriptionsListAsync ( client ) ;
23
+ Console . WriteLine ( "Enter a topic ARN to list subscriptions for a specific topic, " +
24
+ "or press Enter to list subscriptions for all topics." ) ;
25
+ var topicArn = Console . ReadLine ( ) ;
26
+ Console . WriteLine ( ) ;
27
+
28
+ var subscriptions = await GetSubscriptionsListAsync ( client , topicArn ) ;
24
29
25
30
DisplaySubscriptionList ( subscriptions ) ;
26
31
}
27
32
28
33
/// <summary>
29
- /// Gets a list of the existing Amazon SNS subscriptions.
34
+ /// Gets a list of the existing Amazon SNS subscriptions, optionally by specifying a specific topic ARN .
30
35
/// </summary>
31
36
/// <param name="client">The initialized Amazon SNS client object used
32
37
/// to obtain the list of subscriptions.</param>
33
- /// <returns>A List containing information about each subscription.</returns>
34
- public static async Task < List < Subscription > > GetSubscriptionsListAsync ( IAmazonSimpleNotificationService client )
38
+ /// <param name="topicArn">The optional ARN of a specific topic. Defaults to null.</param>
39
+ /// <returns>A list containing information about each subscription.</returns>
40
+ public static async Task < List < Subscription > > GetSubscriptionsListAsync ( IAmazonSimpleNotificationService client , string topicArn = null )
35
41
{
36
- var response = await client . ListSubscriptionsAsync ( ) ;
42
+ var results = new List < Subscription > ( ) ;
43
+
44
+ if ( ! string . IsNullOrEmpty ( topicArn ) )
45
+ {
46
+ var paginateByTopic = client . Paginators . ListSubscriptionsByTopic (
47
+ new ListSubscriptionsByTopicRequest ( )
48
+ {
49
+ TopicArn = topicArn ,
50
+ } ) ;
37
51
38
- return response . Subscriptions ;
52
+ // Get the entire list using the paginator.
53
+ await foreach ( var subscription in paginateByTopic . Subscriptions )
54
+ {
55
+ results . Add ( subscription ) ;
56
+ }
57
+ }
58
+ else
59
+ {
60
+ var paginateAllSubscriptions = client . Paginators . ListSubscriptions ( new ListSubscriptionsRequest ( ) ) ;
61
+
62
+ // Get the entire list using the paginator.
63
+ await foreach ( var subscription in paginateAllSubscriptions . Subscriptions )
64
+ {
65
+ results . Add ( subscription ) ;
66
+ }
67
+ }
68
+
69
+ return results ;
39
70
}
40
71
41
72
/// <summary>
@@ -56,5 +87,6 @@ public static void DisplaySubscriptionList(List<Subscription> subscriptionList)
56
87
}
57
88
}
58
89
}
90
+
59
91
// snippet-end:[SNS.dotnetv3.ListSNSSubscriptionsExample]
60
92
}
0 commit comments