diff --git a/RabbitMQ.AMQP.Client/FeatureFlags.cs b/RabbitMQ.AMQP.Client/FeatureFlags.cs new file mode 100644 index 0000000..7adbcb2 --- /dev/null +++ b/RabbitMQ.AMQP.Client/FeatureFlags.cs @@ -0,0 +1,21 @@ +// This source code is dual-licensed under the Apache License, version 2.0, +// and the Mozilla Public License, version 2.0. +// Copyright (c) 2017-2024 Broadcom. All Rights Reserved. The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries. + +namespace RabbitMQ.AMQP.Client +{ + internal class FeatureFlags + { + public bool IsSqlFeatureEnabled { get; set; } = false; + public bool IsBrokerCompatible { get; set; } = false; + + public void Validate() + { + if (!IsBrokerCompatible) + { + throw new ConnectionException("Client not compatible with the broker version. " + + "The client requires RabbitMQ 4.0 or later."); + } + } + } +} diff --git a/RabbitMQ.AMQP.Client/Impl/AmqpConnection.cs b/RabbitMQ.AMQP.Client/Impl/AmqpConnection.cs index 8899043..5d1d856 100644 --- a/RabbitMQ.AMQP.Client/Impl/AmqpConnection.cs +++ b/RabbitMQ.AMQP.Client/Impl/AmqpConnection.cs @@ -40,6 +40,7 @@ public class AmqpConnection : AbstractLifeCycle, IConnection private readonly Dictionary _connectionProperties = new(); private bool _areFilterExpressionsSupported = false; + private FeatureFlags _featureFlags = new FeatureFlags(); /// /// _publishersDict contains all the publishers created by the connection. @@ -90,6 +91,7 @@ public static async Task CreateAsync(ConnectionSettings connectionS AmqpConnection connection = new(connectionSettings, metricsReporter); await connection.OpenAsync() .ConfigureAwait(false); + return connection; } @@ -189,6 +191,7 @@ await OpenConnectionAsync(CancellationToken.None) .ConfigureAwait(false); await base.OpenAsync() .ConfigureAwait(false); + _featureFlags.Validate(); } public override async Task CloseAsync() @@ -665,10 +668,11 @@ private void HandleProperties(Fields properties) } string brokerVersion = (string)_connectionProperties["version"]; - if (false == Utils.Is4_0_OrMore(brokerVersion)) - { - // TODO Java client throws exception here - } + _featureFlags.IsBrokerCompatible = Utils.Is4_0_OrMore(brokerVersion); + + // check if the broker supports filter expressions + // this is a feature that was introduced in RabbitMQ 4.2.0 + _featureFlags.IsSqlFeatureEnabled = Utils.Is4_2_OrMore(brokerVersion); _areFilterExpressionsSupported = Utils.SupportsFilterExpressions(brokerVersion); } diff --git a/RabbitMQ.AMQP.Client/Utils.cs b/RabbitMQ.AMQP.Client/Utils.cs index a09676f..2eb5d1e 100644 --- a/RabbitMQ.AMQP.Client/Utils.cs +++ b/RabbitMQ.AMQP.Client/Utils.cs @@ -250,6 +250,11 @@ internal static bool Is4_1_OrMore(string brokerVersion) return VersionCompare(CurrentVersion(brokerVersion), "4.1.0") >= 0; } + internal static bool Is4_2_OrMore(string brokerVersion) + { + return VersionCompare(CurrentVersion(brokerVersion), "4.2.0") >= 0; + } + private static string CurrentVersion(string currentVersion) { // versions built from source: 3.7.0+rc.1.4.gedc5d96