Compare commits

...

5 Commits

Author SHA1 Message Date
e6df623538 Update project version to 1.0.0 stable release
The `<Version>` tag in the `DigitalData.MessagingService.Client.csproj` file was updated from `1.0.0-beta` to `1.0.0`. This marks the transition from a beta release to a stable release, indicating the software is now ready for general use.
2026-07-29 14:49:56 +02:00
7773c8aa7f Update OnReconnect docs and README examples
Updated XML documentation in `OnReconnect.cs` to reference the updated `EmailSender.ConnectRabbitMq` method signature, clarifying its behavior when a connection is already established.

Revised `README.md` examples to replace `OutgoingEmailEvent` with `Email` and removed `Id` and `QueuedAt` properties, as they are now set internally. Added a note to clarify required fields for the `Email` object.

Added a new section to the `README.md` demonstrating how to check the connection status using `EmailSender.IsConnected`.
2026-07-29 14:36:47 +02:00
c73d8d8f36 Refactor EmailSender to use new Email abstraction
Introduced a new `Email` record to simplify the representation of outgoing email messages. Updated the `EmailSender.Send` method to accept `Email` instead of `OutgoingEmailEvent`, with a `ToEvent()` method handling the conversion internally.

Refactored test cases to use the `Email` record, removing redundant properties (`Id` and `QueuedAt`) that are now auto-generated. Updated XML documentation to reflect these changes. Adjusted namespaces and added necessary `using` directives for proper referencing.

These changes improve code readability, maintainability, and centralize the mapping logic for outgoing email events.
2026-07-29 14:36:10 +02:00
2f39db94ca Refactor and add OutgoingEmailCreateDto record
Introduced a new namespace `DigitalData.MessagingService.Publisher.Abstraction` in `OutgoingEmailCreateDto.cs` and `OutgoingEmailEvent.cs`.

Added a new record `OutgoingEmailCreateDto` with properties for recipient, subject, body, HTML flag, and queue timestamp.

Converted `OutgoingEmailEvent` from a class to a record.

Removed the unnecessary `using System;` directive from `OutgoingEmailEvent.cs`.
2026-07-29 13:43:21 +02:00
e78ceb522c Enhance logging and update solution structure
Replaced `DigitalData.MessagingService.Client.DependencyInjection`
with `DigitalData.MessagingService.Client` in the solution file,
updating project references and build configurations.

Improved logging by integrating Serilog's SQLite sink and `Serilog.UI`
for web-based log visualization. Added dynamic log directory
resolution and SQLite-based log storage in `Program.cs`.

Enhanced `DigitalData.MessagingService.API.csproj` with metadata
properties for better documentation and packaging. Added new NuGet
dependencies for logging and removed unused `<Folder>` entries.

Updated `appsettings.json` to include `Application:LogDirectory`
and `Swagger:Enabled` settings for configurable logging and Swagger
availability.
2026-07-29 13:08:42 +02:00
13 changed files with 173 additions and 52 deletions

View File

@@ -35,10 +35,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DigitalData.MessagingServic
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DigitalData.MessagingService.API", "src\presentation\DigitalData.MessagingService.API\DigitalData.MessagingService.API.csproj", "{8BF22107-3CB9-C326-B94B-C40C99DA9B68}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DigitalData.MessagingService.API", "src\presentation\DigitalData.MessagingService.API\DigitalData.MessagingService.API.csproj", "{8BF22107-3CB9-C326-B94B-C40C99DA9B68}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DigitalData.MessagingService.Client.DependencyInjection", "src\presentation\DigitalData.MessagingService.Client.DependencyInjection\DigitalData.MessagingService.Client.DependencyInjection.csproj", "{B67C6FA8-DA47-41EC-B15A-511C5B19C036}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DigitalData.MessagingService.Publisher", "src\infrastructure\DigitalData.MessagingService.Publisher\DigitalData.MessagingService.Publisher.csproj", "{8DBBAA7C-C4D3-4ADD-8372-B0D6260C8FFC}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DigitalData.MessagingService.Publisher", "src\infrastructure\DigitalData.MessagingService.Publisher\DigitalData.MessagingService.Publisher.csproj", "{8DBBAA7C-C4D3-4ADD-8372-B0D6260C8FFC}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DigitalData.MessagingService.Client", "src\presentation\DigitalData.MessagingService.Client\DigitalData.MessagingService.Client.csproj", "{770E96B0-C3C9-A9A3-4F98-F7A0295D1599}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
@@ -73,14 +73,14 @@ Global
{8BF22107-3CB9-C326-B94B-C40C99DA9B68}.Debug|Any CPU.Build.0 = Debug|Any CPU {8BF22107-3CB9-C326-B94B-C40C99DA9B68}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8BF22107-3CB9-C326-B94B-C40C99DA9B68}.Release|Any CPU.ActiveCfg = Release|Any CPU {8BF22107-3CB9-C326-B94B-C40C99DA9B68}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8BF22107-3CB9-C326-B94B-C40C99DA9B68}.Release|Any CPU.Build.0 = Release|Any CPU {8BF22107-3CB9-C326-B94B-C40C99DA9B68}.Release|Any CPU.Build.0 = Release|Any CPU
{B67C6FA8-DA47-41EC-B15A-511C5B19C036}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B67C6FA8-DA47-41EC-B15A-511C5B19C036}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B67C6FA8-DA47-41EC-B15A-511C5B19C036}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B67C6FA8-DA47-41EC-B15A-511C5B19C036}.Release|Any CPU.Build.0 = Release|Any CPU
{8DBBAA7C-C4D3-4ADD-8372-B0D6260C8FFC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {8DBBAA7C-C4D3-4ADD-8372-B0D6260C8FFC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8DBBAA7C-C4D3-4ADD-8372-B0D6260C8FFC}.Debug|Any CPU.Build.0 = Debug|Any CPU {8DBBAA7C-C4D3-4ADD-8372-B0D6260C8FFC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8DBBAA7C-C4D3-4ADD-8372-B0D6260C8FFC}.Release|Any CPU.ActiveCfg = Release|Any CPU {8DBBAA7C-C4D3-4ADD-8372-B0D6260C8FFC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8DBBAA7C-C4D3-4ADD-8372-B0D6260C8FFC}.Release|Any CPU.Build.0 = Release|Any CPU {8DBBAA7C-C4D3-4ADD-8372-B0D6260C8FFC}.Release|Any CPU.Build.0 = Release|Any CPU
{770E96B0-C3C9-A9A3-4F98-F7A0295D1599}.Debug|Any CPU.ActiveCfg = Release|Any CPU
{770E96B0-C3C9-A9A3-4F98-F7A0295D1599}.Debug|Any CPU.Build.0 = Release|Any CPU
{770E96B0-C3C9-A9A3-4F98-F7A0295D1599}.Release|Any CPU.ActiveCfg = Release|Any CPU
{770E96B0-C3C9-A9A3-4F98-F7A0295D1599}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE
@@ -96,8 +96,8 @@ Global
{56607AAB-3DEC-CB78-3062-56A8EEF5E9D2} = {71BEA4D0-7835-4A8C-B11E-1088E0801DCE} {56607AAB-3DEC-CB78-3062-56A8EEF5E9D2} = {71BEA4D0-7835-4A8C-B11E-1088E0801DCE}
{4CF993A6-FA3E-CBF7-C4CB-FFAEBFCFF705} = {71BEA4D0-7835-4A8C-B11E-1088E0801DCE} {4CF993A6-FA3E-CBF7-C4CB-FFAEBFCFF705} = {71BEA4D0-7835-4A8C-B11E-1088E0801DCE}
{8BF22107-3CB9-C326-B94B-C40C99DA9B68} = {B52B4CEE-1C67-424B-8659-370FEA7EAF2A} {8BF22107-3CB9-C326-B94B-C40C99DA9B68} = {B52B4CEE-1C67-424B-8659-370FEA7EAF2A}
{B67C6FA8-DA47-41EC-B15A-511C5B19C036} = {B52B4CEE-1C67-424B-8659-370FEA7EAF2A}
{8DBBAA7C-C4D3-4ADD-8372-B0D6260C8FFC} = {71BEA4D0-7835-4A8C-B11E-1088E0801DCE} {8DBBAA7C-C4D3-4ADD-8372-B0D6260C8FFC} = {71BEA4D0-7835-4A8C-B11E-1088E0801DCE}
{770E96B0-C3C9-A9A3-4F98-F7A0295D1599} = {B52B4CEE-1C67-424B-8659-370FEA7EAF2A}
EndGlobalSection EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {90E29FDC-F6C6-414F-94BF-25DF61D18060} SolutionGuid = {90E29FDC-F6C6-414F-94BF-25DF61D18060}

View File

@@ -0,0 +1,26 @@
namespace DigitalData.MessagingService.Publisher.Abstraction;
public record OutgoingEmailCreateDto
{
/// <summary>
/// Recipient email address
/// </summary>
public string Recipient { get; set; } = null!;
/// <summary>
/// Email subject
/// </summary>
public string Subject { get; set; } = null!;
/// <summary>
/// Email body (HTML or plain text)
/// </summary>
public string Body { get; set; } = null!;
/// <summary>
/// Is HTML email (default: true)
/// </summary>
public bool IsHtml { get; set; } = true;
public DateTime QueuedAt { get; set; }
}

View File

@@ -1,8 +1,6 @@
using System; namespace DigitalData.MessagingService.Publisher.Abstraction;
namespace DigitalData.MessagingService.Publisher.Abstraction; public record OutgoingEmailEvent
public class OutgoingEmailEvent
{ {
public Guid Id { get; set; } public Guid Id { get; set; }

View File

@@ -1,25 +1,35 @@
<Project Sdk="Microsoft.NET.Sdk.Web"> <Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net8.0</TargetFramework> <TargetFrameworks>net8.0</TargetFrameworks>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<UserSecretsId>dotnet-DigitalData.MessagingService.Service-e7ef6a9a-436f-48a1-b4f6-ec9381c8cb47</UserSecretsId> <GenerateDocumentationFile>true</GenerateDocumentationFile>
<PackageId>DigitalData.MessagingService.API</PackageId>
<Title></Title>
<Authors>Digital Data GmbH</Authors>
<Company>Digital Data GmbH</Company>
<Product>DigitalData.MessagingService.API</Product>
<Version>1.0.0-beta</Version>
<FileVersion>1.0.0.0</FileVersion>
<AssemblyVersion>1.0.0.0</AssemblyVersion>
<Copyright>Copyright © 2026 Digital Data GmbH. All rights reserved.</Copyright>
<DocumentationFile>bin\$(Configuration)\$(TargetFramework)\$(AssemblyName).xml</DocumentationFile>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Serilog.AspNetCore" Version="10.0.0" /> <PackageReference Include="Serilog.AspNetCore" Version="10.0.0" />
<PackageReference Include="Serilog.Settings.Configuration" Version="10.0.1" />
<PackageReference Include="Serilog.Sinks.Console" Version="6.1.1" /> <PackageReference Include="Serilog.Sinks.Console" Version="6.1.1" />
<PackageReference Include="Serilog.Sinks.File" Version="7.0.0" /> <PackageReference Include="Serilog.Sinks.File" Version="7.0.0" />
<PackageReference Include="Serilog.Sinks.SQLite" Version="7.0.0" />
<PackageReference Include="Serilog.UI" Version="3.2.0" />
<PackageReference Include="Serilog.UI.SqliteProvider" Version="1.1.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.2" /> <PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.2" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="10.0.10" /> <PackageReference Include="Microsoft.Extensions.Hosting" Version="10.0.10" />
<PackageReference Include="System.Security.Cryptography.Xml" Version="10.0.10" /> <PackageReference Include="System.Security.Cryptography.Xml" Version="10.0.10" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<Folder Include="Properties\" />
</ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\..\core\DigitalData.MessagingService.Application\DigitalData.MessagingService.Application.csproj" /> <ProjectReference Include="..\..\core\DigitalData.MessagingService.Application\DigitalData.MessagingService.Application.csproj" />
<ProjectReference Include="..\..\core\DigitalData.MessagingService.Domain\DigitalData.MessagingService.Domain.csproj" /> <ProjectReference Include="..\..\core\DigitalData.MessagingService.Domain\DigitalData.MessagingService.Domain.csproj" />

View File

@@ -3,15 +3,40 @@ using DigitalData.MessagingService.Application;
using DigitalData.MessagingService.Application.Common.Dtos; using DigitalData.MessagingService.Application.Common.Dtos;
using DigitalData.MessagingService.Infrastructure; using DigitalData.MessagingService.Infrastructure;
using Serilog; using Serilog;
using Serilog.Ui.Core.Extensions;
using Serilog.Ui.SqliteDataProvider.Extensions;
using Serilog.Ui.Web.Extensions;
// Configure Serilog early // Build temporary configuration to read log directory early
var tempConfig = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: false)
.AddJsonFile("appsettings.Secrets.json", optional: true, reloadOnChange: false)
.Build();
var logDirectoryRaw = tempConfig.GetValue<string>("Application:LogDirectory") ?? "logs";
// Always resolve to an absolute path so sink and UI provider point to the same file
var logDirectory = Path.IsPathRooted(logDirectoryRaw)
? logDirectoryRaw
: Path.Combine(AppContext.BaseDirectory, logDirectoryRaw);
Directory.CreateDirectory(logDirectory);
var sqliteDbPath = Path.Combine(logDirectory, "logs.db");
// Configure Serilog early (bootstrap + full pipeline)
Log.Logger = new LoggerConfiguration() Log.Logger = new LoggerConfiguration()
.WriteTo.Console() .MinimumLevel.Information()
.MinimumLevel.Override("Microsoft", Serilog.Events.LogEventLevel.Warning)
.MinimumLevel.Override("Microsoft.AspNetCore", Serilog.Events.LogEventLevel.Warning)
.MinimumLevel.Override("Microsoft.EntityFrameworkCore", Serilog.Events.LogEventLevel.Warning)
.MinimumLevel.Override("System", Serilog.Events.LogEventLevel.Warning)
.Enrich.FromLogContext()
.WriteTo.Console(outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level:u3}] {Message:lj}{NewLine}{Exception}")
.WriteTo.File( .WriteTo.File(
path: "logs/emailprofiler-.log", path: Path.Combine(logDirectory, "emailprofiler-.log"),
rollingInterval: RollingInterval.Day, rollingInterval: RollingInterval.Day,
retainedFileCountLimit: 30, retainedFileCountLimit: 30,
outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level:u3}] {Message:lj}{NewLine}{Exception}") outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level:u3}] {Message:lj}{NewLine}{Exception}")
.WriteTo.SQLite(sqliteDbPath, storeTimestampInUtc: true)
.CreateBootstrapLogger(); .CreateBootstrapLogger();
try try
@@ -25,12 +50,13 @@ try
.ReadFrom.Configuration(context.Configuration) .ReadFrom.Configuration(context.Configuration)
.ReadFrom.Services(services) .ReadFrom.Services(services)
.Enrich.FromLogContext() .Enrich.FromLogContext()
.WriteTo.Console() .WriteTo.Console(outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level:u3}] {Message:lj}{NewLine}{Exception}")
.WriteTo.File( .WriteTo.File(
path: "logs/emailprofiler-.log", path: Path.Combine(logDirectory, "emailprofiler-.log"),
rollingInterval: RollingInterval.Day, rollingInterval: RollingInterval.Day,
retainedFileCountLimit: 30, retainedFileCountLimit: 30,
outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level:u3}] {Message:lj}{NewLine}{Exception}")); outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level:u3}] {Message:lj}{NewLine}{Exception}")
.WriteTo.SQLite(sqliteDbPath, storeTimestampInUtc: true));
// Add appsettings.Secrets.json for sensitive configuration (not committed to git) // Add appsettings.Secrets.json for sensitive configuration (not committed to git)
builder.Configuration.AddJsonFile("appsettings.Secrets.json", optional: true, reloadOnChange: true); builder.Configuration.AddJsonFile("appsettings.Secrets.json", optional: true, reloadOnChange: true);
@@ -50,6 +76,16 @@ try
builder.Services.AddEndpointsApiExplorer(); builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen(); builder.Services.AddSwaggerGen();
// Register Serilog.UI with SQLite provider for web log viewer
builder.Services.AddSerilogUi(options =>
{
options.UseSqliteServer(dbOpt =>
{
dbOpt.WithConnectionString($"Data Source={sqliteDbPath}");
dbOpt.WithTable("Logs");
});
});
var app = builder.Build(); var app = builder.Build();
// Add global exception handling middleware // Add global exception handling middleware
@@ -58,8 +94,11 @@ try
// Add Serilog request logging // Add Serilog request logging
app.UseSerilogRequestLogging(); app.UseSerilogRequestLogging();
// Configure the HTTP request pipeline. // Configure Swagger — enabled in Development always, and in other environments based on appsettings
if (app.Environment.IsDevelopment()) var swaggerEnabled = app.Environment.IsDevelopment()
|| app.Configuration.GetValue<bool>("Swagger:Enabled");
if (swaggerEnabled)
{ {
app.UseSwagger(); app.UseSwagger();
app.UseSwaggerUI(); app.UseSwaggerUI();
@@ -67,6 +106,9 @@ try
app.UseHttpsRedirection(); app.UseHttpsRedirection();
// Serve Serilog.UI log viewer at /serilog-ui
app.UseSerilogUi();
app.UseAuthorization(); app.UseAuthorization();
app.MapControllers(); app.MapControllers();

View File

@@ -11,6 +11,12 @@
} }
}, },
"AllowedHosts": "*", "AllowedHosts": "*",
"Application": {
"LogDirectory": "logs"
},
"Swagger": {
"Enabled": true
},
"Workers": { "Workers": {
"EmailSender": { "EmailSender": {
"Enabled": true "Enabled": true

View File

@@ -11,7 +11,7 @@
<PackageIcon>icon.png</PackageIcon> <PackageIcon>icon.png</PackageIcon>
<RepositoryUrl>http://git.dd:3000/AppStd/Rec.git</RepositoryUrl> <RepositoryUrl>http://git.dd:3000/AppStd/Rec.git</RepositoryUrl>
<PackageTags>digital data messaging service api client</PackageTags> <PackageTags>digital data messaging service api client</PackageTags>
<Version>1.0.0-beta</Version> <Version>1.0.0</Version>
<AssemblyVersion>1.0.0.0</AssemblyVersion> <AssemblyVersion>1.0.0.0</AssemblyVersion>
<FileVersion>1.0.0.0</FileVersion> <FileVersion>1.0.0.0</FileVersion>
<Description></Description> <Description></Description>

View File

@@ -0,0 +1,46 @@
using DigitalData.MessagingService.Publisher.Abstraction;
namespace DigitalData.MessagingService.Client;
/// <summary>
/// Represents an outgoing email message to be sent through the messaging service.
/// </summary>
public record Email
{
/// <summary>
/// Recipient email address
/// </summary>
public string Recipient { get; set; } = null!;
/// <summary>
/// Email subject
/// </summary>
public string Subject { get; set; } = null!;
/// <summary>
/// Email body (HTML or plain text)
/// </summary>
public string Body { get; set; } = null!;
/// <summary>
/// Is HTML email (default: true)
/// </summary>
public bool IsHtml { get; set; } = true;
/// <summary>
/// Converts this <see cref="Email"/> instance to an <see cref="OutgoingEmailEvent"/>.
/// </summary>
/// <returns>A new <see cref="OutgoingEmailEvent"/> representing this email.</returns>
internal OutgoingEmailEvent ToEvent()
{
return new OutgoingEmailEvent
{
Id = Guid.NewGuid(),
Recipient = Recipient,
Subject = Subject,
Body = Body,
IsHtml = IsHtml,
QueuedAt = DateTime.Now
};
}
}

View File

@@ -106,24 +106,25 @@ public static class EmailSender
} }
/// <summary> /// <summary>
/// Enqueues the specified email event to the RabbitMQ messaging pipeline. /// Enqueues the specified email to the RabbitMQ messaging pipeline.
/// </summary> /// </summary>
/// <param name="email">The outgoing email event to enqueue.</param> /// <param name="email">The outgoing email data to enqueue.</param>
/// <exception cref="InvalidOperationException"> /// <exception cref="InvalidOperationException">
/// Thrown when <see cref="ConnectRabbitMq(Action{RabbitMqConfiguration}, OnReconnect)"/> has not been called prior to sending. /// Thrown when <see cref="ConnectRabbitMq(Action{RabbitMqConfiguration}, OnReconnect)"/> has not been called prior to sending.
/// </exception> /// </exception>
/// <remarks> /// <remarks>
/// This method resolves <see cref="IOutgoingEmailPublisher"/> from the internal /// This method maps <see cref="Email"/> to <see cref="OutgoingEmailEvent"/>,
/// then resolves <see cref="IOutgoingEmailPublisher"/> from the internal
/// service provider and calls <c>EnqueueAsync</c> in a fire-and-forget manner. /// service provider and calls <c>EnqueueAsync</c> in a fire-and-forget manner.
/// Ensure that any unhandled exceptions from the async operation are handled /// Ensure that any unhandled exceptions from the async operation are handled
/// at the publisher level. /// at the publisher level.
/// </remarks> /// </remarks>
public static void Send(OutgoingEmailEvent email) public static void Send(Email email)
{ {
if(!IsConnected) if(!IsConnected)
throw new InvalidOperationException("Messaging service is not connected. Call ConnectRabbitMq first."); throw new InvalidOperationException("Messaging service is not connected. Call ConnectRabbitMq first.");
var publisher = LazyProvider.Value.GetRequiredService<IOutgoingEmailPublisher>(); var publisher = LazyProvider.Value.GetRequiredService<IOutgoingEmailPublisher>();
publisher.EnqueueAsync(email); publisher.EnqueueAsync(email.ToEvent());
} }
} }

View File

@@ -1,7 +1,7 @@
namespace DigitalData.MessagingService.Client; namespace DigitalData.MessagingService.Client;
/// <summary> /// <summary>
/// Defines the behavior when <see cref="EmailSender.ConnectRabbitMq"/> is called /// Defines the behavior when <see cref="EmailSender.ConnectRabbitMq(Action{RabbitMQ.RabbitMqConfiguration}, OnReconnect)"/> is called
/// while a connection has already been established. /// while a connection has already been established.
/// </summary> /// </summary>
public enum OnReconnect public enum OnReconnect

View File

@@ -63,30 +63,28 @@ EmailSender.ConnectRabbitMq(
### 2. E-Mail versenden ### 2. E-Mail versenden
```csharp ```csharp
EmailSender.Send(new OutgoingEmailEvent EmailSender.Send(new Email
{ {
Id = Guid.NewGuid(),
Recipient = "empfaenger@beispiel.de", Recipient = "empfaenger@beispiel.de",
Subject = "Willkommen", Subject = "Willkommen",
Body = "<p>Hallo Welt!</p>", Body = "<p>Hallo Welt!</p>",
IsHtml = true, IsHtml = true
QueuedAt = DateTime.Now
}); });
``` ```
```vb ```vb
EmailSender.Send(New OutgoingEmailEvent With { EmailSender.Send(New Email With {
.Id = Guid.NewGuid(),
.Recipient = "empfaenger@beispiel.de", .Recipient = "empfaenger@beispiel.de",
.Subject = "Willkommen", .Subject = "Willkommen",
.Body = "<p>Hallo Welt!</p>", .Body = "<p>Hallo Welt!</p>",
.IsHtml = True, .IsHtml = True
.QueuedAt = DateTime.Now
}) })
``` ```
`Send` ist eine **Fire-and-Forget**-Methode: die Nachricht wird in die RabbitMQ-Queue eingereiht und der aufrufende Code wartet nicht auf die eigentliche Zustellung. `Send` ist eine **Fire-and-Forget**-Methode: die Nachricht wird in die RabbitMQ-Queue eingereiht und der aufrufende Code wartet nicht auf die eigentliche Zustellung.
> **Hinweis:** `Id` und `QueuedAt` werden intern automatisch gesetzt. Im `Email`-Objekt müssen nur `Recipient`, `Subject`, `Body` und `IsHtml` angegeben werden.
### 3. Verbindungsstatus prüfen ### 3. Verbindungsstatus prüfen
```csharp ```csharp

View File

@@ -75,14 +75,12 @@ public sealed class EmailSenderTests
[Fact] [Fact]
public void Send_WithValidEmail_DoesNotThrow() public void Send_WithValidEmail_DoesNotThrow()
{ {
var email = new OutgoingEmailEvent var email = new Email
{ {
Id = Guid.NewGuid(),
Recipient = "hakanttek@gmail.com", Recipient = "hakanttek@gmail.com",
Subject = "EmailSender.Send Integration Test", Subject = "EmailSender.Send Integration Test",
Body = "<p>Sent via EmailSender static client.</p>", Body = "<p>Sent via EmailSender static client.</p>",
IsHtml = true, IsHtml = true,
QueuedAt = DateTime.Now
}; };
var exception = Record.Exception(() => EmailSender.Send(email)); var exception = Record.Exception(() => EmailSender.Send(email));
@@ -93,14 +91,12 @@ public sealed class EmailSenderTests
[Fact] [Fact]
public void Send_WithPlainTextBody_DoesNotThrow() public void Send_WithPlainTextBody_DoesNotThrow()
{ {
var email = new OutgoingEmailEvent var email = new Email
{ {
Id = Guid.NewGuid(),
Recipient = "hakanttek@gmail.com", Recipient = "hakanttek@gmail.com",
Subject = "Plain Text Test", Subject = "Plain Text Test",
Body = "This is a plain text email.", Body = "This is a plain text email.",
IsHtml = false, IsHtml = false
QueuedAt = DateTime.Now
}; };
var exception = Record.Exception(() => EmailSender.Send(email)); var exception = Record.Exception(() => EmailSender.Send(email));

View File

@@ -55,14 +55,12 @@ public sealed class EmailSenderUrlOverloadTests
[Fact] [Fact]
public void Send_AfterUrlOverloadConnection_DoesNotThrow() public void Send_AfterUrlOverloadConnection_DoesNotThrow()
{ {
var email = new OutgoingEmailEvent var email = new Email
{ {
Id = Guid.NewGuid(),
Recipient = "url-overload-test@example.com", Recipient = "url-overload-test@example.com",
Subject = "URL Overload Integration Test", Subject = "URL Overload Integration Test",
Body = "<p>Sent after URL-based connection.</p>", Body = "<p>Sent after URL-based connection.</p>",
IsHtml = true, IsHtml = true
QueuedAt = DateTime.Now
}; };
// Connection was established via Action<> overload in the fixture; // Connection was established via Action<> overload in the fixture;