Table of Contents

Class DynamoDbCdcPosition

Namespace
Excalibur.Cdc.DynamoDb
Assembly
Excalibur.Cdc.DynamoDb.dll

Represents a position in DynamoDB Streams using shard sequence numbers.

public sealed class DynamoDbCdcPosition : ChangePosition, IEquatable<ChangePosition>, IEquatable<DynamoDbCdcPosition>
Inheritance
DynamoDbCdcPosition
Implements
Inherited Members

Remarks

DynamoDB Streams are partitioned into shards. Each shard has its own sequence of records. To track position, we must maintain sequence numbers for ALL active shards.

Shards can split or merge over time. When resuming, unknown shards are started from TRIM_HORIZON to ensure no data is missed.

Properties

IsBeginning

Gets a value indicating whether this position represents the beginning of the stream.

public bool IsBeginning { get; }

Property Value

bool

IsValid

Gets a value indicating whether this position is valid for resuming.

public override bool IsValid { get; }

Property Value

bool

ShardPositions

Gets the map of shard ID to sequence number.

public IReadOnlyDictionary<string, string> ShardPositions { get; }

Property Value

IReadOnlyDictionary<string, string>

StreamArn

Gets the Stream ARN for validation.

public string StreamArn { get; }

Property Value

string

Timestamp

Gets the timestamp of the position (for diagnostics).

public override DateTimeOffset? Timestamp { get; }

Property Value

DateTimeOffset?

Methods

Beginning(string)

Creates a position representing the beginning of the stream (TRIM_HORIZON).

public static DynamoDbCdcPosition Beginning(string streamArn)

Parameters

streamArn string

The Stream ARN.

Returns

DynamoDbCdcPosition

A position that will read from the beginning.

Equals(DynamoDbCdcPosition?)

Indicates whether the current object is equal to another object of the same type.

public bool Equals(DynamoDbCdcPosition? other)

Parameters

other DynamoDbCdcPosition

An object to compare with this object.

Returns

bool

true if the current object is equal to the other parameter; otherwise, false.

Equals(ChangePosition?)

Indicates whether the current object is equal to another object of the same type.

public override bool Equals(ChangePosition? other)

Parameters

other ChangePosition

An object to compare with this object.

Returns

bool

true if the current object is equal to the other parameter; otherwise, false.

Equals(object?)

Determines whether the specified object is equal to the current object.

public override bool Equals(object? obj)

Parameters

obj object

The object to compare with the current object.

Returns

bool

true if the specified object is equal to the current object; otherwise, false.

FromBase64(string)

Deserializes a position from a base64 string.

public static DynamoDbCdcPosition FromBase64(string base64)

Parameters

base64 string

The base64-encoded string.

Returns

DynamoDbCdcPosition

The deserialized position.

Exceptions

FormatException

Thrown if the string format is invalid.

FromShardPositions(string, IReadOnlyDictionary<string, string>)

Creates a position from shard sequence numbers.

public static DynamoDbCdcPosition FromShardPositions(string streamArn, IReadOnlyDictionary<string, string> shardPositions)

Parameters

streamArn string

The Stream ARN.

shardPositions IReadOnlyDictionary<string, string>

Map of shard ID to sequence number.

Returns

DynamoDbCdcPosition

A position that will resume from the specified shard positions.

GetHashCode()

Serves as the default hash function.

public override int GetHashCode()

Returns

int

A hash code for the current object.

Now(string)

Creates a position representing the current time (LATEST).

public static DynamoDbCdcPosition Now(string streamArn)

Parameters

streamArn string

The Stream ARN.

Returns

DynamoDbCdcPosition

A position that will read from now.

ToBase64()

Serializes this position to a base64 string for storage.

public string ToBase64()

Returns

string

A base64-encoded string representation.

ToBytes()

Serializes this position to a byte array for storage.

public byte[] ToBytes()

Returns

byte[]

A UTF-8 encoded byte array representation.

ToString()

Returns a string that represents the current object.

public override string ToString()

Returns

string

A string that represents the current object.

ToToken()

Converts this position to a string token suitable for storage and resumption.

public override string ToToken()

Returns

string

A string representation of this position that can be persisted and later used to resume CDC processing from this point.

Remarks

The token format is provider-specific but must be round-trippable through the corresponding Parse method on the derived type.

TryFromBase64(string?, out DynamoDbCdcPosition?)

Attempts to deserialize a position from a base64 string.

public static bool TryFromBase64(string? base64, out DynamoDbCdcPosition? position)

Parameters

base64 string

The base64-encoded string.

position DynamoDbCdcPosition

The deserialized position if successful.

Returns

bool

true if parsing succeeded; otherwise, false.

WithShardPosition(string, string)

Updates the position for a specific shard.

public DynamoDbCdcPosition WithShardPosition(string shardId, string sequenceNumber)

Parameters

shardId string

The shard ID.

sequenceNumber string

The new sequence number.

Returns

DynamoDbCdcPosition

A new position with the updated shard position.

WithoutShard(string)

Removes a shard from the position (when shard is exhausted).

public DynamoDbCdcPosition WithoutShard(string shardId)

Parameters

shardId string

The shard ID to remove.

Returns

DynamoDbCdcPosition

A new position without the specified shard.