From 6fc41400b6ebf299e25dea1151e3ddf192bf75f7 Mon Sep 17 00:00:00 2001 From: Michael Landis Date: Thu, 19 Sep 2024 16:12:16 -0700 Subject: [PATCH] feat: add topic sequence number to topic message (#574) Adds the sequence number to the topic message response type. --- src/Momento.Sdk/Internal/ScsTopicClient.cs | 4 ++-- src/Momento.Sdk/Responses/Topic/TopicMessage.cs | 16 ++++++++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/Momento.Sdk/Internal/ScsTopicClient.cs b/src/Momento.Sdk/Internal/ScsTopicClient.cs index 9db9b2d7..41754939 100644 --- a/src/Momento.Sdk/Internal/ScsTopicClient.cs +++ b/src/Momento.Sdk/Internal/ScsTopicClient.cs @@ -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); diff --git a/src/Momento.Sdk/Responses/Topic/TopicMessage.cs b/src/Momento.Sdk/Responses/Topic/TopicMessage.cs index 7d81694c..1e8714ab 100644 --- a/src/Momento.Sdk/Responses/Topic/TopicMessage.cs +++ b/src/Momento.Sdk/Responses/Topic/TopicMessage.cs @@ -41,9 +41,10 @@ public class Text : TopicMessage /// /// A topic message containing a text value. /// - public Text(_TopicValue topicValue, string? tokenId = null) + public Text(_TopicValue topicValue, long topicSequenceNumber, string? tokenId = null) { Value = topicValue.Text; + TopicSequenceNumber = topicSequenceNumber; TokenId = tokenId; } @@ -52,6 +53,11 @@ public Text(_TopicValue topicValue, string? tokenId = null) /// public string Value { get; } + /// + /// The sequence number of this message. + /// + public long TopicSequenceNumber { get; } + /// /// 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. @@ -67,9 +73,10 @@ public class Binary : TopicMessage /// /// A topic message containing a binary value. /// - public Binary(_TopicValue topicValue, string? tokenId = null) + public Binary(_TopicValue topicValue, long topicSequenceNumber, string? tokenId = null) { Value = topicValue.Binary.ToByteArray(); + TopicSequenceNumber = topicSequenceNumber; TokenId = tokenId; } @@ -78,6 +85,11 @@ public Binary(_TopicValue topicValue, string? tokenId = null) /// public byte[] Value { get; } + /// + /// The sequence number of this message. + /// + public long TopicSequenceNumber { get; } + /// /// 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.