TdsCdc. Persistence behaviour
(tds_cdc v0.1.0)
Copy Markdown
Behaviour for LSN position persistence.
By default, TdsCdc.Persistence.File writes LSN positions to disk so they
survive application restarts. You can implement this behaviour to store
positions in a database, Redis, or any other backend.
Example: custom persistence module
defmodule MyApp.DbPersistence do
@behaviour TdsCdc.Persistence
@impl true
def save_positions(_name, positions) do
# Write positions to your database
:ok
end
@impl true
def load_positions(_name) do
# Read positions from your database
{:ok, %{}} # or {:error, reason}
end
endThen pass it to the client:
TdsCdc.start_link(
conn: [...],
capture_instances: ["dbo_users"],
persistence: {MyApp.DbPersistence, []}
)
Summary
Types
Callbacks
Loads the saved LSN positions.
nameis the client's registered name (atom).
Returns {:ok, positions} where positions is a map of capture instance
name to LSN binary, or {:error, reason} if no positions are found.
Saves the current LSN positions for all capture instances.
nameis the client's registered name (atom).positionsis a map of capture instance name to LSN binary.