ServerSentEvents.Processor 1.0.3

dotnet add package ServerSentEvents.Processor --version 1.0.3
                    
NuGet\Install-Package ServerSentEvents.Processor -Version 1.0.3
                    
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="ServerSentEvents.Processor" Version="1.0.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ServerSentEvents.Processor" Version="1.0.3" />
                    
Directory.Packages.props
<PackageReference Include="ServerSentEvents.Processor" />
                    
Project file
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 ServerSentEvents.Processor --version 1.0.3
                    
#r "nuget: ServerSentEvents.Processor, 1.0.3"
                    
#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.
#addin nuget:?package=ServerSentEvents.Processor&version=1.0.3
                    
Install ServerSentEvents.Processor as a Cake Addin
#tool nuget:?package=ServerSentEvents.Processor&version=1.0.3
                    
Install ServerSentEvents.Processor as a Cake Tool

ServerSentEvents

A lightweight and extensible Server-Sent Events (SSE) library for .NET

ServerSentEvents is a C# library that simplifies working with Server-Sent Events (SSE) in .NET applications. It provides a structured way to consume, process, and manage SSE connections efficiently.

Features

Abstractions for SSE – Define and implement SSE consumers and processors with ease.
Event Processing – Handle real-time events efficiently using the provided processor.
Flexible & Extensible – Customize components to fit your application's needs.
Blazor & ASP.NET Core Support – Seamlessly integrate with Blazor Server, ASP.NET Core APIs, and other real-time applications.

Packages

This repository contains a set of C# libraries for working with Server-Sent Events (SSE). The library is split into three NuGet packages, each serving a distinct purpose:

Package Name Description NuGet Link
ServerSentEvents.Abstractions Core interfaces and abstractions for SSE https://www.nuget.org/packages/ServerSentEvents.Abstractions
ServerSentEvents.Consumer For consuming SSE streams within Blazor WASM project https://www.nuget.org/packages/ServerSentEvents.Consumer
ServerSentEvents.Processor Processing logic for SSE data within Blazor ASP.NET Hosted project https://www.nuget.org/packages/ServerSentEvents.Processor

These packages are designed to work together seamlessly, sharing a common foundation while allowing flexibility for specific use cases.

Use Cases

This package is ideal for:

  • Real-time updates – Stock prices, live dashboards, and monitoring systems.
  • Live notifications – Chat applications, system alerts, and event-driven workflows.
  • Streaming data – Logs, metrics, and continuous data streams.

Resources

🔗 GitHub Repository: https://github.com/dotnetnoobie/ServerSentEvents

🔗 Server-sent events: https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events
🔗 Using server-sent events: https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events
🔗 HTML Server-Sent Events API: https://www.w3schools.com/html/html5_serversentevents.asp

📖 Documentation: [Coming Soon]

Get Started

In Visual Studio Create a Blazor Web App

Option Description
Framework .NET 9.0
Interactivite render mode WebAssembly
Interactivity location Global

Add a .NET 9.0 class library called Models to your solution

General Project Structure

Project Description
BlazorApp.Models C# class library shared between the host and client apps which contains message objects
BlazorApp ASP.NET app to host the Blazor WASM client app
BlazorApp.Client Blazor WASM client app

BlazorApp.Models Project

Installation

You can install the package via NuGet Package Manager or the .NET CLI. Below are the commands for each package:

dotnet add package ServerSentEvents.Abstractions

In a shared project add message objects, example of some simple messages, message objects must implement the IServerSentEvent interface from the ServerSentEvents.Abstractions NuGet package

Concepually message objects are DTO type objects for transporting data

using ServerSentEvents.Abstractions;

namespace BlazorApp.Models;

public record ClearItems() : IServerSentEvent;
public record DemoEvent(DateTime Date) : IServerSentEvent;
public record SportScore(int Team1Score, int Team2Score) : IServerSentEvent;
public record WeatherForecast(DateOnly Date, int TemperatureC, string? Summary) : IServerSentEvent;

BlazorApp Project

To use ServerSentEvents.Processor, follow this example:

Installation

You can install the package via NuGet Package Manager or the .NET CLI. Below are the commands for each package:

dotnet add package ServerSentEvents.Processor

Add to the program.cs file

using ServerSentEvents.Processor;
builder.Services.AddHttpClient();
builder.Services.AddServerSentEvents();
app.UseServerSentEvents();

BlazorApp.Client Project

To use ServerSentEvents.Consumer, follow this example:

Installation

You can install the package via NuGet Package Manager or the .NET CLI. Below are the commands for each package:

dotnet add package ServerSentEvents.Consumer

Add to the program.cs file

builder.AddServerSentEventsConsumer([typeof(ClearItems), typeof(SportScore), typeof(WeatherForecast), typeof(DemoEvent)]);

AddServerSentEventsConsumer([]) takes an array of types that implement IServerSentEvent these are the messages that the BlazorApp.Client WASM app will be listerning for from the BlazorApp host project

Add to the MainLayout.razor file

@code {
    [Inject] public IServerSentEventConsumer ServerSentEventClient { get; set; } = default!;
}

By adding this to the MainLayout.razor file it will automatically connect and listen to the BlazorApp host project for any Server Sent Events

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.3 147 4/2/2025
1.0.2 82 3/29/2025
1.0.1 89 3/29/2025