Table of Contents

Class CdcBuilderPostgresExtensions

Namespace
Excalibur.Cdc.Postgres
Assembly
Excalibur.Cdc.Postgres.dll

Extension methods for configuring Postgres CDC provider on ICdcBuilder.

public static class CdcBuilderPostgresExtensions
Inheritance
CdcBuilderPostgresExtensions
Inherited Members

Remarks

These extensions provide fluent provider selection by adding provider-specific configuration to the core ICdcBuilder interface.

Methods

UsePostgres(ICdcBuilder, Action<IPostgresCdcBuilder>)

Configures the CDC processor to use Postgres.

[RequiresUnreferencedCode("Binding configuration to the options type reflects over its members, which trimming may remove. Configure the options in code instead of binding IConfiguration.")]
[RequiresDynamicCode("Binding configuration to the options type can require runtime code generation, which native AOT does not support. Configure the options in code instead of binding IConfiguration.")]
public static ICdcBuilder UsePostgres(this ICdcBuilder builder, Action<IPostgresCdcBuilder> configure)

Parameters

builder ICdcBuilder

The CDC builder.

configure Action<IPostgresCdcBuilder>

Action to configure Postgres-specific options including connection.

Returns

ICdcBuilder

The builder for fluent chaining.

Examples

// Connection string
services.AddCdcProcessor(cdc =>
{
    cdc.UsePostgres(pg =>
    {
        pg.ConnectionString(connectionString)
          .SchemaName("excalibur")
          .ReplicationSlotName("my_cdc_slot")
          .PublicationName("my_publication")
          .PollingInterval(TimeSpan.FromSeconds(1))
          .BatchSize(1000);
    })
    .TrackTable("public.orders", table =>
    {
        table.MapInsert<OrderCreatedEvent>()
             .MapUpdate<OrderUpdatedEvent>()
             .MapDelete<OrderDeletedEvent>();
    })
    .EnableBackgroundProcessing();
});

// Named connection string
services.AddCdcProcessor(cdc =>
{
    cdc.UsePostgres(pg =>
    {
        pg.ConnectionStringName("CdcDatabase")
          .ReplicationSlotName("my_slot")
          .PublicationName("my_pub");
    });
});

// Connection factory
services.AddCdcProcessor(cdc =>
{
    cdc.UsePostgres(pg =>
    {
        pg.ConnectionFactory(sp =>
        {
            var config = sp.GetRequiredService<IConfiguration>();
            var connStr = config.GetConnectionString("CdcDatabase")!;
            return () => new NpgsqlConnection(connStr);
        })
        .ReplicationSlotName("my_slot")
        .PublicationName("my_pub");
    });
});

// From appsettings.json
services.AddCdcProcessor(cdc =>
{
    cdc.UsePostgres(pg =>
    {
        pg.BindConfiguration("Cdc:Postgres")
          .ReplicationSlotName("my_slot")
          .PublicationName("my_pub");
    });
});

Remarks

This is the primary method for configuring Postgres as the CDC provider. It registers the PostgresCdcProcessor and PostgresCdcStateStore. Connection can be provided via the builder using ConnectionString(string), ConnectionStringName(string), ConnectionFactory(Func<IServiceProvider, Func<NpgsqlConnection>>), or BindConfiguration(string).

Postgres CDC uses logical replication with the pgoutput protocol. Server requirements:

  • wal_level = logical
  • A publication for the tables to capture
  • A replication slot (created automatically if AutoCreateSlot is true)

Exceptions

ArgumentNullException

Thrown when builder or configure is null.