Skip to content

Commit 490e21e

Browse files
authored
Add PolicyDefinition.ExtensionData, Queue.ExtensionData, IMC.GetQueuesWithoutStatsAsync (#285)
* Create QueueWithoutStats.cs * Create QueueType.cs * Update Queue.cs * Update PolicyDefinition.cs * Update IManagementClient.cs * Update IManagementClient.cs * Update Connection.cs * Update IManagementClient.cs * Update ManagementClient.cs * Fix * fix * Fix formatting * approved.txt * string? Node * string? Node * . * fix
1 parent 7ca648c commit 490e21e

File tree

10 files changed

+269
-67
lines changed

10 files changed

+269
-67
lines changed

Source/EasyNetQ.Management.Client.ApprovalTests/EasyNetQ.Management.Client.approved.txt

Lines changed: 54 additions & 28 deletions
Large diffs are not rendered by default.

Source/EasyNetQ.Management.Client.IntegrationTests/ManagementClientTests.cs

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ public async Task Should_be_able_to_create_all_the_definitions_in_a_policy()
234234
const long maxLengthBytes = 5000;
235235
const Overflow overflow = Overflow.RejectPublish;
236236
uint? consumerTimeout = fixture.RabbitmqVersion >= new Version("3.12") ? 3600000 : null;
237+
Dictionary<string, object> extensionData = new Dictionary<string, object> { { "max-in-memory-length", 1000000 } };
237238

238239
await fixture.ManagementClient.CreatePolicyAsync(
239240
new Policy(
@@ -265,7 +266,8 @@ await fixture.ManagementClient.CreatePolicyAsync(
265266
MaxLengthBytes: maxLengthBytes,
266267
Overflow: overflow,
267268
ConsumerTimeout: consumerTimeout
268-
),
269+
)
270+
{ ExtensionData = extensionData },
269271
Priority: priority
270272
)
271273
);
@@ -292,7 +294,8 @@ await fixture.ManagementClient.CreatePolicyAsync(
292294
&& p.Definition.MaxLength == maxLength
293295
&& p.Definition.MaxLengthBytes == maxLengthBytes
294296
&& p.Definition.Overflow == overflow
295-
&& p.Definition.ConsumerTimeout == consumerTimeout)
297+
&& p.Definition.ConsumerTimeout == consumerTimeout
298+
&& p.Definition.ExtensionData.Keys.Order().SequenceEqual(extensionData.Keys.Order()))
296299
);
297300
}
298301

@@ -1207,7 +1210,24 @@ public async Task Should_get_permissions()
12071210
public async Task Should_get_queues()
12081211
{
12091212
await CreateTestQueue(TestQueue);
1210-
(await fixture.ManagementClient.GetQueuesAsync()).Count.Should().BeGreaterThan(0);
1213+
while (true)
1214+
{
1215+
var queues = await fixture.ManagementClient.GetQueuesAsync();
1216+
queues.Should().NotBeNullOrEmpty();
1217+
if (queues[0].State != null)
1218+
{
1219+
queues[0].ExtensionData.Should().NotBeNullOrEmpty();
1220+
break;
1221+
}
1222+
}
1223+
}
1224+
1225+
[Fact]
1226+
public async Task Should_get_queues_without_stats()
1227+
{
1228+
await CreateTestQueue(TestQueue);
1229+
var queues = await fixture.ManagementClient.GetQueuesWithoutStatsAsync();
1230+
queues.Should().NotBeNullOrEmpty();
12111231
}
12121232

12131233

Source/EasyNetQ.Management.Client/IManagementClient.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ Task<Channel> GetChannelAsync(
9999
Task<PageResult<Exchange>> GetExchangesByPageAsync(PageCriteria pageCriteria, CancellationToken cancellationToken = default);
100100

101101
/// <summary>
102-
/// A list of all exchanges.
102+
/// A list of all exchanges for a virtual host.
103103
/// </summary>
104104
/// <param name="vhostName"></param>
105105
/// <param name="cancellationToken"></param>
@@ -147,6 +147,13 @@ Task<Channel> GetChannelAsync(
147147
/// <returns></returns>
148148
Task<PageResult<Queue>> GetQueuesByPageAsync(string vhostName, PageCriteria pageCriteria, CancellationToken cancellationToken = default);
149149

150+
/// <summary>
151+
/// A list of all queues.
152+
/// </summary>
153+
/// <param name="cancellationToken"></param>
154+
/// <returns></returns>
155+
Task<IReadOnlyList<QueueWithoutStats>> GetQueuesWithoutStatsAsync(CancellationToken cancellationToken = default);
156+
150157
/// <summary>
151158
/// A list of all bindings.
152159
/// </summary>

Source/EasyNetQ.Management.Client/ManagementClient.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ public class ManagementClient : IManagementClient
4242
private static readonly RelativePath Health = Api / "health";
4343
private static readonly RelativePath Rebalance = Api / "rebalance";
4444

45+
private static readonly Dictionary<string, string> GetQueuesWithoutStatsQueryParameters = new Dictionary<string, string> {
46+
{ "disable_stats", "true" },
47+
{ "enable_queue_totals", "true" }
48+
};
49+
4550
internal static readonly JsonSerializerOptions SerializerOptions;
4651

4752
private readonly HttpClient httpClient;
@@ -313,6 +318,11 @@ public Task<PageResult<Queue>> GetQueuesByPageAsync(string vhostName, PageCriter
313318
return GetAsync<PageResult<Queue>>(Queues / vhostName, pageCriteria.ToQueryParameters(), cancellationToken);
314319
}
315320

321+
public Task<IReadOnlyList<QueueWithoutStats>> GetQueuesWithoutStatsAsync(CancellationToken cancellationToken = default)
322+
{
323+
return GetAsync<IReadOnlyList<QueueWithoutStats>>(Queues, GetQueuesWithoutStatsQueryParameters, cancellationToken);
324+
}
325+
316326
public Task CreateQueueAsync(
317327
string vhostName,
318328
QueueInfo queueInfo,

Source/EasyNetQ.Management.Client/ManagementClientExtensions.cs

Lines changed: 117 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ public static Overview GetOverview(
2424
.GetResult();
2525
}
2626

27-
2827
/// <summary>
2928
/// A list of nodes in the RabbitMQ cluster.
3029
/// </summary>
@@ -74,6 +73,24 @@ public static IReadOnlyList<Connection> GetConnections(
7473
.GetResult();
7574
}
7675

76+
/// <summary>
77+
/// A list of all open connections on the specified VHost.
78+
/// </summary>
79+
/// <param name="client"></param>
80+
/// <param name="vhostName"></param>
81+
/// <param name="cancellationToken"></param>
82+
/// <returns></returns>
83+
public static IReadOnlyList<Connection> GetConnections(
84+
this IManagementClient client,
85+
string vhostName,
86+
CancellationToken cancellationToken = default
87+
)
88+
{
89+
return client.GetConnectionsAsync(vhostName, cancellationToken)
90+
.GetAwaiter()
91+
.GetResult();
92+
}
93+
7794
/// <summary>
7895
/// A list of all open channels.
7996
/// </summary>
@@ -91,7 +108,25 @@ public static IReadOnlyList<Channel> GetChannels(
91108
}
92109

93110
/// <summary>
94-
/// A list of all open channels.
111+
/// A list of all open channels for the given connection.
112+
/// </summary>
113+
/// <param name="client"></param>
114+
/// <param name="connectionName"></param>
115+
/// <param name="cancellationToken"></param>
116+
/// <returns></returns>
117+
public static IReadOnlyList<Channel> GetChannels(
118+
this IManagementClient client,
119+
string connectionName,
120+
CancellationToken cancellationToken = default
121+
)
122+
{
123+
return client.GetChannelsAsync(connectionName, cancellationToken)
124+
.GetAwaiter()
125+
.GetResult();
126+
}
127+
128+
/// <summary>
129+
/// A list of all open channels for the given connection.
95130
/// </summary>
96131
/// <param name="client"></param>
97132
/// <param name="connection"></param>
@@ -103,6 +138,24 @@ public static Task<IReadOnlyList<Channel>> GetChannelsAsync(
103138
CancellationToken cancellationToken = default
104139
) => client.GetChannelsAsync(connection.Name, cancellationToken);
105140

141+
/// <summary>
142+
/// A list of all open channels for the given connection.
143+
/// </summary>
144+
/// <param name="client"></param>
145+
/// <param name="connection"></param>
146+
/// <param name="cancellationToken"></param>
147+
/// <returns></returns>
148+
public static IReadOnlyList<Channel> GetChannels(
149+
this IManagementClient client,
150+
Connection connection,
151+
CancellationToken cancellationToken = default
152+
)
153+
{
154+
return client.GetChannelsAsync(connection, cancellationToken)
155+
.GetAwaiter()
156+
.GetResult();
157+
}
158+
106159
/// <summary>
107160
/// Gets the channel. This returns more detail, including consumers than the GetChannels method.
108161
/// </summary>
@@ -139,6 +192,24 @@ public static IReadOnlyList<Exchange> GetExchanges(
139192
.GetResult();
140193
}
141194

195+
/// <summary>
196+
/// A list of all exchanges for a virtual host.
197+
/// </summary>
198+
/// <param name="client"></param>
199+
/// <param name="vhostName"></param>
200+
/// <param name="cancellationToken"></param>
201+
/// <returns></returns>
202+
public static IReadOnlyList<Exchange> GetExchanges(
203+
this IManagementClient client,
204+
string vhostName,
205+
CancellationToken cancellationToken = default
206+
)
207+
{
208+
return client.GetExchangesAsync(vhostName, cancellationToken)
209+
.GetAwaiter()
210+
.GetResult();
211+
}
212+
142213
/// <summary>
143214
/// A list of all queues.
144215
/// </summary>
@@ -155,6 +226,24 @@ public static IReadOnlyList<Queue> GetQueues(
155226
.GetResult();
156227
}
157228

229+
/// <summary>
230+
/// A list of all queues for a virtual host.
231+
/// </summary>
232+
/// <param name="client"></param>
233+
/// <param name="vhostName"></param>
234+
/// <param name="cancellationToken"></param>
235+
/// <returns></returns>
236+
public static IReadOnlyList<Queue> GetQueues(
237+
this IManagementClient client,
238+
string vhostName,
239+
CancellationToken cancellationToken = default
240+
)
241+
{
242+
return client.GetQueuesAsync(vhostName, cancellationToken)
243+
.GetAwaiter()
244+
.GetResult();
245+
}
246+
158247
/// <summary>
159248
/// A list of all queues for a virtual host.
160249
/// </summary>
@@ -239,6 +328,17 @@ public static PageResult<Queue> GetQueuesByPage(
239328
.GetResult();
240329
}
241330

331+
/// <summary>
332+
/// A list of all queues without stats.
333+
/// </summary>
334+
/// <param name="client"></param>
335+
/// <param name="cancellationToken"></param>
336+
/// <returns></returns>
337+
public static IReadOnlyList<QueueWithoutStats> GetQueuesWithoutStats(
338+
this IManagementClient client,
339+
CancellationToken cancellationToken = default
340+
) => client.GetQueuesWithoutStatsAsync(cancellationToken).GetAwaiter().GetResult();
341+
242342
/// <summary>
243343
/// A list of all bindings.
244344
/// </summary>
@@ -1658,13 +1758,13 @@ public static Parameter GetShovel(
16581758
string vhostName,
16591759
string shovelName,
16601760
CancellationToken cancellationToken = default
1661-
)
1662-
{
1663-
return client.GetParameterAsync(vhostName, "shovel", shovelName, cancellationToken)
1664-
.GetAwaiter()
1665-
.GetResult();
1761+
)
1762+
{
1763+
return client.GetParameterAsync(vhostName, "shovel", shovelName, cancellationToken)
1764+
.GetAwaiter()
1765+
.GetResult();
16661766
}
1667-
1767+
16681768
/// <summary>
16691769
/// Creates a federation upstream in a specific vhost
16701770
/// </summary>
@@ -1680,7 +1780,7 @@ public static Task CreateFederationUpstreamAsync(
16801780
ParameterFederationValue federationUpstreamDescription,
16811781
CancellationToken cancellationToken = default
16821782
) => client.CreateParameterAsync("federation-upstream", vhostName, federationUpstreamName, federationUpstreamDescription, cancellationToken);
1683-
1783+
16841784
/// <summary>
16851785
/// Creates a federation upstream in a specific vhost
16861786
/// </summary>
@@ -1695,11 +1795,11 @@ public static void CreateFederationUpstream(
16951795
string federationUpstreamName,
16961796
ParameterFederationValue federationUpstreamDescription,
16971797
CancellationToken cancellationToken = default
1698-
)
1699-
{
1798+
)
1799+
{
17001800
client.CreateParameterAsync("federation-upstream", vhostName, federationUpstreamName, federationUpstreamDescription, cancellationToken)
17011801
.GetAwaiter()
1702-
.GetResult();
1802+
.GetResult();
17031803
}
17041804

17051805
/// <summary>
@@ -1728,10 +1828,10 @@ public static Parameter GetFederationUpstream(
17281828
string vhostName,
17291829
string federationUpstreamName,
17301830
CancellationToken cancellationToken = default
1731-
)
1732-
{
1733-
return client.GetParameterAsync(vhostName, "federation-upstream", federationUpstreamName, cancellationToken)
1734-
.GetAwaiter()
1735-
.GetResult();
1831+
)
1832+
{
1833+
return client.GetParameterAsync(vhostName, "federation-upstream", federationUpstreamName, cancellationToken)
1834+
.GetAwaiter()
1835+
.GetResult();
17361836
}
17371837
}

Source/EasyNetQ.Management.Client/Model/Connection.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System.Text.Json.Serialization;
1+
using System.Text.Json.Serialization;
22
using EasyNetQ.Management.Client.Serialization;
33

44
namespace EasyNetQ.Management.Client.Model;
@@ -9,7 +9,7 @@ public record Connection(
99
long SendOct,
1010
long SendCnt,
1111
long SendPend,
12-
string State,
12+
string? State,
1313
string? LastBlockedBy,
1414
string? LastBlockedAge,
1515
long Channels,
@@ -18,13 +18,13 @@ public record Connection(
1818
string Name,
1919
string? Address,
2020
int Port,
21-
string PeerHost,
21+
string? PeerHost,
2222
int PeerPort,
2323
bool Ssl,
2424
string? PeerCertSubject,
2525
string? PeerCertIssuer,
2626
string? PeerCertValidity,
27-
string AuthMechanism,
27+
string? AuthMechanism,
2828
string? SslProtocol,
2929
string? SslKeyExchange,
3030
string? SslCipher,

Source/EasyNetQ.Management.Client/Model/PolicyDefinition.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,8 @@ public record PolicyDefinition
6767

6868
[property: JsonPropertyName("queue-mode")]
6969
string? QueueMode = null
70-
);
70+
)
71+
{
72+
[JsonExtensionData()]
73+
public Dictionary<string, object>? ExtensionData { get; set; }
74+
};

0 commit comments

Comments
 (0)