Lumen.SSE
1.0.0
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package Lumen.SSE --version 1.0.0
NuGet\Install-Package Lumen.SSE -Version 1.0.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Lumen.SSE" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Lumen.SSE" Version="1.0.0" />
<PackageReference Include="Lumen.SSE" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Lumen.SSE --version 1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Lumen.SSE, 1.0.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Lumen.SSE@1.0.0
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Lumen.SSE&version=1.0.0
#tool nuget:?package=Lumen.SSE&version=1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
🔌 SSE for ASP.NET Core
A lightweight, configurable Server-Sent Events (SSE) library for ASP.NET Core.
Easily add real-time, uni-directional server-to-client messaging without WebSockets.
✨ Features
- ✅ Simple integration with minimal APIs
- 🧩 Middleware-based connection handling
- 🧠 Supports multiple clients & devices per user
- 🔄 Built-in ping/keep-alive
- 🔧 Fully configurable endpoints and connection logic
- 📦 .NET 6/7/8 compatible
📦 Installation
Install via NuGet:
dotnet add package Lumen.SSE
🚀 Usage
1. Configure services
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddSse(config =>
{
config.PingIntervalMilliseconds = 30_000;
config.ConnectionLiveMinutes = null;
config.MaxEventsForConnection = null;
});
2. Configure middleware
var app = builder.Build();
app.UseSse(options =>
{
options.ConnectionPath = "/sse/connection";
options.UserId = ctx =>
{
var userId = ctx.Request.Query["userId"].FirstOrDefault() ?? string.Empty;
return Guid.Parse(userId);
};
options.DeviceId = ctx =>
{
var deviceIdQuery = ctx.Request.Query["deviceId"].FirstOrDefault();
return Guid.TryParse(deviceIdQuery, out var id) ? id : null;
};
});
3. Send events
app.MapPost("/send-message/{clientId:guid}", async (
Guid clientId,
Guid? deviceId,
Message message,
ISseBuilder sse) =>
{
const string eventType = "new_message";
var sender = sse.Build()
.SetEventName(eventType)
.SetData(message);
if (deviceId != null)
await sender.SendAsync(clientId, deviceId.Value);
else
await sender.SendToClientAllDevicesAsync(clientId);
});
📡 Client-Side (JavaScript)
const userId = "e4d65e91-8dc1-49fb-a13f-bb07f847fcb4";
const deviceId = "bce0f4a6-73ff-45dc-aede-678942aec99e";
const sseUrl = `https://localhost:7287/sse/connection?userId=${userId}&deviceId=${deviceId}`;
const eventSource = new EventSource(sseUrl);
eventSource.onopen = () => {
console.log("✅ Connected to SSE server");
};
eventSource.onmessage = (event) => {
try {
const parsedData = JSON.parse(event.data);
console.log("📨 Json Message:", parsedData);
} catch (error) {
console.warn("📨 Default Message:", event.data);
}
};
eventSource.addEventListener("new_message", (event) => {
const parsedData = JSON.parse(event.data);
console.log("📨 New Message:", parsedData);
});
eventSource.addEventListener("ping", (event) => {
console.log("🔁 Ping:", event.data);
});
eventSource.addEventListener("disconnect", (event) => {
console.warn("❌ Disconnected:", event.data);
eventSource.close();
});
eventSource.onerror = (err) => {
console.error("🚨 SSE connection error:", err);
};
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net9.0
- Lumen.Core (>= 1.0.0)
- Microsoft.AspNetCore.Http.Abstractions (>= 2.3.0)
- Microsoft.Extensions.Options (>= 9.0.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.