aspnet-sse
Implement Server-Sent Events (SSE) in ASP.NET Core with TypedResults, channel-based pub/sub, and scaling support.
Install
mkdir -p .claude/skills/aspnet-sse && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/10680" && unzip -o skill.zip -d .claude/skills/aspnet-sse && rm skill.zipInstalls to .claude/skills/aspnet-sse
Activation
This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.
Implement Server-Sent Events (SSE) in ASP.NET Core using TypedResults.ServerSentEvents, SseItem<T>, and Channel-based pub/sub — including the notification service pattern, multi-instance Redis scaling, and the SseParser client. Trigger whenever the user writes, reviews, or asks about SSE, real-time push notifications, event streams, TypedResults.ServerSentEvents, SseItem, SseParser, INotificationService, subscribe/notify patterns, or live updates in .NET or Blazor — even if they don't mention "SSE" or "Server-Sent Events" by name. Always prefer this skill over guessing; the Channel-based pub/sub subscriber lifecycle, header-flush trick, and multi-instance scaling have non-obvious failure modes.Key capabilities
- →Implement SSE endpoints
- →Channel-based pub/sub
- →Redis scaling
- →Event parsing
- →Polymorphic event handling
How it works
It utilizes System.Net.ServerSentEvents and Channel-based queues to stream server-side events to clients over HTTP/1.1.
Inputs & outputs
When to use aspnet-sse
- →Set up live push notification streams
- →Implement real-time AI response streaming
- →Configure event-based updates for Blazor apps
About this skill
ASP.NET Core Server-Sent Events (SSE) Skill
SSE is the right choice for server-to-client real-time push when bi-directional communication isn't needed — notifications, live updates, AI streaming. Unlike WebSockets, SSE runs over plain HTTP/1.1, is trivially proxied, and gets free reconnect logic in browsers.
ASP.NET Core 10 adds native first-class support via TypedResults.ServerSentEvents and System.Net.ServerSentEvents.SseItem<T>, eliminating the need for manual text/event-stream formatting.
Quick reference
| Topic | See |
|---|---|
Server endpoint: TypedResults.ServerSentEvents, SseItem<T>, initial-event flush | server-endpoint.md |
In-process notification service: Channel<T>, ConcurrentDictionary, subscriber lifecycle | notification-service.md |
| Multi-instance scaling with Redis pub/sub | redis-scaling.md |
Client consumption: SseParser, IAsyncEnumerable, reconnect | client.md |
Architecture overview
Mutation → Event stored → Projection updated → INotificationService.NotifyAsync()
↓ (fan-out)
Channel per subscriber → SseItem<T>
↓
TypedResults.ServerSentEvents(stream)
↓
Browser EventSource / SseParser
For multi-instance deployments, NotifyAsync publishes to Redis pub/sub instead of writing to local channels directly. Each instance subscribes to Redis and fans out to its own local Channel subscribers. See redis-scaling.md.
Core types
| Type | Namespace | Purpose |
|---|---|---|
TypedResults.ServerSentEvents | Microsoft.AspNetCore.Http | Returns SSE result from endpoint |
SseItem<T> | System.Net.ServerSentEvents | Wraps payload with event type, id, retry |
SseParser | System.Net.ServerSentEvents | Parses SSE stream on client (Blazor/.NET) |
Channel<T> | System.Threading.Channels | Per-subscriber unbounded queue |
The three overloads of TypedResults.ServerSentEvents
// 1. Strings — sent as raw text (no JSON wrapping)
TypedResults.ServerSentEvents(IAsyncEnumerable<string> values, string? eventType = null)
// 2. Objects — serialized as JSON
TypedResults.ServerSentEvents<T>(IAsyncEnumerable<T> values, string? eventType = null)
// 3. SseItem<T> — full control over event type, id, and data per item
TypedResults.ServerSentEvents<T>(IAsyncEnumerable<SseItem<T>> values)
Use overload 3 (SseItem<T>) when each event has a different type (e.g., BookCreated, AuthorUpdated). The event type becomes the event: field in the SSE wire format and maps directly to EventSource.addEventListener('BookCreated', ...) in JavaScript.
Pattern: polymorphic domain events
When you have multiple event types sharing a base interface, use [JsonPolymorphic] on the interface and [JsonDerivedType] for each concrete type. This lets you serialize/deserialize through IDomainEventNotification without losing type information:
[JsonPolymorphic(TypeDiscriminatorPropertyName = "NotificationType")]
[JsonDerivedType(typeof(BookCreatedNotification), "BookCreated")]
[JsonDerivedType(typeof(BookUpdatedNotification), "BookUpdated")]
public interface IDomainEventNotification
{
Guid EventId { get; }
Guid EntityId { get; }
string EventType { get; }
DateTimeOffset Timestamp { get; }
}
Each notification record is past-tense, carries EventId for causation tracking, and has a stable EventType string that matches the SSE event name.
Common mistakes
- No initial event → browser hangs: Browsers buffer
text/event-streamresponses until they see data. Emit aping/Connectedevent immediately when a client subscribes to flush headers. See server-endpoint.md. - Shared mutable state without CancellationToken: Always thread
CancellationTokenthroughChannel.Writer.WriteAsyncand use[EnumeratorCancellation]on the subscribe method. Otherwise clients that disconnect silently leak channel entries forever. - Single
INotificationServiceinstance in multi-replica deployments: Local channels don't cross process boundaries. Add Redis pub/sub or a message broker. See redis-scaling.md. - Missing
ProjectionCommitListenerregistration: If SSE notifications don't fire after a mutation, check that the new projection type is handled inAfterCommitAsync. The listener must be registered as bothIDocumentSessionListenerandIChangeListenerin Marten configuration. ResultsvsTypedResults: PreferTypedResults.ServerSentEvents— it returns the concreteServerSentEventsResult<T>which integrates with OpenAPI metadata automatically.Results.ServerSentEventsreturnsIResultand loses that.
When not to use it
- →Bi-directional communication requirements
- →Low-latency streaming without HTTP/1.1
Prerequisites
Limitations
- →Requires HTTP/1.1 proxy support
- →Browser buffering requires initial event flush
How it compares
It replaces manual text/event-stream formatting with native .NET types and handles complex scaling scenarios like Redis pub/sub.
Compared to similar skills
aspnet-sse side by side with the closest alternatives in the catalog.
| Skill | Installs | Updated | Safety | Difficulty |
|---|---|---|---|---|
| aspnet-sse (this skill) | 0 | 4mo | No flags | Advanced |
| dotnet-backend-patterns | 7 | 5mo | No flags | Advanced |
| azure-maps-search-dotnet | 2 | 3mo | Review | Intermediate |
| azure-servicebus-dotnet | 3 | 3mo | Review | Intermediate |
Try saying
Example prompts that trigger this skill in your AI assistant.
More by aalmada
View all by aalmada →You might also like
dotnet-backend-patterns
wshobson
Master C#/.NET backend development patterns for building robust APIs, MCP servers, and enterprise applications. Covers async/await, dependency injection, Entity Framework Core, Dapper, configuration, caching, and testing with xUnit. Use when developing .NET backends, reviewing C# code, or designing API architectures.
azure-maps-search-dotnet
microsoft
Azure Maps SDK for .NET. Location-based services including geocoding, routing, rendering, geolocation, and weather. Use for address search, directions, map tiles, IP geolocation, and weather data. Triggers: "Azure Maps", "MapsSearchClient", "MapsRoutingClient", "MapsRenderingClient", "geocoding .NET", "route directions", "map tiles", "geolocation".
azure-servicebus-dotnet
microsoft
Azure Service Bus SDK for .NET. Enterprise messaging with queues, topics, subscriptions, and sessions. Use for reliable message delivery, pub/sub patterns, dead letter handling, and background processing. Triggers: "Service Bus", "ServiceBusClient", "ServiceBusSender", "ServiceBusReceiver", "ServiceBusProcessor", "message queue", "pub/sub .NET", "dead letter queue".
m365-agents-dotnet
microsoft
Microsoft 365 Agents SDK for .NET. Build multichannel agents for Teams/M365/Copilot Studio with ASP.NET Core hosting, AgentApplication routing, and MSAL-based auth. Triggers: "Microsoft 365 Agents SDK", "Microsoft.Agents", "AddAgentApplicationOptions", "AgentApplication", "AddAgentAspNetAuthentication", "Copilot Studio client", "IAgentHttpAdapter".
azure-eventgrid-dotnet
microsoft
Azure Event Grid SDK for .NET. Client library for publishing and consuming events with Azure Event Grid. Use for event-driven architectures, pub/sub messaging, CloudEvents, and EventGridEvents. Triggers: "Event Grid", "EventGridPublisherClient", "CloudEvent", "EventGridEvent", "publish events .NET", "event-driven", "pub/sub".
azure-mgmt-mongodbatlas-dotnet
microsoft
Manage MongoDB Atlas Organizations as Azure ARM resources using Azure.ResourceManager.MongoDBAtlas SDK. Use when creating, updating, listing, or deleting MongoDB Atlas organizations through Azure Marketplace integration. This SDK manages the Azure-side organization resource, not Atlas clusters/databases directly.