-
-
Save jagadeeshvenkatesh/da693f854f2292e35381d06d42ed3794 to your computer and use it in GitHub Desktop.
SNS Load Testing Code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Threading.Tasks; | |
using Amazon.SimpleNotificationService; | |
using Newtonsoft.Json; | |
namespace sns_load_test | |
{ | |
class Program | |
{ | |
//Change this to control what SNS topic you are publishing to | |
const string TopicArn = "arn:aws:sns:ap-southeast-2:xxxxxxxxxxxxxxxxxxxx"; | |
//Change this to control how many messages to send in the load test | |
const int NumberOfMessagesToSend = 100; | |
static void Main(string[] args) | |
{ | |
Run().Wait(); | |
} | |
static async Task Run() | |
{ | |
List<string> serializedMessages = new List<string>(); | |
for (int i = 0; i < NumberOfMessagesToSend; i++) | |
{ | |
//Customise the content of your SNS messages as need be here | |
var message = new { | |
Property = "Hello World!" | |
}; | |
serializedMessages.Add(JsonConvert.SerializeObject(message)); | |
} | |
var snsClient = new AmazonSimpleNotificationServiceClient(Amazon.RegionEndpoint.APSoutheast2); | |
IEnumerable<Task> tasks = serializedMessages.Select(async serializedMessage => | |
{ | |
try | |
{ | |
await snsClient.PublishAsync(TopicArn, serializedMessage); | |
} | |
catch (Exception ex) | |
{ | |
Console.WriteLine(ex.Message); | |
} | |
}); | |
await Task.WhenAll(tasks); | |
Console.WriteLine("Done!"); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Project Sdk="Microsoft.NET.Sdk"> | |
<PropertyGroup> | |
<OutputType>Exe</OutputType> | |
<TargetFramework>netcoreapp2.1</TargetFramework> | |
<RootNamespace>sns_load_test</RootNamespace> | |
</PropertyGroup> | |
<ItemGroup> | |
<PackageReference Include="AWSSDK.SimpleNotificationService" Version="3.3.2.10" /> | |
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" /> | |
</ItemGroup> | |
</Project> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment