Skip to main content

CDC for Microsoft SQL Server

Microsoft SQL Server CDC integrations capture row-level changes from SQL Server tables in real time using Debezium-based Change Data Capture. Use them for data synchronization, audit logging, and event-driven workflows that must react to database inserts, updates, and deletes without polling. This page covers creating the integration, configuring the service and listener, and adding event handlers for insert, update, delete and read events.

Prerequisites

CDC must be enabled on the SQL Server database and on each table you want to track before creating this integration. See the CDC connector setup guide for step-by-step instructions.

Create a CDC service for Microsoft SQL Server​

  1. Click + Add Artifact in the canvas or click + next to Entry Points in the sidebar.

  2. In the Artifacts panel, select CDC for Microsoft SQL Server under Event Integration.

  3. In the creation form, select Create new to configure a new listener.

    Microsoft SQL Server CDC creation form: connection fieldsMicrosoft SQL Server CDC creation form: connection fields

    Under Listener Configurations, fill in the following fields:

    FieldDescriptionDefault
    Listener NameIdentifier for the listener created with this service.mssqlCdcListener
    HostHostname of the Microsoft SQL Server.localhost
    PortPort number of the Microsoft SQL Server.1433
    UsernameUsername for the SQL Server connection.Required
    PasswordPassword for the SQL Server connection.Required
    DatabasesList of databases to capture changes from. Click + Add Item to add each database name.Required
    SchemasRegular expressions matching schema names to capture changes from. Click + Add Item to add each pattern.—

    Expand Advanced Configurations for additional settings:

    FieldDescriptionDefault
    Database InstanceMicrosoft SQL Server named instance (if applicable).—
    Secure SocketSSL/TLS configuration for a secure connection.—
    OptionsAdditional options for the CDC engine as a record expression. Common keys include snapshotMode (for example, cdc:NO_DATA to skip the initial snapshot) and skippedOperations (for example, [cdc:TRUNCATE, cdc:UPDATE, cdc:DELETE] to skip truncate, update, and delete events; note that snapshot reads still trigger onRead unless snapshotMode is also set to cdc:NO_DATA).—

    Under Table, enter the fully qualified table name to capture events from in the format <database>.<schema>.<table> (for example, mydb.dbo.customers).

  4. Click Create.

  5. WSO2 Integrator creates the empty service and opens it in the Service Designer. The canvas shows the attached listener pill and the table name pill. The service has no handlers yet.

    Service Designer showing the Microsoft SQL Server CDC service canvasService Designer showing the Microsoft SQL Server CDC service canvas

Service configuration​

In the Service Designer, click the Configure icon in the header to open the CDC for Microsoft SQL Server Configuration panel. Select CDC for Microsoft SQL Server in the left panel.

Microsoft SQL Server CDC Configuration panel: service config and listener connectionMicrosoft SQL Server CDC Configuration panel: service config and listener connection
FieldDescription
Service ConfigAdvanced CDC configuration as a record expression. The tables field sets the table(s) whose change events are routed to this service, using the fully qualified format <database>.<schema>.<table>. Provide a single table as a string (for example, "mydb.dbo.customers"), or multiple tables as a string array (for example, ["mydb.dbo.customers", "mydb.dbo.orders"]).

Listener configuration​

In the CDC for Microsoft SQL Server Configuration panel, select mssqlCdcListener under Attached Listeners to configure the listener.

A CDC service can be attached to only one listener.

Listener configuration: Database, Engine Name, Internal Schema Storage, Offset Storage, Liveness Interval, OptionsListener configuration: Database, Engine Name, Internal Schema Storage, Offset Storage, Liveness Interval, Options
FieldDescriptionDefault
NameIdentifier for the listener.mssqlCdcListener
DatabaseDatabase connection configuration as a record expression with hostname, port, username, password, and databaseNames fields.Required
Engine NameDebezium engine instance name.ballerina-cdc-connector
Internal Schema StorageSchema history storage configuration.{fileName: "tmp/dbhistory.dat"}
Offset StorageOffset storage configuration for tracking CDC progress.{fileName: "tmp/debezium-offsets.dat"}
Liveness IntervalInterval in seconds for checking CDC listener liveness.60.0
OptionsAdditional connector options as a record expression.{}

Click Save Changes to apply updates.

Polling interval

The Debezium SQL Server connector reads changes from CDC change tables on a polling cycle. To tune the cycle, set Debezium properties such as poll.interval.ms in the Options field (for example, { "poll.interval.ms": "1000" }).

Event handlers​

Adding an event handler​

In the Service Designer, click + Add Handler. The Select Handler to Add panel lists onRead, onCreate, onUpdate, onDelete, and onError.

onRead, onCreate, onUpdate, and onDelete each open a Message Handler Configuration panel for the row payload. onError is added directly without additional configuration.

Message Handler Configuration panel with Define Database Entry and Advanced Parameters TableName checkboxMessage Handler Configuration panel with Define Database Entry and Advanced Parameters TableName checkbox

The configuration panel exposes the following fields:

FieldDescription
+ Define Database EntryDefines the record type representing one row of the tracked table. The handler receives this record at runtime with values from the change event.
Advanced Parameters > TableNameAdds a string parameter to the handler that receives the name of the table the change event came from. It does not filter events.

Click Save to add the handler. Added handlers appear in the Event Handlers list on the Service Designer, where you can edit or remove each one.

Service Designer for a CDC for Microsoft SQL Server service showing the Event Handlers list with onCreate, onUpdate, onDelete, and onError entries.Service Designer for a CDC for Microsoft SQL Server service showing the Event Handlers list with onCreate, onUpdate, onDelete, and onError entries.

Handler types​

HandlerTriggered whenUse when
onReadA row is read during the initial snapshot of the tableBootstrapping downstream systems with existing data
onCreateA row is inserted into the tracked tableSyncing new records to downstream systems
onUpdateA row is updated in the tracked tablePropagating field changes
onDeleteA row is deleted from the tracked tableRemoving records from downstream systems
onErrorA CDC processing error occursLogging failures and sending alerts

What's next​

  • CDC Connector Overview — full CDC connector reference covering listeners, configuration, and supported databases
  • Data Mapper — transform change events into the shape your downstream systems expect
  • CDC for PostgreSQL — capture changes from PostgreSQL tables