Chatter.SqlChangeFeed
0.12.0
See the version list below for details.
dotnet add package Chatter.SqlChangeFeed --version 0.12.0
NuGet\Install-Package Chatter.SqlChangeFeed -Version 0.12.0
<PackageReference Include="Chatter.SqlChangeFeed" Version="0.12.0" />
<PackageVersion Include="Chatter.SqlChangeFeed" Version="0.12.0" />
<PackageReference Include="Chatter.SqlChangeFeed" />
paket add Chatter.SqlChangeFeed --version 0.12.0
#r "nuget: Chatter.SqlChangeFeed, 0.12.0"
#:package Chatter.SqlChangeFeed@0.12.0
#addin nuget:?package=Chatter.SqlChangeFeed&version=0.12.0
#tool nuget:?package=Chatter.SqlChangeFeed&version=0.12.0
<a name="chatter-sqlchangefeed"></a> Chatter.SqlChangeFeed
Emit strongly-typed notifications whenever rows in a watched SQL Server table are inserted, updated, or deleted.
Overview
Chatter.SqlChangeFeed turns row-level changes in a SQL Server table into a change feed of in-process messages, without polling. It provisions a SQL trigger on the watched table that publishes changes onto a SQL Server Service Broker queue; Chatter's Service Broker receiver picks those messages up and dispatches them to your handlers.
This package was originally named Table Watcher (Chatter.TableWatcher); it is now Chatter.SqlChangeFeed. The "watcher" terminology still appears throughout the domain language.
By default, each change is delivered to your code as one of three strongly-typed events:
RowInsertedEvent<TRowChangeData>RowUpdatedEvent<TRowChangeData>RowDeletedEvent<TRowChangeData>
Alternatively you can opt out of that fan-out and handle the raw ProcessChangeFeedCommand<TRowChangeData> (a batch of ChangeFeedItem<TRowChangeData>) yourself.
Installation
dotnet add package Chatter.SqlChangeFeed
This package builds on Chatter.CQRS and Chatter.MessageBrokers.SqlServiceBroker, which are pulled in transitively.
Getting Started
1. Register the change feed
AddSqlChangeFeed<TRowChangedData> is the primary entry point. It is an extension on IChatterBuilder, so chain it off your existing Chatter registration. TRowChangedData is a type implementing IMessage whose properties map to the columns of the watched row.
using Chatter.CQRS.DependencyInjection;
using Chatter.SqlChangeFeed.DependencyInjection;
public void ConfigureServices(IServiceCollection services)
{
services.AddChatterCqrs(typeof(Startup).Assembly)
.AddSqlChangeFeed<MyRow>(
connectionString: Configuration.GetConnectionString("Chatter"),
databaseName: "MyDatabase", // optional; falls back to the connection string's Initial Catalog
tableName: "MyTable",
optionsBuilder: opts => opts
.WithSchema("dbo")
.WithTypesOfChangesToWatch(ChangeTypes.Insert | ChangeTypes.Update | ChangeTypes.Delete));
}
// The IMessage that maps to a row in MyTable
public class MyRow : Chatter.CQRS.IMessage
{
public int Id { get; set; }
public string Name { get; set; }
}
A non-generic overload, AddSqlChangeFeed(Type rowChangedDataType, ...), is available when the row type is only known at runtime.
2. Provision the SQL dependencies
The trigger, stored procedures, and Service Broker objects are not created at registration time. Call UseChangeFeedSqlMigrations<TRowChangedData> during startup to deploy them:
public void Configure(IApplicationBuilder app)
{
app.UseChangeFeedSqlMigrations<MyRow>();
}
(Overloads also exist on IServiceProvider for non-web hosts.)
3. Handle the change notifications
With the default behavior (ProcessChangeFeedCommandViaChatter = true), implement IMessageHandler<T> for whichever events you care about:
using Chatter.CQRS;
using Chatter.CQRS.Context;
using Chatter.SqlChangeFeed;
public class MyRowChangeHandler :
IMessageHandler<RowInsertedEvent<MyRow>>,
IMessageHandler<RowUpdatedEvent<MyRow>>,
IMessageHandler<RowDeletedEvent<MyRow>>
{
public Task Handle(RowInsertedEvent<MyRow> message, IMessageHandlerContext context)
{
var inserted = message.Inserted;
// ...
return Task.CompletedTask;
}
public Task Handle(RowUpdatedEvent<MyRow> message, IMessageHandlerContext context)
{
var before = message.OldValue;
var after = message.NewValue;
// ...
return Task.CompletedTask;
}
public Task Handle(RowDeletedEvent<MyRow> message, IMessageHandlerContext context)
{
var deleted = message.Deleted;
// ...
return Task.CompletedTask;
}
}
Handling the raw change feed instead
If you call ProcessTableChangesManually() on the options builder, Chatter does not fan out to the row events. Instead, handle the batch command directly:
public class MyChangeFeedHandler : IMessageHandler<ProcessChangeFeedCommand<MyRow>>
{
public Task Handle(ProcessChangeFeedCommand<MyRow> message, IMessageHandlerContext context)
{
foreach (ChangeFeedItem<MyRow> change in message.Changes)
{
// change.Inserted and/or change.Deleted are populated depending on the operation
}
return Task.CompletedTask;
}
}
Configuration
AddSqlChangeFeed takes the connection string, database, and table directly. Everything else is configured through the optional Action<SqlChangeFeedOptionsBuilder>, which produces a SqlChangeFeedOptions.
Core arguments / SqlChangeFeedOptions
| Property | Meaning |
|---|---|
ConnectionString |
Connection to the SQL Server hosting the watched table. |
DatabaseName |
Database containing the table. Optional; defaults to the connection string's Initial Catalog. |
TableName |
The table to watch. |
SchemaName |
Schema of the table. Defaults to dbo. |
ChangeFeedTriggerTypes |
Which operations to watch (ChangeTypes.Insert \| Update \| Delete). Defaults to all three. |
ChangeFeedQueueName |
Name of the backing Service Broker queue. Defaults to a Chatter-generated name based on the row type. |
ChangeFeedDeadLetterServiceName |
Service Broker service to which dead-lettered messages are routed. Defaults to a generated name. |
ProcessChangeFeedCommandViaChatter |
When true (default), Chatter fans changes out as RowInserted/RowUpdated/RowDeleted events. When false, you handle ProcessChangeFeedCommand<T> directly. |
SqlChangeFeedOptionsBuilder methods
| Method | Effect |
|---|---|
WithNameOfDatabaseToWatch(string) |
Sets the database name. |
WithSchema(string) |
Sets the table schema (default dbo). |
WithTypesOfChangesToWatch(ChangeTypes) |
Restricts which operations raise notifications. |
EmitRowChangeEvents() |
Fan out to the row-change events (default). |
ProcessTableChangesManually() |
Deliver the raw ProcessChangeFeedCommand<T> instead. |
WithChangeFeedQueueName(string) |
Overrides the Service Broker queue name. |
WithChangeFeedDeadLetterServiceName(string) |
Overrides the dead-letter service name. |
WithErrorQueueName(string) |
Sets the error queue path for the receiver. |
WithTransactionMode(TransactionMode) |
Atomicity of the receiver (default FullAtomicityViaInfrastructure). |
WithMaxReceiveAttempts(int) |
Max receive attempts before recovery action (default 10). |
WithReceiverTimeoutInMilliseconds(int) |
Receiver wait timeout (default -1, unlimited). |
WithConversationLifetimeInSeconds(int) |
Service Broker dialog lifetime. |
EnableConversationEncryption() / DisableConversationEncryption() |
Toggle Service Broker dialog encryption (default disabled). |
WithCompressedMessageBody() / WithUncompressedMessageBody() |
Toggle message-body compression (default compressed). |
WithMessageBodyType(string) / WithApplicationJsonUtf16CharsetMessageBodyType() |
Set the message body content type (default application/json; charset=utf-16). |
How It Works
When you call UseChangeFeedSqlMigrations<T>, SqlDependencyManager<T> runs a set of generated SQL scripts (via ISqlDependencyManager) against the target database. For each watched row type it provisions:
- Service Broker objects — enables Service Broker on the database if needed and creates the message type, contract, a conversation queue + service, and a dead-letter queue + service (
InstallAndConfigureSqlServiceBroker). Names are derived fromChatterServiceBrokerConstantsand the row type name. - A trigger on the watched table (
CreateChangeFeedTrigger) — anAFTER INSERT/UPDATE/DELETEtrigger (scoped toChangeFeedTriggerTypes) that serializes the affectedinserted/deletedrows andSENDs them onto a Service Broker conversation as a compressed message. - Install / uninstall stored procedures (
CreateInstallationProcedure,CreateUninstallProcedure) — the install procedure wires everything together; the uninstall procedure tears the trigger, queues, services, and procedures back down.
At runtime the queue is drained by Chatter's SQL Service Broker receiver. A ChangeFeedReceiver<T> (a BrokeredMessageReceiver) deserializes each batch into a ProcessChangeFeedCommand<T> of ChangeFeedItem<T>. Each item carries an Inserted and/or Deleted snapshot, which the receiver uses to decide whether the change was an insert (inserted only), delete (deleted only), or update (both), dispatching the matching event — unless you chose ProcessTableChangesManually().
Provisioning is manual, not automatic. Registration (AddSqlChangeFeed) only wires up DI; the SQL objects are created only when UseChangeFeedSqlMigrations is invoked at startup. The scripts are idempotent (IF NOT EXISTS guards), so running them on each startup is safe.
Header Propagation (including Trace Context)
Change-feed messages carry no headers at all. They originate from the SQL trigger this package provisions, which SENDs a DEFAULT-message-type message directly onto the Service Broker queue — there is no producer-side Chatter dispatch to stamp a Message Context, so there is nothing to propagate and nothing for a receiver to extract.
The consequence for the opt-in tracing added in ADR-0010: W3C trace context (traceparent / tracestate) does not flow into a change-feed message, so handling a row change starts a new trace rather than continuing the trace of whatever wrote the row.
This is inherent to the change feed's trigger origin and is a pre-existing property that affects all headers alike — it is not something tracing introduced. It compounds with the receive side: because the trigger sends the DEFAULT message type, the queue is drained through the SQL Service Broker receiver's DEFAULT path, which itself builds a fresh header dictionary (see Header Propagation in the SqlServiceBroker README). Both ends are pinned by conformance tests, so a change that accidentally alters either is visible.
Domain Language
See ../CONTEXT.md for the change-feed / Table Watcher glossary and relationships.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. 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 is compatible. 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. |
-
net10.0
- Chatter.MessageBrokers.SqlServiceBroker (>= 0.14.0)
- Microsoft.AspNetCore.Http.Abstractions (>= 2.2.0)
- Microsoft.Data.SqlClient (>= 7.0.1)
-
net8.0
- Chatter.MessageBrokers.SqlServiceBroker (>= 0.14.0)
- Microsoft.AspNetCore.Http.Abstractions (>= 2.2.0)
- Microsoft.Data.SqlClient (>= 7.0.1)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Chatter.SqlChangeFeed:
| Package | Downloads |
|---|---|
|
Chatter.IntegrationEventRelay.ServiceBroker
SQL Service Broker change source for Chatter.IntegrationEventRelay: captures row changes with triggers and Chatter.SqlChangeFeed |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 0.16.1 | 147 | 10/17/2026 |
| 0.16.0 | 414 | 9/29/2026 |
| 0.15.1 | 117 | 9/24/2026 |
| 0.15.0 | 115 | 9/24/2026 |
| 0.14.2 | 125 | 9/12/2026 |
| 0.14.1 | 139 | 9/2/2026 |
| 0.14.0 | 120 | 9/2/2026 |
| 0.13.0 | 125 | 9/2/2026 |
| 0.12.0 | 137 | 9/1/2026 |
| 0.11.0 | 186 | 6/16/2026 |
| 0.9.1 | 157 | 6/16/2026 |
| 0.9.0 | 158 | 5/30/2026 |
| 0.8.4 | 535 | 3/3/2023 |
| 0.8.3 | 1,179 | 4/2/2022 |
| 0.8.2 | 626 | 4/1/2022 |
| 0.8.1 | 666 | 4/1/2022 |
| 0.8.0 | 653 | 4/1/2022 |
| 0.7.0 | 948 | 3/4/2022 |