Kanject EventHub
A strongly-typed, serverless event bus on AWS — publish typed events and fan them out to subscribers over SNS + SQS, without hand-writing topic and queue wiring. Deployed into your own account.
- Provision EventHub into your AWS account
- Register the client with
AddServerlessEventHubClient - Publish typed
[HubEvent]events - Subscribe with an
IEventHubRequestHandler<T>bound to an SQS queue
Provision
kanject baas deploy eventhub --env dev Register it in your service
Register the client with AddServerlessEventHubClient(serviceName, config). The serviceName scopes this service's topics and queues on the shared bus; the transport is SNS + SQS fan-out (EventBridge is used only for scheduled events).
using Kanject.ServerlessEventHub.Provider.AwsSnsV4.Extensions;var builder = WebApplication.CreateBuilder(args);// serviceName scopes this service's topics/queues on the shared bus.builder.Services.AddServerlessEventHubClient( serviceName: "orders", new AwsServerlessEventHubConfiguration { /* region, schema, … */ });var app = builder.Build();app.Run(); Publish typed events
Events are C# classes marked with [HubEvent(Topic, Version)]. Inject IServerlessEventHubClient (or IPublishEventAction) and call PublishAsync — the event goes to its SNS topic, and subscribed SQS queues fan out from there.
using Kanject.ServerlessEventHub.Abstractions.Attributes;// Events are typed classes, marked with a topic + version.[HubEvent(Topic = "order.completed", Version = 1)]public sealed class OrderCompleted{ public string OrderId { get; set; } = ""; public string UserId { get; set; } = ""; public decimal Amount { get; set; }}// Publish: inject IServerlessEventHubClient (or IPublishEventAction).public class OrderService(IServerlessEventHubClient hub){ public Task PublishAsync(OrderCompleted evt) => hub.PublishAsync(evt); // → SNS topic; SQS subscribers fan out} Subscribe
A subscriber implements IEventHubRequestHandler<TEventArgs>. Register it with AddEventHubHandler<,>() and bind an SQS queue to the topics it consumes with SubscribeQueueToTopic — an explicit infrastructure wiring, not attribute auto-magic.
// Subscribe: implement IEventHubRequestHandler<TEventArgs>, then register it// and bind an SQS queue to the topic(s) it consumes.public sealed class LedgerProjector : IEventHubRequestHandler<OrderCompletedArgs>{ public Task OnIncomingRequest(object sender, EventHubRequestHandlerArgs e) { // handle the delivered event return Task.CompletedTask; }}// Composition root:services.AddEventHubHandler<LedgerProjector, OrderCompletedArgs>();services.SubscribeQueueToTopic("orders-ledger", "order.completed"); What you get
- Typed events — a C# class per event, marked
[HubEvent(Topic, Version)]. - SNS + SQS fan-out — publish to a topic; each subscriber drains its own SQS queue.
- Explicit subscriptions —
IEventHubRequestHandler<T>+AddEventHubHandler<,>()+SubscribeQueueToTopic. - Service scoping —
serviceNamenamespaces each service's topics and queues on the shared bus. - Scheduled events — an EventBridge scheduling extension for time-based publishes.
- Provision with
kanject baas deploy eventhub; register withAddServerlessEventHubClient(serviceName, config). - The real package is
Kanject.ServerlessEventHub(brand: EventHub); transport is SNS + SQS fan-out. - Publish
[HubEvent]classes viaIServerlessEventHubClient.PublishAsync. - Subscribe with
IEventHubRequestHandler<T>+AddEventHubHandler<,>()+SubscribeQueueToTopic.