Skip to content

Search EricksonLopez.* Ecosystem

Type a library name, NuGet package ID, .NET type, or architectural concept to search across the portal.

Guides & Recipes — Messaging

Verified testing and middleware recipes compiled on .NET 10 (ImplicitUsings=disable, Nullable=enable).

using System;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using EricksonLopez.Messaging.Contracts;
using EricksonLopez.Messaging.Testing;
using EricksonLopez.Messaging.Transport;
using EricksonLopez.Result;
namespace Example.MessagingQuickStart;
public static class HarnessRecipe
{
public static async Task VerifyPublishAsync(CancellationToken ct)
{
var harness = new InMemoryTestHarness();
byte[] payload = Encoding.UTF8.GetBytes("{\"orderId\":\"1001\"}");
var metadata = TransportMessageMetadata.Create("orders.confirmed", correlationId: "corr-100");
Result result = await harness.PublishRawAsync("orders-topic", payload, metadata, ct);
if (result.IsFailure || harness.PublishedMessages.Count != 1)
{
throw new InvalidOperationException("Expected one published message in harness.");
}
}
}

In v2.0.0 (BC-003), construct RetryMiddleware using RetryOptions rather than the removed 3-parameter constructor:

using System;
using EricksonLopez.Messaging.Middleware;
namespace Example.MessagingQuickStart;
public static class RetryRecipe
{
public static RetryMiddleware CreateRetryMiddleware()
{
return new RetryMiddleware(new RetryOptions
{
MaxRetries = 3,
InitialDelay = TimeSpan.FromSeconds(1),
TimeProvider = TimeProvider.System,
});
}
}