Skip to content

Commit 18fe3a3

Browse files
authored
Add Metadata to KV Bucket (#741)
* Add Metadata to KV Bucket * Add test * Fix test
1 parent 7736cf9 commit 18fe3a3

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

src/NATS.Client.KeyValueStore/NatsKVConfig.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ public record NatsKVConfig
7777
/// Sources defines the configuration for sources of a KeyValue store.
7878
/// </summary>
7979
public ICollection<StreamSource>? Sources { get; set; }
80+
81+
/// <summary>
82+
/// Additional metadata for the Bucket
83+
/// </summary>
84+
public IDictionary<string, string>? Metadata { get; set; }
8085
}
8186

8287
/// <summary>

src/NATS.Client.KeyValueStore/NatsKVContext.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ private static StreamConfig CreateStreamConfig(NatsKVConfig config)
246246
MirrorDirect = mirrorDirect,
247247
Sources = sources,
248248
Retention = StreamConfigRetention.Limits, // from ADR-8
249+
Metadata = config.Metadata,
249250
};
250251

251252
return streamConfig;

tests/NATS.Client.KeyValueStore.Tests/KeyValueStoreTest.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,13 @@ public async Task Status()
515515
var js = new NatsJSContext(nats);
516516
var kv = new NatsKVContext(js);
517517

518-
var store = await kv.CreateStoreAsync(new NatsKVConfig("kv1") { History = 10 }, cancellationToken: cancellationToken);
518+
var store = await kv.CreateStoreAsync(
519+
new NatsKVConfig("kv1")
520+
{
521+
History = 10,
522+
Metadata = new Dictionary<string, string> { { "meta1", "value1" } },
523+
},
524+
cancellationToken: cancellationToken);
519525

520526
Assert.Equal("kv1", store.Bucket);
521527

@@ -524,6 +530,16 @@ public async Task Status()
524530
Assert.Equal("kv1", status.Bucket);
525531
Assert.Equal("KV_kv1", status.Info.Config.Name);
526532
Assert.Equal(10, status.Info.Config.MaxMsgsPerSubject);
533+
534+
if (!nats.ServerInfo!.Version.StartsWith("2.9."))
535+
{
536+
_output.WriteLine("Check metadata");
537+
Assert.Equal("value1", status.Info.Config.Metadata?["meta1"]);
538+
}
539+
else
540+
{
541+
_output.WriteLine("Metadata is not supported in server versions < 2.10");
542+
}
527543
}
528544

529545
[SkipIfNatsServer(versionEarlierThan: "2.10")]

0 commit comments

Comments
 (0)