diff --git a/src/NATS.Client.JetStream/INatsJSStream.cs b/src/NATS.Client.JetStream/INatsJSStream.cs index 9fd3734df..7b041304d 100644 --- a/src/NATS.Client.JetStream/INatsJSStream.cs +++ b/src/NATS.Client.JetStream/INatsJSStream.cs @@ -112,5 +112,15 @@ ValueTask UpdateAsync( ValueTask> GetDirectAsync(StreamMsgGetRequest request, INatsDeserialize? serializer = default, CancellationToken cancellationToken = default); + /// + /// Request a direct batch message + /// + /// Batch message request. + /// Serializer to use for the message type. + /// A used to cancel the API call. + /// + /// + IAsyncEnumerable> GetBatchDirectAsync(StreamMsgBatchGetRequest request, INatsDeserialize? serializer = default, CancellationToken cancellationToken = default); + ValueTask GetAsync(StreamMsgGetRequest request, CancellationToken cancellationToken = default); } diff --git a/src/NATS.Client.JetStream/Models/StreamMsgBatchGetRequest.cs b/src/NATS.Client.JetStream/Models/StreamMsgBatchGetRequest.cs new file mode 100644 index 000000000..14d863ae3 --- /dev/null +++ b/src/NATS.Client.JetStream/Models/StreamMsgBatchGetRequest.cs @@ -0,0 +1,80 @@ +using System.ComponentModel.DataAnnotations; +using System.Text.Json.Serialization; + +namespace NATS.Client.JetStream.Models; + +/// +/// A request to the JetStream $JS.API.STREAM.MSG.GET API +/// +public record StreamMsgBatchGetRequest +{ + /// + /// The maximum amount of messages to be returned for this request + /// + [JsonPropertyName("batch")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + [Range(-1, int.MaxValue)] + public int Batch { get; set; } + + /// + /// The maximum amount of returned bytes for this request. + /// + [JsonPropertyName("max_bytes")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + [Range(-1, int.MaxValue)] + public int MaxBytes { get; set; } + + /// + /// The minimum sequence for returned message + /// + [JsonPropertyName("seq")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + [Range(ulong.MinValue, ulong.MaxValue)] + public ulong MinSequence { get; set; } + + /// + /// The minimum start time for returned message + /// + [JsonPropertyName("start_time")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + [Range(ulong.MinValue, ulong.MaxValue)] + public DateTime StartTime { get; set; } + + /// + /// The subject used filter messages that should be returned + /// + [JsonPropertyName("next_by_subj")] + [JsonIgnore(Condition = JsonIgnoreCondition.Never)] + [Required] +#if NET6_0 + public string Subject { get; set; } = default!; +#else +#pragma warning disable SA1206 + public required string Subject { get; set; } + +#pragma warning restore SA1206 +#endif + + /// + /// Return last messages mathing the subjects + /// + [JsonPropertyName("multi_last")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + [Range(ulong.MinValue, ulong.MaxValue)] + public string[] LastBySubjects { get; set; } = []; + + /// + /// Return message after sequence + /// + [JsonPropertyName("up_to_seq")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + [Range(ulong.MinValue, ulong.MaxValue)] + public ulong UpToSequence { get; set; } + + /// + /// Return message after time + /// + [JsonPropertyName("up_to_time")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)] + public DateTimeOffset UpToTime { get; set; } +}