Skip to content

Commit 97c2729

Browse files
authored
feature flags (#130)
Signed-off-by: Gabriele Santomaggio <[email protected]>
1 parent 8dcbad6 commit 97c2729

File tree

3 files changed

+34
-4
lines changed

3 files changed

+34
-4
lines changed

RabbitMQ.AMQP.Client/FeatureFlags.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// This source code is dual-licensed under the Apache License, version 2.0,
2+
// and the Mozilla Public License, version 2.0.
3+
// Copyright (c) 2017-2024 Broadcom. All Rights Reserved. The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries.
4+
5+
namespace RabbitMQ.AMQP.Client
6+
{
7+
internal class FeatureFlags
8+
{
9+
public bool IsSqlFeatureEnabled { get; set; } = false;
10+
public bool IsBrokerCompatible { get; set; } = false;
11+
12+
public void Validate()
13+
{
14+
if (!IsBrokerCompatible)
15+
{
16+
throw new ConnectionException("Client not compatible with the broker version. " +
17+
"The client requires RabbitMQ 4.0 or later.");
18+
}
19+
}
20+
}
21+
}

RabbitMQ.AMQP.Client/Impl/AmqpConnection.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public class AmqpConnection : AbstractLifeCycle, IConnection
4040

4141
private readonly Dictionary<string, object> _connectionProperties = new();
4242
private bool _areFilterExpressionsSupported = false;
43+
private FeatureFlags _featureFlags = new FeatureFlags();
4344

4445
/// <summary>
4546
/// _publishersDict contains all the publishers created by the connection.
@@ -90,6 +91,7 @@ public static async Task<IConnection> CreateAsync(ConnectionSettings connectionS
9091
AmqpConnection connection = new(connectionSettings, metricsReporter);
9192
await connection.OpenAsync()
9293
.ConfigureAwait(false);
94+
9395
return connection;
9496
}
9597

@@ -189,6 +191,7 @@ await OpenConnectionAsync(CancellationToken.None)
189191
.ConfigureAwait(false);
190192
await base.OpenAsync()
191193
.ConfigureAwait(false);
194+
_featureFlags.Validate();
192195
}
193196

194197
public override async Task CloseAsync()
@@ -665,10 +668,11 @@ private void HandleProperties(Fields properties)
665668
}
666669

667670
string brokerVersion = (string)_connectionProperties["version"];
668-
if (false == Utils.Is4_0_OrMore(brokerVersion))
669-
{
670-
// TODO Java client throws exception here
671-
}
671+
_featureFlags.IsBrokerCompatible = Utils.Is4_0_OrMore(brokerVersion);
672+
673+
// check if the broker supports filter expressions
674+
// this is a feature that was introduced in RabbitMQ 4.2.0
675+
_featureFlags.IsSqlFeatureEnabled = Utils.Is4_2_OrMore(brokerVersion);
672676

673677
_areFilterExpressionsSupported = Utils.SupportsFilterExpressions(brokerVersion);
674678
}

RabbitMQ.AMQP.Client/Utils.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,11 @@ internal static bool Is4_1_OrMore(string brokerVersion)
250250
return VersionCompare(CurrentVersion(brokerVersion), "4.1.0") >= 0;
251251
}
252252

253+
internal static bool Is4_2_OrMore(string brokerVersion)
254+
{
255+
return VersionCompare(CurrentVersion(brokerVersion), "4.2.0") >= 0;
256+
}
257+
253258
private static string CurrentVersion(string currentVersion)
254259
{
255260
// versions built from source: 3.7.0+rc.1.4.gedc5d96

0 commit comments

Comments
 (0)