Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/NATS.Client.JetStream/Models/StreamConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,13 @@ public StreamConfig()
[System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)]
public bool AllowMsgCounter { get; set; }

/// <summary>
/// AllowMsgSchedules enables the scheduling of messages.
/// </summary>
[System.Text.Json.Serialization.JsonPropertyName("allow_msg_schedules")]
[System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)]
public bool AllowMsgSchedules { get; set; }

/// <summary>
/// AllowAtomicPublish allows atomic batch publishing into the stream.
/// </summary>
Expand Down
38 changes: 38 additions & 0 deletions tests/NATS.Client.JetStream.Tests/ManageStreamTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,44 @@ public async Task Create_or_update_stream_should_be_throwing_update_operation_er
await Assert.ThrowsAsync<NatsJSApiException>(async () => await js.CreateOrUpdateStreamAsync(streamConfigForUpdated, cts.Token));
}

[SkipIfNatsServer(versionEarlierThan: "2.12")]
public async Task AllowMsgSchedules_property_should_be_set_on_stream()
{
await using var nats = new NatsConnection(new NatsOpts { Url = _server.Url });
var prefix = _server.GetNextId();
await nats.ConnectRetryAsync();

var js = new NatsJSContext(nats);

var cts = new CancellationTokenSource(TimeSpan.FromSeconds(10));

// Create a stream with AllowMsgSchedules enabled
var streamConfig = new StreamConfig($"{prefix}schedules", [$"{prefix}schedules.*"])
{
AllowMsgSchedules = true,
};

var stream = await js.CreateStreamAsync(streamConfig, cts.Token);

// Verify the property is set on the created stream
Assert.True(stream.Info.Config.AllowMsgSchedules);

// Get the stream and verify the property is persisted
var retrievedStream = await js.GetStreamAsync($"{prefix}schedules", cancellationToken: cts.Token);
Assert.True(retrievedStream.Info.Config.AllowMsgSchedules);

// Update stream with AllowMsgSchedules disabled should error
var updatedConfig = streamConfig with { AllowMsgSchedules = false };
var exception = await Assert.ThrowsAsync<NatsJSApiException>(async () => await js.UpdateStreamAsync(updatedConfig, cts.Token));
Assert.Equal(500, exception.Error.Code);
Assert.Equal(10052, exception.Error.ErrCode);
Assert.Equal("message schedules can not be disabled", exception.Error.Description);

// Get the stream and verify the update has failed
var reRetrievedStream = await js.GetStreamAsync($"{prefix}schedules", cancellationToken: cts.Token);
Assert.True(reRetrievedStream.Info.Config.AllowMsgSchedules);
}

[SkipIfNatsServer(versionEarlierThan: "2.12")]
public async Task AllowAtomicPublish_property_should_be_set_on_stream()
{
Expand Down
Loading