Nera.Lib.Messaging.Sender
1.0.0
dotnet add package Nera.Lib.Messaging.Sender --version 1.0.0
NuGet\Install-Package Nera.Lib.Messaging.Sender -Version 1.0.0
<PackageReference Include="Nera.Lib.Messaging.Sender" Version="1.0.0" />
<PackageVersion Include="Nera.Lib.Messaging.Sender" Version="1.0.0" />
<PackageReference Include="Nera.Lib.Messaging.Sender" />
paket add Nera.Lib.Messaging.Sender --version 1.0.0
#r "nuget: Nera.Lib.Messaging.Sender, 1.0.0"
#:package Nera.Lib.Messaging.Sender@1.0.0
#addin nuget:?package=Nera.Lib.Messaging.Sender&version=1.0.0
#tool nuget:?package=Nera.Lib.Messaging.Sender&version=1.0.0
Nera.Lib.Messaging.Sender
A robust messaging sender library for Nera applications that provides event-driven communication capabilities with comprehensive logging, retry policies, and template variable substitution.
Features
- Event-Driven Messaging: Send structured events with metadata and logging
- Template Variable Support: Dynamic template variable substitution in messages
- Comprehensive Logging: Track send events with detailed logging entities
- Retry Policies: Built-in resilience with Polly integration
- Entity Framework Integration: Persistent event logging with PostgreSQL support
- Redis Caching: Performance optimization with distributed caching
- Dependency Injection: Seamless integration with .NET Core DI container
Installation
Install the package via NuGet Package Manager:
dotnet add package Nera.Lib.Messaging.Sender
Or via Package Manager Console:
Install-Package Nera.Lib.Messaging.Sender
Configuration
Add the messaging sender services to your dependency injection container:
using Nera.Lib.Messaging.Sender;
// In your Program.cs or Startup.cs
services.AddNeraMessagingSender(configuration);
Configuration Options
Configure the messaging sender in your appsettings.json
:
{
"NeraMessaging": {
"Sender": {
"RetryPolicy": {
"MaxRetryAttempts": 3,
"DelayBetweenRetries": "00:00:02"
},
"LoggingEnabled": true,
"CacheSettings": {
"DefaultExpiration": "00:15:00"
}
}
}
}
Usage
Basic Event Sending
public class NotificationController : ControllerBase
{
private readonly ISenderService _senderService;
public NotificationController(ISenderService senderService)
{
_senderService = senderService;
}
[HttpPost("send-notification")]
public async Task<IActionResult> SendNotification(NotificationRequest request)
{
var metadata = new SendEventMetadata
{
TemplateId = "welcome-email",
Recipient = request.Email,
Priority = MessagePriority.High
};
var templateVariables = new Dictionary<string, object>
{
["UserName"] = request.UserName,
["WelcomeMessage"] = "Welcome to our platform!",
["ActivationLink"] = request.ActivationUrl
};
await _senderService.SendEventAsync(metadata, templateVariables);
return Ok("Notification sent successfully");
}
}
Working with Template Variables
The library provides a helper for managing template variables:
public class EmailService
{
private readonly ISenderService _senderService;
public async Task SendWelcomeEmail(User user)
{
var templateHelper = new TemplateVariableHelper();
// Add variables using the helper
templateHelper.AddVariable("FirstName", user.FirstName);
templateHelper.AddVariable("LastName", user.LastName);
templateHelper.AddVariable("CompanyName", "Nextera Systems");
var metadata = new SendEventMetadata
{
TemplateId = "user-welcome",
Recipient = user.Email,
Subject = "Welcome to Our Platform"
};
await _senderService.SendEventAsync(metadata, templateHelper.GetVariables());
}
}
Event Logging and Tracking
All send events are automatically logged and can be tracked:
public class MessageTrackingService
{
private readonly ISendEventLogRepository _logRepository;
public MessageTrackingService(ISendEventLogRepository logRepository)
{
_logRepository = logRepository;
}
public async Task<IEnumerable<SendEventLogEntity>> GetRecentSendEvents(int hours = 24)
{
var since = DateTime.UtcNow.AddHours(-hours);
return await _logRepository.GetEventsSinceAsync(since);
}
public async Task<SendEventLogEntity> GetEventById(Guid eventId)
{
return await _logRepository.GetByIdAsync(eventId);
}
}
Project Structure
Nera.Lib.Messaging.Sender/
├── Common/
│ ├── TemplateVariableHelper.cs # Helper for managing template variables
│ └── Exceptions/ # Custom exceptions
├── Entities/
│ └── SendEventLogEntity.cs # Entity for logging send events
├── Events/
│ ├── SendEventCreatedEvent.cs # Event raised when send event is created
│ └── SendEventStatusUpdatedEvent.cs # Event raised when send status updates
├── Extensions/
│ └── SendEventMetadataExtensions.cs # Extension methods for metadata
├── Interfaces/
│ ├── ISenderService.cs # Main sender service interface
│ └── ISendEventLogRepository.cs # Repository interface for event logs
├── Models/
│ └── SendEventUsageExamples.cs # Usage examples and documentation
├── Services/
│ └── SenderService.cs # Main implementation of sender service
├── ValueObjects/
│ └── SendEventMetadata.cs # Value object for event metadata
└── ServiceCollectionExtensions.cs # DI container extensions
Events
The library raises the following domain events:
- SendEventCreatedEvent: Raised when a new send event is created
- SendEventStatusUpdatedEvent: Raised when the status of a send event changes
Subscribe to these events to implement custom business logic:
public class SendEventHandler : INotificationHandler<SendEventCreatedEvent>
{
public async Task Handle(SendEventCreatedEvent notification, CancellationToken cancellationToken)
{
// Custom logic when send event is created
Console.WriteLine($"Send event created: {notification.EventId}");
}
}
Dependencies
This library depends on the following Nera libraries:
- Nera.Lib.Core (v1.0.1+): Core utilities and base classes
- Nera.Lib.Domain (v1.0.2+): Domain modeling and DDD patterns
- Nera.Lib.Caching (v1.0.0+): Caching abstractions and implementations
Requirements
- .NET 9.0 or later
- Entity Framework Core 9.0+
- PostgreSQL database (for event logging)
- Redis (optional, for caching)
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Submit a pull request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Support
For questions and support, please contact the Nextera Systems development team or create an issue in the repository.
Nextera Systems - Building robust, scalable applications with .NET
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net9.0
- BCrypt.Net-Next (>= 4.0.3)
- Microsoft.EntityFrameworkCore (>= 9.0.8)
- Microsoft.Extensions.Configuration (>= 9.0.8)
- Microsoft.Extensions.Http (>= 9.0.8)
- Microsoft.Extensions.Logging (>= 9.0.8)
- Nera.Lib.Caching (>= 1.0.0)
- Nera.Lib.Core (>= 1.0.0)
- Nera.Lib.Messaging.Abstractions (>= 1.0.0)
- Npgsql.EntityFrameworkCore.PostgreSQL (>= 9.0.4)
- Polly (>= 8.6.3)
- Polly.Extensions.Http (>= 3.0.0)
- Serilog (>= 4.3.0)
- Serilog.Extensions.Hosting (>= 9.0.0)
- Serilog.Sinks.Console (>= 6.0.0)
- Serilog.Sinks.File (>= 7.0.0)
- StackExchange.Redis (>= 2.9.11)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last Updated |
---|---|---|
1.0.0 | 159 | 9/9/2025 |