Nera.Lib.Messaging.Abstractions
1.0.2
dotnet add package Nera.Lib.Messaging.Abstractions --version 1.0.2
NuGet\Install-Package Nera.Lib.Messaging.Abstractions -Version 1.0.2
<PackageReference Include="Nera.Lib.Messaging.Abstractions" Version="1.0.2" />
<PackageVersion Include="Nera.Lib.Messaging.Abstractions" Version="1.0.2" />
<PackageReference Include="Nera.Lib.Messaging.Abstractions" />
paket add Nera.Lib.Messaging.Abstractions --version 1.0.2
#r "nuget: Nera.Lib.Messaging.Abstractions, 1.0.2"
#:package Nera.Lib.Messaging.Abstractions@1.0.2
#addin nuget:?package=Nera.Lib.Messaging.Abstractions&version=1.0.2
#tool nuget:?package=Nera.Lib.Messaging.Abstractions&version=1.0.2
Nera.Lib.Messaging.Abstractions
Simplified Messaging Library for Nextera Services - Redesigned to be as simple as MediatR π
Overview
A lightweight messaging library that provides two distinct messaging patterns for microservices:
- In-Service Events - Simple, MediatR-like events within the same service
- External Events - Cross-service messaging using MassTransit + RabbitMQ
Key Features
- β Simple like MediatR - Familiar API for developers
- β Auto-discovery - Automatic handler registration
- β Proper lifetimes - Correct DI scoping
- β Error isolation - One failing handler won't crash others
- β Zero configuration - Works out of the box
- β Type-safe - Full compile-time type checking
Quick Start
1. Install Package
<PackageReference Include="Nera.Lib.Messaging.Abstractions" Version="1.0.0" />
2. Register Services
// Program.cs or Startup.cs
services.AddMessagingServices(); // Enables in-service events
// Optional: Add MassTransit for external messaging
services.AddMassTransitWithRabbitMq(
consumers => consumers.AddConsumer<MyConsumer>(),
(cfg, ctx) => cfg.ReceiveEndpoint("my-queue", e => e.ConfigureConsumer<MyConsumer>(ctx))
);
3. Create Event & Handler
// Define an event
public class UserCreated : IInServiceEvent
{
public string UserId { get; set; }
public string Email { get; set; }
}
// Create a handler
public class SendWelcomeEmailHandler : IInServiceEventHandler<UserCreated>
{
public async Task Handle(UserCreated @event, CancellationToken cancellationToken)
{
// Handle the event
await SendWelcomeEmail(@event.Email);
}
}
4. Publish Events
public class UserService
{
private readonly IInServiceEventBus _eventBus;
public async Task CreateUser(CreateUserRequest request)
{
var user = await CreateUserLogic(request);
// Publish event - all handlers will be called automatically
await _eventBus.Publish(new UserCreated
{
UserId = user.Id,
Email = user.Email
});
}
}
Architecture
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Your Service β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β In-Service Events (Fast, Same Process) β
β βββββββββββββββ βββββββββββββββββββββββββββββββββββββββ β
β β Publisher βββββΆβ IInServiceEventBus β β
β βββββββββββββββ β ββ Handler 1 β β
β β ββ Handler 2 β β
β β ββ Handler N β β
β βββββββββββββββββββββββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β External Events (Reliable, Cross-Service) β
β βββββββββββββββ βββββββββββββββββββββββββββββββββββββββ β
β β Publisher βββββΆβ MassTransit + RabbitMQ β β
β βββββββββββββββ βββββββββββββββββββββββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Other Services β
β βββββββββββββββββββββββββββββββββββββββ β
β β MassTransit Consumers β β
β β ββ Consumer 1 β β
β β ββ Consumer 2 β β
β β ββ Consumer N β β
β βββββββββββββββββββββββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Comparison
Feature | In-Service Events | External Events |
---|---|---|
Use Case | Same service logic | Cross-service communication |
Performance | Very fast (in-memory) | Network calls |
Reliability | Process dependent | Durable, retries |
Scope | Single service | Multiple services |
Interface | IInServiceEvent |
IIntegrationEvent |
Bus | IInServiceEventBus |
IEventBus (MassTransit) |
Migration from Old Version
Before (Complex)
// Complex registration
services.AddInServiceEventHandlers(Assembly.GetExecutingAssembly());
// Manual handler registration with reflection issues
public class Handler : InServiceEventHandlerBase<Event>
{
// Required specific base class
}
// Event with required properties
public class Event : InServiceEventBase
{
public Guid Id { get; set; } // Required
public DateTimeOffset OccurredOn { get; set; } // Required
}
After (Simple)
// Simple registration - auto-discovery
services.AddMessagingServices();
// Flexible handler implementation
public class Handler : IInServiceEventHandler<Event>
{
// Or optionally inherit from base class for logging
}
// Simple event definition
public class Event : IInServiceEvent
{
// Only your business properties
}
Documentation
Requirements
- .NET 9.0+
- MassTransit 8.0+ (for external events)
- RabbitMQ (for external events)
License
Internal Nextera library - Not for public distribution
Simple, Reliable, Type-Safe Messaging for Nextera Services πͺ
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
- MassTransit (>= 8.5.2)
- MassTransit.AspNetCore (>= 7.3.1)
- MassTransit.EntityFrameworkCore (>= 8.5.2)
- MassTransit.RabbitMQ (>= 8.5.2)
- Microsoft.AspNetCore.Http (>= 2.3.0)
- Microsoft.AspNetCore.Http.Abstractions (>= 2.3.0)
- Microsoft.Extensions.DependencyInjection (>= 9.0.8)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 9.0.8)
- Microsoft.Extensions.Hosting (>= 9.0.8)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 9.0.8)
- Nera.Lib.Core (>= 1.0.8)
- OpenTelemetry.Extensions.Hosting (>= 1.12.0)
- Serilog.AspNetCore (>= 9.0.0)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on Nera.Lib.Messaging.Abstractions:
Package | Downloads |
---|---|
Nera.Lib.Database
Database access layer with Entity Framework Core, Repository pattern, Specification pattern, and advanced querying capabilities for Nera applications |
|
Nera.Lib.Messaging.Sender
A robust messaging sender library for Nera applications providing event-driven communication capabilities with logging, retry policies, and template variable substitution |
GitHub repositories
This package is not used by any popular GitHub repositories.