This library is wrapper around Amazon Simple Queue Service. The main goals are:
- To publish messages to a configured SQS queue.
- To receive messages from a configured SQS queue.
You will need an SQS instance in order to use this library. To create an SQS instance, you can follow the instructions in the AWS SQS Documentation.
Amido.Stacks.Application.CQRS.Abstractions
Amido.Stacks.Configuration
Amido.Stacks.Core
AWSSDK.SQS
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.
MenuCreatedEvent.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; }
}
MenuCreatedEventHandler.cs
public class MenuCreatedEventHandler : IApplicationEventHandler<MenuCreatedEvent>
{
public Task HandleAsync(MenuCreatedEvent applicationEvent)
{
// Code to handle the event...
return Task.CompletedTask;
}
}
appsettings.json
{
"AwsSqsConfiguration": {
"QueueUrl": {
"Identifier": "SQS_QUEUE_URL",
"Source": "Environment"
}
}
}
Usage
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.Configure<AwsSqsConfiguration>(context.Configuration.GetSection("AwsSqsConfiguration"));
services.AddAwsSqs();
services.AddSecrets(); // To read the secret defined as an environment variable appsettings.json.
}
}