Fast.EventBus
Public members, parameters, returns, and exceptions
Reference source version 3.5.35; targets: net8.0;net9.0;net10.0.
When upgrading code that uses platform flags, see the Runtime H5 migration guide and the dependency history.
Contract and constraints
An in-process bounded channel, not a durable or distributed message broker. AddEventBus() registers singleton publishing, dynamic subscriptions, discovered IEventSubscriber implementations and a background consumer. Default capacity is 3000. Subscriber methods return Task and take EventHandlerExecutingContext. The HTTP 202 example acknowledges enqueueing, not completed processing. PublishDelayAsync uses milliseconds and is not a persistent scheduler. EventSubscribeAttribute defaults to NumRetries=0, RetryTimeout=1000, Order=0 and GCCollect=false. Retries can repeat side effects; handlers need their own idempotency. Multiple handlers may run concurrently, and Order is not a transactional serialization guarantee. Pending work can be lost when the process exits.
Installation and examples
Install the package
dotnet add package Fast.EventBusExample 1
using Fast.EventBus;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddEventBus();
var app = builder.Build();
app.MapPost("/notices", async (Notice notice, IEventPublisher publisher, CancellationToken cancellationToken) =>
{
await publisher.PublishAsync("notice.received", notice, cancellationToken);
return Results.Accepted();
});
app.Run();
public sealed record Notice(string Message);
public sealed class NoticeSubscriber : IEventSubscriber
{
[EventSubscribe("notice.received")]
public Task ReceiveAsync(EventHandlerExecutingContext context)
{
if (context.Source.Payload is Notice notice)
{
Console.WriteLine(notice.Message);
}
return Task.CompletedTask;
}
}Web-host examples belong in a consumer project using Microsoft.NET.Sdk.Web and a supported .NET target. IaaS examples can be used in an ordinary class library. Registration precedes builder.Build(); configure middleware and endpoints before app.Run(). Samples retain their original code and comments. No host, external service, database operation or client generator was run, and these snippets have not been compiled in this update.
Source reference
Nested publication and bounded backpressure
Ordinary publishers wait when the bounded queue is full. A handler publishing recursively to its own queue enqueues immediately when capacity exists; a full queue throws InvalidOperationException rather than waiting for itself. The implementation does not use an unbounded queue, drop events silently, or start detached tasks. Publish after the current handler completes or explicitly handle capacity failure.
Automatic scanning accepts only closed, concrete implementations. Explicit monitor registration takes precedence; multiple discovered monitors require an explicit choice.
Cancellation and retry boundaries
Since Fast.EventBus 3.5.30, the implementation checks the linked host/event token before the first attempt, before every retry and before retry/fallback processing after a failure. Immediate retries without a delay also observe cancellation. Once cancellation is observed, no further retry or fallback callback runs. This does not forcibly interrupt a handler that has already started; handlers must observe the event token themselves.
NumRetries is the maximum number of retries after the initial execution. Zero or a negative value executes once without entering the retry loop. Exhausted retries or an exception incompatible with every entry of a nonempty ExceptionTypes array enter the failure path. Matching includes derived exception types. A null or empty exception-type array does not restrict retries by type.
Dependency alignment on 2026-11-02
2026-11-02 dependency alignment: this package increments from 3.5.34 to 3.5.35, updating its dependency to Fast.Runtime 3.5.37. This module's implementation and public declarations are unchanged. Runtime adds mobile H5 and shifts Android and subsequent flags; migrate numeric protocols/masks, rebuild consumers and regenerate client enums. See the Runtime H5 migration guide.
2026-10-24 versions and dependencies
On 2026-10-24, this package increments from 3.5.31 to 3.5.32, with dependencies updated to Fast.Runtime 3.5.34. This module's own implementation and public declarations are unchanged.
Consumers using AppEnvironmentEnum must migrate numeric values and rebuild according to the Runtime HarmonyOS migration guide. This batch reviewed source and effective MSBuild package metadata only. Tests were skipped as requested; no restore, build, pack or consumer runtime validation was performed.
