Skip to content

Commit

Permalink
feat: add topic sequence number to topic message (#574)
Browse files Browse the repository at this point in the history
Adds the sequence number to the topic message response type.
  • Loading branch information
malandis authored Sep 19, 2024
1 parent 4ac887e commit 6fc4140
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/Momento.Sdk/Internal/ScsTopicClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -251,10 +251,10 @@ public async Task Subscribe()
{
case _TopicValue.KindOneofCase.Text:
_logger.LogTraceTopicMessageReceived("text", _cacheName, _topicName);
return new TopicMessage.Text(message.Item.Value, message.Item.PublisherId == "" ? null : message.Item.PublisherId);
return new TopicMessage.Text(message.Item.Value, checked((long)message.Item.TopicSequenceNumber), message.Item.PublisherId == "" ? null : message.Item.PublisherId);
case _TopicValue.KindOneofCase.Binary:
_logger.LogTraceTopicMessageReceived("binary", _cacheName, _topicName);
return new TopicMessage.Binary(message.Item.Value, message.Item.PublisherId == "" ? null : message.Item.PublisherId);
return new TopicMessage.Binary(message.Item.Value, checked((long)message.Item.TopicSequenceNumber), message.Item.PublisherId == "" ? null : message.Item.PublisherId);
case _TopicValue.KindOneofCase.None:
default:
_logger.LogTraceTopicMessageReceived("unknown", _cacheName, _topicName);
Expand Down
16 changes: 14 additions & 2 deletions src/Momento.Sdk/Responses/Topic/TopicMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@ public class Text : TopicMessage
/// <summary>
/// A topic message containing a text value.
/// </summary>
public Text(_TopicValue topicValue, string? tokenId = null)
public Text(_TopicValue topicValue, long topicSequenceNumber, string? tokenId = null)
{
Value = topicValue.Text;
TopicSequenceNumber = topicSequenceNumber;
TokenId = tokenId;
}

Expand All @@ -52,6 +53,11 @@ public Text(_TopicValue topicValue, string? tokenId = null)
/// </summary>
public string Value { get; }

/// <summary>
/// The sequence number of this message.
/// </summary>
public long TopicSequenceNumber { get; }

/// <summary>
/// The TokenId that was used to publish the message, or null if the token did not have an id.
/// This can be used to securely identify the sender of a message.
Expand All @@ -67,9 +73,10 @@ public class Binary : TopicMessage
/// <summary>
/// A topic message containing a binary value.
/// </summary>
public Binary(_TopicValue topicValue, string? tokenId = null)
public Binary(_TopicValue topicValue, long topicSequenceNumber, string? tokenId = null)
{
Value = topicValue.Binary.ToByteArray();
TopicSequenceNumber = topicSequenceNumber;
TokenId = tokenId;
}

Expand All @@ -78,6 +85,11 @@ public Binary(_TopicValue topicValue, string? tokenId = null)
/// </summary>
public byte[] Value { get; }

/// <summary>
/// The sequence number of this message.
/// </summary>
public long TopicSequenceNumber { get; }

/// <summary>
/// The TokenId that was used to publish the message, or null if the token did not have an id.
/// This can be used to securely identify the sender of a message.
Expand Down

0 comments on commit 6fc4140

Please sign in to comment.