-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add an topic event enumerable (#575)
Introduces an interface ITopicEvent which covers both normal messages (TopicMessage) and system events (TopicSystemEvent). We refactor the internals of the stream to be over ITopicEvents, so that we can filter to just TopicMessage (as is implemented currently) or pass through all events in an event enumerable. To enumerate over all events in the stream, call GetAllEventsAsyncEnumerable, or WithCancellationForAllEvents. This largely parallels the existing enumerator over messages only. See the integration tests for an example usage.
- Loading branch information
Showing
6 changed files
with
294 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
namespace Momento.Sdk.Responses; | ||
|
||
/// <summary> | ||
/// Represents an event that can be published to a topic. | ||
/// | ||
/// This includes not just topic mesasges, but also system events | ||
/// such as discontinuities and heartbeats. | ||
/// </summary> | ||
public interface ITopicEvent | ||
{ | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
namespace Momento.Sdk.Responses; | ||
|
||
/// <summary> | ||
/// Represents a system event that can be published to a topic. | ||
/// </summary> | ||
public abstract class TopicSystemEvent : ITopicEvent | ||
{ | ||
/// <summary> | ||
/// Represents a heartbeat event. | ||
/// </summary> | ||
public class Heartbeat : TopicSystemEvent | ||
{ | ||
/// <summary> | ||
/// Constructs a new heartbeat event. | ||
/// </summary> | ||
public Heartbeat() | ||
{ | ||
|
||
} | ||
|
||
/// <inheritdoc/> | ||
public override string ToString() => base.ToString() ?? "Heartbeat"; | ||
} | ||
|
||
/// <summary> | ||
/// Represents a discontinuity event. | ||
/// </summary> | ||
public class Discontinuity : TopicSystemEvent | ||
{ | ||
/// <summary> | ||
/// Constructs a new discontinuity event. | ||
/// </summary> | ||
/// <param name="lastKnownSequenceNumber">The last known sequence number before the discontinuity.</param> | ||
/// <param name="sequenceNumber">The sequence number of the discontinuity.</param> | ||
public Discontinuity(long lastKnownSequenceNumber, long sequenceNumber) | ||
{ | ||
LastKnownSequenceNumber = lastKnownSequenceNumber; | ||
SequenceNumber = sequenceNumber; | ||
} | ||
|
||
/// <summary> | ||
/// The last known sequence number before the discontinuity. | ||
/// </summary> | ||
public long LastKnownSequenceNumber { get; } | ||
/// <summary> | ||
/// The sequence number of the discontinuity. | ||
/// </summary> | ||
public long SequenceNumber { get; } | ||
|
||
/// <inheritdoc/> | ||
public override string ToString() | ||
{ | ||
return $"{base.ToString()}: LastKnownSequenceNumber: {LastKnownSequenceNumber} SequenceNumber: {SequenceNumber}"; | ||
} | ||
} | ||
} |
Oops, something went wrong.