This library is wrapper around Amazon Simple Notification Service. The main goals are:
- To publish messages to a configured SNS topic.
- To receive messages from a configured SNS topic.
You will need an SNS instance in order to use this library. To create an SNS instance, you can follow the instructions in the AWS SNS Documentation.
Amido.Stacks.Application.CQRS.Abstractions
Amido.Stacks.Configuration
Amido.Stacks.Core
AWSSDK.SimpleNotificationService
The library currently supports:
- Publishing and receiving events that implement
Amido.Stacks.Application.CQRS.ApplicationEvents.IApplicationEvent
.
In this example the MenuCreatedEvent
is handled by the MenuCreatedEventHandler
. The event must implement the IApplicationEvent
interface and the handler must implement the IApplicationEventHandler<NotifyEvent>
interface. Both of these interfaces are found in the Amido.Stacks.Application.CQRS.ApplicationEvents namespace.
MenuCreated.cs
public class MenuCreatedEvent : IApplicationEvent
{
public MenuCreatedEvent(Guid correlationId, int eventCode, int operationCode)
{
CorrelationId = correlationId;
EventCode = eventCode;
OperationCode = operationCode;
}
public Guid CorrelationId { get; }
public int EventCode { get; }
public int OperationCode { get; }
}
MenuCreatedHandler.cs
public class MenuCreatedEventHandler : IApplicationEventHandler<MenuCreatedEvent>
{
public Task HandleAsync(MenuCreatedEvent applicationEvent)
{
// Code to handle the event...
return Task.CompletedTask;
}
}
appsettings.json
{
"AwsSnsConfiguration": {
"TopicArn": {
"Identifier": "TOPIC_ARN",
"Source": "Environment"
}
}
}
Usage
public class Startup
{
public void ConfigureServices(IServiceCollection services, WebHostBuilderContext context)
{
services.Configure<AwsSnsConfiguration>(context.Configuration.GetSection("AwsSnsConfiguration"));
services.AddAwsSns(context.Configuration);
services.AddSecrets(); // To read the secret defined as an environment variable appsettings.json.
}
}