Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Keep caller's config intact.
  • Loading branch information
mtmk committed Sep 19, 2024
commit ded2bca35c0a5bad79135f9850bc21ea1031e8de
8 changes: 8 additions & 0 deletions src/NATS.Client.JetStream/Models/StreamConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -245,4 +245,12 @@ internal StreamConfig()
[System.Text.Json.Serialization.JsonPropertyName("metadata")]
[System.Text.Json.Serialization.JsonIgnore(Condition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingDefault)]
public IDictionary<string, string>? Metadata { get; set; }

/// <summary>
/// Creates a shallow copy of the current StreamConfig instance using the MemberwiseClone method.
/// </summary>
/// <return>
/// A shallow copy of the current StreamConfig.
/// </return>
public StreamConfig ShallowCopy() => (StreamConfig)MemberwiseClone();
}
8 changes: 8 additions & 0 deletions src/NATS.Client.JetStream/Models/StreamSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,12 @@ public record StreamSource
/// </summary>
[System.Text.Json.Serialization.JsonIgnore]
public string? Domain { get; set; }

/// <summary>
/// Creates a shallow copy of the current StreamSource instance using the MemberwiseClone method.
/// </summary>
/// <return>
/// A shallow copy of the current StreamSource.
/// </return>
public StreamSource ShallowCopy() => (StreamSource)MemberwiseClone();
}
25 changes: 5 additions & 20 deletions src/NATS.Client.JetStream/NatsJSContext.Streams.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,13 @@ public async ValueTask<INatsJSStream> CreateStreamAsync(
{
ThrowIfInvalidStreamName(config.Name, nameof(config.Name));

// keep caller's config intact.
config = config.ShallowCopy();

// If we have a mirror and an external domain, convert to ext.APIPrefix.
if (config.Mirror != null && !string.IsNullOrEmpty(config.Mirror.Domain))
{
config.Mirror = new StreamSource
{
Name = config.Mirror.Name,
Domain = config.Mirror.Domain,
External = config.Mirror.External,
FilterSubject = config.Mirror.FilterSubject,
OptStartSeq = config.Mirror.OptStartSeq,
OptStartTime = config.Mirror.OptStartTime,
SubjectTransforms = config.Mirror.SubjectTransforms,
};
config.Mirror = config.Mirror.ShallowCopy();
ConvertDomain(config.Mirror);
}

Expand All @@ -45,16 +39,7 @@ public async ValueTask<INatsJSStream> CreateStreamAsync(
{
if (!string.IsNullOrEmpty(ss.Domain))
{
var remappedDomainSource = new StreamSource
{
Name = ss.Name,
Domain = ss.Domain,
External = ss.External,
FilterSubject = ss.FilterSubject,
OptStartSeq = ss.OptStartSeq,
OptStartTime = ss.OptStartTime,
SubjectTransforms = ss.SubjectTransforms,
};
var remappedDomainSource = ss.ShallowCopy();
ConvertDomain(remappedDomainSource);
sources.Add(remappedDomainSource);
}
Expand Down