Class DynamoDbCdcPosition
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
IsValid
Gets a value indicating whether this position is valid for resuming.
public override bool IsValid { get; }
Property Value
ShardPositions
Gets the map of shard ID to sequence number.
public IReadOnlyDictionary<string, string> ShardPositions { get; }
Property Value
StreamArn
Gets the Stream ARN for validation.
public string StreamArn { get; }
Property Value
Timestamp
Gets the timestamp of the position (for diagnostics).
public override DateTimeOffset? Timestamp { get; }
Property Value
Methods
Beginning(string)
Creates a position representing the beginning of the stream (TRIM_HORIZON).
public static DynamoDbCdcPosition Beginning(string streamArn)
Parameters
streamArnstringThe 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
otherDynamoDbCdcPositionAn object to compare with this object.
Returns
Equals(ChangePosition?)
Indicates whether the current object is equal to another object of the same type.
public override bool Equals(ChangePosition? other)
Parameters
otherChangePositionAn object to compare with this object.
Returns
Equals(object?)
Determines whether the specified object is equal to the current object.
public override bool Equals(object? obj)
Parameters
objobjectThe object to compare with the current object.
Returns
FromBase64(string)
Deserializes a position from a base64 string.
public static DynamoDbCdcPosition FromBase64(string base64)
Parameters
base64stringThe 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
streamArnstringThe Stream ARN.
shardPositionsIReadOnlyDictionary<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
streamArnstringThe 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
base64stringThe base64-encoded string.
positionDynamoDbCdcPositionThe deserialized position if successful.
Returns
WithShardPosition(string, string)
Updates the position for a specific shard.
public DynamoDbCdcPosition WithShardPosition(string shardId, string sequenceNumber)
Parameters
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
shardIdstringThe shard ID to remove.
Returns
- DynamoDbCdcPosition
A new position without the specified shard.