# aws-dotnet-messaging **Repository Path**: mirrors_aws/aws-dotnet-messaging ## Basic Information - **Project Name**: aws-dotnet-messaging - **Description**: An AWS-native framework that simplifies the development of .NET message processing applications that use AWS services, such as SQS, SNS, and EventBridge. - **Primary Language**: Unknown - **License**: Apache-2.0 - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-05-07 - **Last Updated**: 2026-03-28 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # AWS Message Processing Framework for .NET [![nuget](https://img.shields.io/nuget/v/AWS.Messaging.svg) ![downloads](https://img.shields.io/nuget/dt/AWS.Messaging.svg)](https://www.nuget.org/packages/AWS.Messaging/) [![build status](https://img.shields.io/github/actions/workflow/status/awslabs/aws-dotnet-messaging/aws-ci.yml?branch=dev)](https://github.com/awslabs/aws-dotnet-messaging/actions/workflows/aws-ci.yml) The **AWS Message Processing Framework for .NET** is an AWS-native framework that simplifies the development of .NET message processing applications that use AWS services, such as Amazon Simple Queue Service (SQS), Amazon Simple Notification Service (SNS), and Amazon EventBridge. The framework reduces the amount of boiler-plate code developers need to write, allowing you to focus on your business logic when publishing and consuming messages. * For publishers, the framework serializes the message from a .NET object to a [CloudEvents](https://cloudevents.io/)-compatible message, and then wraps that in the service-specific AWS message. It then publishes the message to the configured SQS queue, SNS topic, or EventBridge event bus. * For consumers, the framework deserializes the message to its .NET object and routes it to the appropriate business logic. The framework also keeps track of the message visibility while it is being processed (to avoid processing a message more than once), and deletes the message from the queue when completed. The framework supports consuming messages in both long-running polling processes and in AWS Lambda functions. # Getting started Add the `AWS.Messaging` NuGet package to your project: ``` dotnet add package AWS.Messaging ``` The framework integrates with .NET's [dependency injection (DI) service container](https://learn.microsoft.com/en-us/dotnet/core/extensions/dependency-injection). You can configure the framework during your application's startup by calling `AddAWSMessageBus` to add it to the DI container. ```csharp var builder = WebApplication.CreateBuilder(args); // Register the AWS Message Processing Framework for .NET builder.Services.AddAWSMessageBus(builder => { // Register that you'll publish messages of type ChatMessage to an existing queue builder.AddSQSPublisher("https://sqs.us-west-2.amazonaws.com/012345678910/MyAppProd"); }); ``` The framework supports publishing one or more message types, processing one or more message types, or doing both in the same application. # Publishing Messages The following code shows a configuration for an application that is publishing different message types to different AWS services. ```csharp var builder = WebApplication.CreateBuilder(args); // Register the AWS Message Processing Framework for .NET builder.Services.AddAWSMessageBus(builder => { // Register that you'll publish messages of type ChatMessage to an existing queue builder.AddSQSPublisher("https://sqs.us-west-2.amazonaws.com/012345678910/MyAppProd"); // Register that you'll publish messages of type OrderInfo to an existing SNS topic builder.AddSNSPublisher("arn:aws:sns:us-west-2:012345678910:MyAppProd"); // Register that you'll publish messages of type FoodItem to an existing EventBridge bus builder.AddEventBridgePublisher("arn:aws:events:us-west-2:012345678910:event-bus/default"); }); ``` Once you have registered the framework during startup, inject the generic `IMessagePublisher` into your code. Call its `PublishAsync` method to publish any of the message types that were configured above. The generic publisher will determine the destination to route the message to based on its type. In the following example, an ASP.NET MVC controller receives both `ChatMessage` messages and `OrderInfo` events from users, and then publishes them to SQS and SNS respectively. Both message types can be published using the generic publisher that was configured above. ```csharp [ApiController] [Route("[controller]")] public class PublisherController : ControllerBase { private readonly IMessagePublisher _messagePublisher; public PublisherController(IMessagePublisher messagePublisher) { _messagePublisher = messagePublisher; } [HttpPost("chatmessage", Name = "Chat Message")] public async Task PublishChatMessage([FromBody] ChatMessage message) { // Perform business and validation logic on the ChatMessage here if (message == null) { return BadRequest("A chat message was not submitted. Unable to forward to the message queue."); } if (string.IsNullOrEmpty(message.MessageDescription)) { return BadRequest("The MessageDescription cannot be null or empty."); } // Publish the ChatMessage to SQS, using the generic publisher await _messagePublisher.PublishAsync(message); return Ok(); } [HttpPost("order", Name = "Order")] public async Task PublishOrder([FromBody] OrderInfo message) { if (message == null) { return BadRequest("An order was not submitted."); } // Publish the OrderInfo to SNS, using the generic publisher await _messagePublisher.PublishAsync(message); return Ok(); } } ``` ## Service-specific publishers The example shown above uses the generic `IMessagePublisher`, which can publish to any supported AWS service based on the configured message type. The framework also provides *service-specific publishers* for SQS, SNS and EventBridge. These specific publishers expose options that only apply to that service, and can be injected using the types `ISQSPublisher`, `ISNSPublisher` and `IEventBridgePublisher`. For example, when publishing messages to an SQS FIFO queue, you must set the appropriate [message group ID](https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/FIFO-key-terms.html). The following code shows the `ChatMessage` example again, but now using an `ISQSPublisher` to set SQS-specific options. ```csharp public class PublisherController : ControllerBase { private readonly ISQSPublisher _sqsPublisher; public PublisherController(ISQSPublisher sqsPublisher) { _sqsPublisher = sqsPublisher; } [HttpPost("chatmessage", Name = "Chat Message")] public async Task PublishChatMessage([FromBody] ChatMessage message) { // Perform business and validation logic on the ChatMessage here if (message == null) { return BadRequest("A chat message was not submitted. Unable to forward to the message queue."); } if (string.IsNullOrEmpty(message.MessageDescription)) { return BadRequest("The MessageDescription cannot be null or empty."); } // Send the ChatMessage to SQS using the injected ISQSPublisher, with SQS-specific options await _sqsPublisher.SendAsync(message, new SQSOptions { DelaySeconds = , MessageAttributes = , MessageDeduplicationId = , MessageGroupId = }); return Ok(); } } ``` The same can be done for SNS and EventBridge, using `ISNSPublisher` and `IEventBridgePublisher` respectively. ```csharp await _snsPublisher.PublishAsync(message, new SNSOptions { Subject = , MessageAttributes = , MessageDeduplicationId = , MessageGroupId = }); ``` ```csharp await _eventBridgePublisher.PublishAsync(message, new EventBridgeOptions { DetailType = , Resources = , Source = , Time =