Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing properties to ParameterShovelValue #291

Merged
merged 2 commits into from
Dec 24, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -895,27 +895,79 @@ namespace EasyNetQ.Management.Client.Model
}
public class ParameterShovelValue : System.IEquatable<EasyNetQ.Management.Client.Model.ParameterShovelValue>
{
public ParameterShovelValue(string SrcProtocol, string SrcUri, string? SrcExchange, string? SrcExchangeKey, string? SrcQueue, string SrcDeleteAfter, string DestProtocol, string DestUri, string? DestExchange, string? DestQueue, string AckMode, bool AddForwardHeaders) { }
public ParameterShovelValue(
string SrcUri,
string DestUri,
string? SrcProtocol = null,
string? SrcQueue = null,
System.Collections.Generic.IReadOnlyDictionary<string, object?>? SrcQueueArguments = null,
string? SrcExchange = null,
string? SrcExchangeKey = null,
string? SrcDeleteAfter = null,
int? SrcPrefetchCount = default,
string? DestProtocol = null,
string? DestQueue = null,
System.Collections.Generic.IReadOnlyDictionary<string, object?>? DestQueueArguments = null,
string? DestExchange = null,
string? DestExchangeKey = null,
bool? DestAddForwardHeaders = default,
bool? DestAddTimestampHeader = default,
string? AckMode = null,
int? ReconnectDelay = default) { }
[System.Text.Json.Serialization.JsonIgnore]
public System.Collections.Generic.IReadOnlyDictionary<string, object?>? ExtensionData { get; set; }
[System.Text.Json.Serialization.JsonExtensionData]
public System.Collections.Generic.IDictionary<string, System.Text.Json.JsonElement>? JsonExtensionData { get; set; }
[System.Text.Json.Serialization.JsonIgnore(Condition=System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull)]
[System.Text.Json.Serialization.JsonPropertyName("ack-mode")]
public string AckMode { get; init; }
[System.Text.Json.Serialization.JsonPropertyName("add-forward-headers")]
public bool AddForwardHeaders { get; init; }
public string? AckMode { get; init; }
[System.Text.Json.Serialization.JsonIgnore(Condition=System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull)]
[System.Text.Json.Serialization.JsonPropertyName("dest-add-forward-headers")]
public bool? DestAddForwardHeaders { get; init; }
[System.Text.Json.Serialization.JsonIgnore(Condition=System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull)]
[System.Text.Json.Serialization.JsonPropertyName("dest-add-timestamp-header")]
public bool? DestAddTimestampHeader { get; init; }
[System.Text.Json.Serialization.JsonIgnore(Condition=System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull)]
[System.Text.Json.Serialization.JsonPropertyName("dest-exchange-key")]
public string? DestExchangeKey { get; init; }
[System.Text.Json.Serialization.JsonIgnore(Condition=System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull)]
[System.Text.Json.Serialization.JsonPropertyName("dest-exchange")]
public string? DestExchange { get; init; }
[System.Text.Json.Serialization.JsonIgnore(Condition=System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull)]
[System.Text.Json.Serialization.JsonPropertyName("dest-protocol")]
public string DestProtocol { get; init; }
public string? DestProtocol { get; init; }
[System.Text.Json.Serialization.JsonConverter(typeof(EasyNetQ.Management.Client.Serialization.StringObjectReadOnlyDictionaryConverter?))]
[System.Text.Json.Serialization.JsonIgnore(Condition=System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull)]
[System.Text.Json.Serialization.JsonPropertyName("dest-queue-args")]
public System.Collections.Generic.IReadOnlyDictionary<string, object?>? DestQueueArguments { get; init; }
[System.Text.Json.Serialization.JsonIgnore(Condition=System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull)]
[System.Text.Json.Serialization.JsonPropertyName("dest-queue")]
public string? DestQueue { get; init; }
[System.Text.Json.Serialization.JsonPropertyName("dest-uri")]
public string DestUri { get; init; }
[System.Text.Json.Serialization.JsonIgnore(Condition=System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull)]
[System.Text.Json.Serialization.JsonPropertyName("reconnect-delay")]
public int? ReconnectDelay { get; init; }
[System.Text.Json.Serialization.JsonIgnore(Condition=System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull)]
[System.Text.Json.Serialization.JsonPropertyName("src-delete-after")]
public string SrcDeleteAfter { get; init; }
public string? SrcDeleteAfter { get; init; }
[System.Text.Json.Serialization.JsonIgnore(Condition=System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull)]
[System.Text.Json.Serialization.JsonPropertyName("src-exchange-key")]
public string? SrcExchangeKey { get; init; }
[System.Text.Json.Serialization.JsonIgnore(Condition=System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull)]
[System.Text.Json.Serialization.JsonPropertyName("src-exchange")]
public string? SrcExchange { get; init; }
[System.Text.Json.Serialization.JsonIgnore(Condition=System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull)]
[System.Text.Json.Serialization.JsonPropertyName("src-prefetch-count")]
public int? SrcPrefetchCount { get; init; }
[System.Text.Json.Serialization.JsonIgnore(Condition=System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull)]
[System.Text.Json.Serialization.JsonPropertyName("src-protocol")]
public string SrcProtocol { get; init; }
public string? SrcProtocol { get; init; }
[System.Text.Json.Serialization.JsonConverter(typeof(EasyNetQ.Management.Client.Serialization.StringObjectReadOnlyDictionaryConverter?))]
[System.Text.Json.Serialization.JsonIgnore(Condition=System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull)]
[System.Text.Json.Serialization.JsonPropertyName("src-queue-args")]
public System.Collections.Generic.IReadOnlyDictionary<string, object?>? SrcQueueArguments { get; init; }
[System.Text.Json.Serialization.JsonIgnore(Condition=System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull)]
[System.Text.Json.Serialization.JsonPropertyName("src-queue")]
public string? SrcQueue { get; init; }
[System.Text.Json.Serialization.JsonPropertyName("src-uri")]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
using EasyNetQ.Management.Client.Model;
using System.Text.Json;

namespace EasyNetQ.Management.Client.IntegrationTests;

using JsonSerializer = System.Text.Json.JsonSerializer;

[Collection("RabbitMQ")]
public class ManagementClientTests
{
Expand Down Expand Up @@ -106,7 +109,7 @@
{
const string exchangeName = "test-dead-letter-exchange";
const string argumentKey = "x-dead-letter-exchange";
var queueInfo = new QueueInfo(Name: $"{TestQueue}1", Arguments: new Dictionary<string, object> { { argumentKey, exchangeName } });
var queueInfo = new QueueInfo(Name: $"{TestQueue}1", Arguments: new Dictionary<string, object?> { { argumentKey, exchangeName } });

await fixture.ManagementClient.CreateQueueAsync(queueInfo, Vhost);
var queue = await fixture.ManagementClient.GetQueueAsync(Vhost, queueInfo.Name);
Expand Down Expand Up @@ -295,7 +298,7 @@
&& p.Definition.MaxLengthBytes == maxLengthBytes
&& p.Definition.Overflow == overflow
&& p.Definition.ConsumerTimeout == consumerTimeout
&& p.Definition.ExtensionData.Keys.Order().SequenceEqual(extensionData.Keys.Order()))

Check warning on line 301 in Source/EasyNetQ.Management.Client.IntegrationTests/ManagementClientTests.cs

View workflow job for this annotation

GitHub Actions / Lint & Tests

Dereference of a possibly null reference.

Check warning on line 301 in Source/EasyNetQ.Management.Client.IntegrationTests/ManagementClientTests.cs

View workflow job for this annotation

GitHub Actions / Integrations Tests (3.10)

Dereference of a possibly null reference.

Check warning on line 301 in Source/EasyNetQ.Management.Client.IntegrationTests/ManagementClientTests.cs

View workflow job for this annotation

GitHub Actions / Integrations Tests (3.11)

Dereference of a possibly null reference.

Check warning on line 301 in Source/EasyNetQ.Management.Client.IntegrationTests/ManagementClientTests.cs

View workflow job for this annotation

GitHub Actions / Integrations Tests (3.12)

Dereference of a possibly null reference.
);
}

Expand Down Expand Up @@ -787,9 +790,9 @@
);

queue.Name.Should().Be(TestQueue);
queue.MessagesDetails.Samples.Count.Should().BeGreaterThan(0);

Check warning on line 793 in Source/EasyNetQ.Management.Client.IntegrationTests/ManagementClientTests.cs

View workflow job for this annotation

GitHub Actions / Lint & Tests

Dereference of a possibly null reference.

Check warning on line 793 in Source/EasyNetQ.Management.Client.IntegrationTests/ManagementClientTests.cs

View workflow job for this annotation

GitHub Actions / Lint & Tests

Dereference of a possibly null reference.

Check warning on line 793 in Source/EasyNetQ.Management.Client.IntegrationTests/ManagementClientTests.cs

View workflow job for this annotation

GitHub Actions / Integrations Tests (3.10)

Dereference of a possibly null reference.

Check warning on line 793 in Source/EasyNetQ.Management.Client.IntegrationTests/ManagementClientTests.cs

View workflow job for this annotation

GitHub Actions / Integrations Tests (3.10)

Dereference of a possibly null reference.

Check warning on line 793 in Source/EasyNetQ.Management.Client.IntegrationTests/ManagementClientTests.cs

View workflow job for this annotation

GitHub Actions / Integrations Tests (3.11)

Dereference of a possibly null reference.

Check warning on line 793 in Source/EasyNetQ.Management.Client.IntegrationTests/ManagementClientTests.cs

View workflow job for this annotation

GitHub Actions / Integrations Tests (3.11)

Dereference of a possibly null reference.

Check warning on line 793 in Source/EasyNetQ.Management.Client.IntegrationTests/ManagementClientTests.cs

View workflow job for this annotation

GitHub Actions / Integrations Tests (3.12)

Dereference of a possibly null reference.

Check warning on line 793 in Source/EasyNetQ.Management.Client.IntegrationTests/ManagementClientTests.cs

View workflow job for this annotation

GitHub Actions / Integrations Tests (3.12)

Dereference of a possibly null reference.
queue.MessagesReadyDetails.Samples.Count.Should().BeGreaterThan(0);

Check warning on line 794 in Source/EasyNetQ.Management.Client.IntegrationTests/ManagementClientTests.cs

View workflow job for this annotation

GitHub Actions / Lint & Tests

Dereference of a possibly null reference.

Check warning on line 794 in Source/EasyNetQ.Management.Client.IntegrationTests/ManagementClientTests.cs

View workflow job for this annotation

GitHub Actions / Lint & Tests

Dereference of a possibly null reference.

Check warning on line 794 in Source/EasyNetQ.Management.Client.IntegrationTests/ManagementClientTests.cs

View workflow job for this annotation

GitHub Actions / Integrations Tests (3.10)

Dereference of a possibly null reference.

Check warning on line 794 in Source/EasyNetQ.Management.Client.IntegrationTests/ManagementClientTests.cs

View workflow job for this annotation

GitHub Actions / Integrations Tests (3.10)

Dereference of a possibly null reference.

Check warning on line 794 in Source/EasyNetQ.Management.Client.IntegrationTests/ManagementClientTests.cs

View workflow job for this annotation

GitHub Actions / Integrations Tests (3.11)

Dereference of a possibly null reference.

Check warning on line 794 in Source/EasyNetQ.Management.Client.IntegrationTests/ManagementClientTests.cs

View workflow job for this annotation

GitHub Actions / Integrations Tests (3.11)

Dereference of a possibly null reference.

Check warning on line 794 in Source/EasyNetQ.Management.Client.IntegrationTests/ManagementClientTests.cs

View workflow job for this annotation

GitHub Actions / Integrations Tests (3.12)

Dereference of a possibly null reference.

Check warning on line 794 in Source/EasyNetQ.Management.Client.IntegrationTests/ManagementClientTests.cs

View workflow job for this annotation

GitHub Actions / Integrations Tests (3.12)

Dereference of a possibly null reference.
queue.MessagesUnacknowledgedDetails.Samples.Count.Should().BeGreaterThan(0);

Check warning on line 795 in Source/EasyNetQ.Management.Client.IntegrationTests/ManagementClientTests.cs

View workflow job for this annotation

GitHub Actions / Lint & Tests

Dereference of a possibly null reference.

Check warning on line 795 in Source/EasyNetQ.Management.Client.IntegrationTests/ManagementClientTests.cs

View workflow job for this annotation

GitHub Actions / Lint & Tests

Dereference of a possibly null reference.

Check warning on line 795 in Source/EasyNetQ.Management.Client.IntegrationTests/ManagementClientTests.cs

View workflow job for this annotation

GitHub Actions / Integrations Tests (3.10)

Dereference of a possibly null reference.

Check warning on line 795 in Source/EasyNetQ.Management.Client.IntegrationTests/ManagementClientTests.cs

View workflow job for this annotation

GitHub Actions / Integrations Tests (3.10)

Dereference of a possibly null reference.

Check warning on line 795 in Source/EasyNetQ.Management.Client.IntegrationTests/ManagementClientTests.cs

View workflow job for this annotation

GitHub Actions / Integrations Tests (3.11)

Dereference of a possibly null reference.

Check warning on line 795 in Source/EasyNetQ.Management.Client.IntegrationTests/ManagementClientTests.cs

View workflow job for this annotation

GitHub Actions / Integrations Tests (3.11)

Dereference of a possibly null reference.

Check warning on line 795 in Source/EasyNetQ.Management.Client.IntegrationTests/ManagementClientTests.cs

View workflow job for this annotation

GitHub Actions / Integrations Tests (3.12)

Dereference of a possibly null reference.

Check warning on line 795 in Source/EasyNetQ.Management.Client.IntegrationTests/ManagementClientTests.cs

View workflow job for this annotation

GitHub Actions / Integrations Tests (3.12)

Dereference of a possibly null reference.
}

[Fact]
Expand All @@ -803,7 +806,7 @@
var queue = await fixture.ManagementClient.GetQueueAsync(Vhost, TestQueue, new LengthsCriteria(age, increment));

queue.Name.Should().Be(TestQueue);
queue.MessagesDetails.Samples.Count.Should().BeGreaterThan(0);

Check warning on line 809 in Source/EasyNetQ.Management.Client.IntegrationTests/ManagementClientTests.cs

View workflow job for this annotation

GitHub Actions / Lint & Tests

Dereference of a possibly null reference.

Check warning on line 809 in Source/EasyNetQ.Management.Client.IntegrationTests/ManagementClientTests.cs

View workflow job for this annotation

GitHub Actions / Integrations Tests (3.10)

Dereference of a possibly null reference.

Check warning on line 809 in Source/EasyNetQ.Management.Client.IntegrationTests/ManagementClientTests.cs

View workflow job for this annotation

GitHub Actions / Integrations Tests (3.11)

Dereference of a possibly null reference.

Check warning on line 809 in Source/EasyNetQ.Management.Client.IntegrationTests/ManagementClientTests.cs

View workflow job for this annotation

GitHub Actions / Integrations Tests (3.12)

Dereference of a possibly null reference.
queue.MessagesReadyDetails.Samples.Count.Should().BeGreaterThan(0);
queue.MessagesUnacknowledgedDetails.Samples.Count.Should().BeGreaterThan(0);
}
Expand Down Expand Up @@ -868,7 +871,7 @@
TestQueue,
"Hello World",
PayloadEncoding.String,
new Dictionary<string, object>
new Dictionary<string, object?>
{
{ "app_id", "management-test" }
}
Expand Down Expand Up @@ -1301,30 +1304,39 @@
var destUri = new AmqpUri($"{fixture.Endpoint.Host}-1", fixture.Endpoint.Port, fixture.User, fixture.Password);

var shovelName = "queue-shovel";

await fixture.ManagementClient.CreateShovelAsync(
vhostName: Vhost.Name,
shovelName,
new ParameterShovelValue
var parameterShovelValue = new ParameterShovelValue
(
SrcProtocol: AmqpProtocol.AMQP091,
SrcUri: srcUri.ToString(),
SrcQueue: "test-queue-src",
SrcExchange: null,
SrcExchangeKey: null,
SrcQueueArguments: new Dictionary<string, object?> { { "x-queue-mode", "lazy" } },
SrcDeleteAfter: "never",
SrcPrefetchCount: 10,
DestProtocol: AmqpProtocol.AMQP091,
DestUri: destUri.ToString(),
DestQueue: "test-queue-dest",
DestExchange: null,
DestQueueArguments: new Dictionary<string, object?> { { "x-queue-mode", "lazy" } },
DestAddForwardHeaders: false,
DestAddTimestampHeader: false,
AckMode: "on-confirm",
AddForwardHeaders: false
)
ReconnectDelay: 10
);

await fixture.ManagementClient.CreateShovelAsync(
vhostName: Vhost.Name,
shovelName,
parameterShovelValue
);

var parameter = await fixture.ManagementClient.GetShovelAsync(Vhost.Name, shovelName);

Assert.Equal(shovelName, parameter.Name);
parameter.Value.Should().BeOfType<JsonElement>();
if (parameter.Value is JsonElement jsonElement)
{
var actualParameterShovelValue = JsonSerializer.Deserialize<ParameterShovelValue>(jsonElement.GetRawText());
actualParameterShovelValue.Should().BeEquivalentTo(parameterShovelValue);
}
}

[Fact]
Expand All @@ -1334,30 +1346,39 @@
var destUri = new AmqpUri($"{fixture.Endpoint.Host}-1", fixture.Endpoint.Port, fixture.User, fixture.Password);

var shovelName = "exchange-shovel";

await fixture.ManagementClient.CreateShovelAsync(
vhostName: Vhost.Name,
shovelName,
new ParameterShovelValue
var parameterShovelValue = new ParameterShovelValue
(
SrcProtocol: AmqpProtocol.AMQP091,
SrcUri: srcUri.ToString(),
SrcExchange: "test-exchange-src",
SrcExchangeKey: null,
SrcQueue: null,
SrcExchangeKey: "aaa",
SrcDeleteAfter: "never",
SrcPrefetchCount: 10,
DestProtocol: AmqpProtocol.AMQP091,
DestUri: destUri.ToString(),
DestExchange: "test-exchange-dest",
DestQueue: null,
DestExchangeKey: "bbb",
DestAddForwardHeaders: false,
DestAddTimestampHeader: false,
AckMode: "on-confirm",
AddForwardHeaders: false
)
ReconnectDelay: 10
);

await fixture.ManagementClient.CreateShovelAsync(
vhostName: Vhost.Name,
shovelName,
parameterShovelValue
);

var parameters = await fixture.ManagementClient.GetParametersAsync();
var parameter = await fixture.ManagementClient.GetShovelAsync(Vhost.Name, shovelName);

Assert.Contains(parameters, p => p.Name == shovelName);
Assert.Equal(shovelName, parameter.Name);
parameter.Value.Should().BeOfType<JsonElement>();
if (parameter.Value is JsonElement jsonElement)
{
var actualParameterShovelValue = JsonSerializer.Deserialize<ParameterShovelValue>(jsonElement.GetRawText());
actualParameterShovelValue.Should().BeEquivalentTo(parameterShovelValue);
}
}

[Fact]
Expand Down Expand Up @@ -1391,7 +1412,7 @@
DestExchange: "test-exchange-dest",
DestQueue: null,
AckMode: "on-confirm",
AddForwardHeaders: false
DestAddForwardHeaders: false
)
);

Expand Down
84 changes: 66 additions & 18 deletions Source/EasyNetQ.Management.Client/Model/ParameterShovelValue.cs
Original file line number Diff line number Diff line change
@@ -1,33 +1,81 @@
using System.Text.Json.Serialization;
using EasyNetQ.Management.Client.Serialization;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace EasyNetQ.Management.Client.Model;

/// <summary>
/// About shovel parameters: https://www.rabbitmq.com/shovel-dynamic.html
/// </summary>
public record ParameterShovelValue(
[property: JsonPropertyName("src-protocol")]
string SrcProtocol,
[property: JsonPropertyName("src-uri")]
string SrcUri,
[property: JsonPropertyName("dest-uri")]
string DestUri,

[property: JsonPropertyName("src-protocol")]
[property: JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
string? SrcProtocol = null, // Either amqp091 or amqp10. If omitted it will default to amqp091.
[property: JsonPropertyName("src-queue")]
[property: JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
string? SrcQueue = null,
[property: JsonPropertyName("src-queue-args")]
[property: JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[property: JsonConverter(typeof(StringObjectReadOnlyDictionaryConverter))]
IReadOnlyDictionary<string, object?>? SrcQueueArguments = null,
[property: JsonPropertyName("src-exchange")]
string? SrcExchange,
[property: JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
string? SrcExchange = null,
[property: JsonPropertyName("src-exchange-key")]
string? SrcExchangeKey,
[property: JsonPropertyName("src-queue")]
string? SrcQueue,
[property: JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
string? SrcExchangeKey = null,

[property: JsonPropertyName("src-delete-after")]
string SrcDeleteAfter,
[property: JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
string? SrcDeleteAfter = null,
[property: JsonPropertyName("src-prefetch-count")]
[property: JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
int? SrcPrefetchCount = null,

[property: JsonPropertyName("dest-protocol")]
string DestProtocol,
[property: JsonPropertyName("dest-uri")]
string DestUri,
[property: JsonPropertyName("dest-exchange")]
string? DestExchange,
[property: JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
string? DestProtocol = null, // Either amqp091 or amqp10. If omitted it will default to amqp091.
[property: JsonPropertyName("dest-queue")]
string? DestQueue,
[property: JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
string? DestQueue = null,
[property: JsonPropertyName("dest-queue-args")]
[property: JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[property: JsonConverter(typeof(StringObjectReadOnlyDictionaryConverter))]
IReadOnlyDictionary<string, object?>? DestQueueArguments = null,
[property: JsonPropertyName("dest-exchange")]
[property: JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
string? DestExchange = null,
[property: JsonPropertyName("dest-exchange-key")]
[property: JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
string? DestExchangeKey = null,

[property: JsonPropertyName("dest-add-forward-headers")]
[property: JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
bool? DestAddForwardHeaders = null,
[property: JsonPropertyName("dest-add-timestamp-header")]
[property: JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
bool? DestAddTimestampHeader = null,

[property: JsonPropertyName("ack-mode")]
string AckMode,
[property: JsonPropertyName("add-forward-headers")]
bool AddForwardHeaders
);
[property: JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
string? AckMode = null,
[property: JsonPropertyName("reconnect-delay")]
[property: JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
int? ReconnectDelay = null
)
{
[JsonExtensionData()]
public IDictionary<string, JsonElement>? JsonExtensionData { get; set; }

[JsonIgnore()]
public IReadOnlyDictionary<string, object?>? ExtensionData
{
get { return JsonExtensionDataExtensions.ToExtensionData(JsonExtensionData); }
set { JsonExtensionData = JsonExtensionDataExtensions.ToJsonExtensionData(value); }
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using System.Text.Json;

namespace EasyNetQ.Management.Client.Serialization;

internal static class JsonExtensionDataExtensions
{
public static IReadOnlyDictionary<string, object?>? ToExtensionData(IDictionary<string, JsonElement>? jsonExtensionData)
{
Dictionary<string, object?>? dictionary;
if (jsonExtensionData == null)
{
dictionary = null;
}
else
{
dictionary = new Dictionary<string, object?>();
foreach (var property in jsonExtensionData)
{
dictionary.Add(property.Key, property.Value.GetObjectValue());
}
}
return dictionary;
}
public static IDictionary<string, JsonElement>? ToJsonExtensionData(IReadOnlyDictionary<string, object?>? extensionData)
{
IDictionary<string, JsonElement>? dictionary;
if (extensionData == null)
{
dictionary = null;
}
else
{
dictionary = new Dictionary<string, JsonElement>();
foreach (var property in extensionData)
{
#if NET6_0_OR_GREATER
dictionary.Add(property.Key, JsonSerializer.SerializeToElement(property.Value));
#else
var bytes = JsonSerializer.SerializeToUtf8Bytes(property.Value);
dictionary.Add(property.Key, JsonDocument.Parse(bytes).RootElement.Clone());
#endif
}
}
return dictionary;
}
}
Loading