forked from nats-io/nats.net
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial JetStream support (nats-io#86)
* Started JetStream project * Test projects tidy-up and minor fixes * Seperated JetStream tests * Naming fix for JS * Exclude JetStream from NuGet for now * Adding generated records (nats-io#88) * Adding records to jumpstart jetstream * by hand changes * Fixed stream model names * Set minimum stream config defaults * Fixed JSON types * better conversion (nats-io#89) * Increased logging on flaky test * generate JetStream models with NJsonSchema (nats-io#90) Signed-off-by: Caleb Lloyd <[email protected]> * Trace another flaky test --------- Signed-off-by: Caleb Lloyd <[email protected]> Co-authored-by: Scott Fauerbach <[email protected]> Co-authored-by: Caleb Lloyd <[email protected]>
- Loading branch information
1 parent
5341478
commit 0aaccd7
Showing
157 changed files
with
6,802 additions
and
86 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
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
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,64 @@ | ||
using System.ComponentModel.DataAnnotations; | ||
using NATS.Client.Core; | ||
using NATS.Client.JetStream.Models; | ||
|
||
namespace NATS.Client.JetStream; | ||
|
||
public class JSContext | ||
{ | ||
private readonly NatsConnection _nats; | ||
private readonly JSOptions _options; | ||
|
||
public JSContext(NatsConnection nats, JSOptions options) | ||
{ | ||
_nats = nats; | ||
_options = options; | ||
} | ||
|
||
public async ValueTask<JSStream> CreateStream(Action<StreamCreateRequest> request) | ||
{ | ||
var requestObj = new StreamCreateRequest(); | ||
request(requestObj); | ||
|
||
Validator.ValidateObject(requestObj, new ValidationContext(requestObj)); | ||
|
||
var response = | ||
await _nats.RequestAsync<StreamCreateRequest, StreamCreateResponse>( | ||
$"{_options.Prefix}.STREAM.CREATE.{requestObj.Name}", | ||
requestObj); | ||
|
||
// TODO: Better error handling | ||
if (response?.Data == null) | ||
throw new NatsJetStreamException("No response received"); | ||
|
||
return new JSStream(response.Value.Data); | ||
} | ||
} | ||
|
||
public class NatsJetStreamException : NatsException | ||
{ | ||
public NatsJetStreamException(string message) | ||
: base(message) | ||
{ | ||
} | ||
|
||
public NatsJetStreamException(string message, Exception exception) | ||
: base(message, exception) | ||
{ | ||
} | ||
} | ||
|
||
public record JSOptions | ||
{ | ||
public string Prefix { get; init; } = "$JS.API"; | ||
} | ||
|
||
public class JSStream | ||
{ | ||
public JSStream(StreamCreateResponse response) | ||
{ | ||
Response = response; | ||
} | ||
|
||
public StreamCreateResponse Response { get; } | ||
} |
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,9 @@ | ||
namespace NATS.Client.JetStream.Models; | ||
|
||
/// <summary> | ||
/// A response from the JetStream $JS.API.INFO API | ||
/// </summary> | ||
|
||
public record AccountInfoResponse : AccountStats | ||
{ | ||
} |
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,66 @@ | ||
namespace NATS.Client.JetStream.Models; | ||
|
||
public record AccountLimits | ||
{ | ||
/// <summary> | ||
/// The maximum amount of Memory storage Stream Messages may consume | ||
/// </summary> | ||
[System.Text.Json.Serialization.JsonPropertyName("max_memory")] | ||
[System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.Never)] | ||
[System.ComponentModel.DataAnnotations.Range(-1, int.MaxValue)] | ||
public int MaxMemory { get; set; } = default!; | ||
|
||
/// <summary> | ||
/// The maximum amount of File storage Stream Messages may consume | ||
/// </summary> | ||
[System.Text.Json.Serialization.JsonPropertyName("max_storage")] | ||
[System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.Never)] | ||
[System.ComponentModel.DataAnnotations.Range(-1, int.MaxValue)] | ||
public int MaxStorage { get; set; } = default!; | ||
|
||
/// <summary> | ||
/// The maximum number of Streams an account can create | ||
/// </summary> | ||
[System.Text.Json.Serialization.JsonPropertyName("max_streams")] | ||
[System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.Never)] | ||
[System.ComponentModel.DataAnnotations.Range(-1, int.MaxValue)] | ||
public int MaxStreams { get; set; } = default!; | ||
|
||
/// <summary> | ||
/// The maximum number of Consumer an account can create | ||
/// </summary> | ||
[System.Text.Json.Serialization.JsonPropertyName("max_consumers")] | ||
[System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.Never)] | ||
[System.ComponentModel.DataAnnotations.Range(-1, int.MaxValue)] | ||
public int MaxConsumers { get; set; } = default!; | ||
|
||
/// <summary> | ||
/// Indicates if Streams created in this account requires the max_bytes property set | ||
/// </summary> | ||
[System.Text.Json.Serialization.JsonPropertyName("max_bytes_required")] | ||
[System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] | ||
public bool MaxBytesRequired { get; set; } = false; | ||
|
||
/// <summary> | ||
/// The maximum number of outstanding ACKs any consumer may configure | ||
/// </summary> | ||
[System.Text.Json.Serialization.JsonPropertyName("max_ack_pending")] | ||
[System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] | ||
public int MaxAckPending { get; set; } = default!; | ||
|
||
/// <summary> | ||
/// The maximum size any single memory stream may be | ||
/// </summary> | ||
[System.Text.Json.Serialization.JsonPropertyName("memory_max_stream_bytes")] | ||
[System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] | ||
[System.ComponentModel.DataAnnotations.Range(-1, int.MaxValue)] | ||
public int MemoryMaxStreamBytes { get; set; } = -1; | ||
|
||
/// <summary> | ||
/// The maximum size any single storage based stream may be | ||
/// </summary> | ||
[System.Text.Json.Serialization.JsonPropertyName("storage_max_stream_bytes")] | ||
[System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] | ||
[System.ComponentModel.DataAnnotations.Range(-1, int.MaxValue)] | ||
public int StorageMaxStreamBytes { get; set; } = -1; | ||
} |
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,15 @@ | ||
namespace NATS.Client.JetStream.Models; | ||
|
||
/// <summary> | ||
/// A response from the JetStream $JS.API.ACCOUNT.PURGE API | ||
/// </summary> | ||
|
||
public record AccountPurgeResponse | ||
{ | ||
/// <summary> | ||
/// If the purge operation was succesfully started | ||
/// </summary> | ||
[System.Text.Json.Serialization.JsonPropertyName("initiated")] | ||
[System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] | ||
public bool Initiated { get; set; } = false; | ||
} |
Oops, something went wrong.