diff --git a/src/NATS.Client.JetStream/Models/StreamConfig.cs b/src/NATS.Client.JetStream/Models/StreamConfig.cs index 66a06a752..1ad84c1a3 100644 --- a/src/NATS.Client.JetStream/Models/StreamConfig.cs +++ b/src/NATS.Client.JetStream/Models/StreamConfig.cs @@ -271,6 +271,13 @@ public StreamConfig() [System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)] public bool AllowMsgCounter { get; set; } + /// + /// AllowMsgSchedules enables the scheduling of messages. + /// + [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; } + /// /// AllowAtomicPublish allows atomic batch publishing into the stream. /// diff --git a/tests/NATS.Client.JetStream.Tests/ManageStreamTest.cs b/tests/NATS.Client.JetStream.Tests/ManageStreamTest.cs index 56e287def..4ed299555 100644 --- a/tests/NATS.Client.JetStream.Tests/ManageStreamTest.cs +++ b/tests/NATS.Client.JetStream.Tests/ManageStreamTest.cs @@ -221,6 +221,44 @@ public async Task Create_or_update_stream_should_be_throwing_update_operation_er await Assert.ThrowsAsync(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(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() {