From 22133d24462c4f2e5c308f41154eda88b1d6d00e Mon Sep 17 00:00:00 2001 From: Michael Klishin Date: Thu, 17 Sep 2020 20:16:43 +0300 Subject: [PATCH] Fold IAutorecoveringConnection [back] into IConnection This undoes #758 (made in response to #515). The events make more sense in the primary IConnection interface. Most users enable automatic connection recovery and asking them to cast to IAutorecoveringConnection is counter-intuitive. As suggested in #515, we add no-op add and remove handlers so that IConnection is easier to implement/mock. See #940 for the discussion. Closes #940. --- .../client/api/IAutorecoveringConnection.cs | 53 ------------------- .../RabbitMQ.Client/client/api/IConnection.cs | 37 +++++++++++++ .../client/impl/AutorecoveringConnection.cs | 2 +- .../RabbitMQ.Client/client/impl/Connection.cs | 30 ++++++++++- .../Unit/APIApproval.Approve.verified.txt | 11 ++-- 5 files changed, 71 insertions(+), 62 deletions(-) delete mode 100644 projects/RabbitMQ.Client/client/api/IAutorecoveringConnection.cs diff --git a/projects/RabbitMQ.Client/client/api/IAutorecoveringConnection.cs b/projects/RabbitMQ.Client/client/api/IAutorecoveringConnection.cs deleted file mode 100644 index 6b8ed65b18..0000000000 --- a/projects/RabbitMQ.Client/client/api/IAutorecoveringConnection.cs +++ /dev/null @@ -1,53 +0,0 @@ -// This source code is dual-licensed under the Apache License, version -// 2.0, and the Mozilla Public License, version 2.0. -// -// The APL v2.0: -// -//--------------------------------------------------------------------------- -// Copyright (c) 2007-2020 VMware, Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -//--------------------------------------------------------------------------- -// -// The MPL v2.0: -// -//--------------------------------------------------------------------------- -// This Source Code Form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at https://mozilla.org/MPL/2.0/. -// -// Copyright (c) 2007-2020 VMware, Inc. All rights reserved. -//--------------------------------------------------------------------------- - -using System; -using System.Collections.Generic; -using System.IO; -using System.Threading; - -using RabbitMQ.Client.Events; -using RabbitMQ.Client.Exceptions; - -namespace RabbitMQ.Client -{ - /// - /// Interface to an auto-recovering AMQP connection. - /// - public interface IAutorecoveringConnection : IConnection - { - event EventHandler RecoverySucceeded; - event EventHandler ConnectionRecoveryError; - - event EventHandler ConsumerTagChangeAfterRecovery; - event EventHandler QueueNameChangeAfterRecovery; - } -} diff --git a/projects/RabbitMQ.Client/client/api/IConnection.cs b/projects/RabbitMQ.Client/client/api/IConnection.cs index 22b56bf1fb..5da59a801f 100644 --- a/projects/RabbitMQ.Client/client/api/IConnection.cs +++ b/projects/RabbitMQ.Client/client/api/IConnection.cs @@ -166,6 +166,43 @@ public interface IConnection : INetworkConnection, IDisposable /// event EventHandler ConnectionShutdown; + /// + /// Raised when the connection completes recovery. + /// + /// + /// This event will never fire for connections that disable automatic recovery. + /// + event EventHandler RecoverySucceeded; + + /// + /// Raised when the connection recovery fails, e.g. because reconnection or topology + /// recovery failed. + /// + /// + /// This event will never fire for connections that disable automatic recovery. + /// + event EventHandler ConnectionRecoveryError; + + /// + /// Raised when the server-generated tag of a consumer registered on this connection changes during + /// connection recovery. This allows applications that need to be aware of server-generated + /// consumer tag values to keep track of the changes. + /// + /// + /// This event will never fire for connections that disable automatic recovery. + /// + event EventHandler ConsumerTagChangeAfterRecovery; + + /// + /// Raised when the name of a server-named queue declared on this connection changes during + /// connection recovery. This allows applications that need to be aware of server-named + /// queue names to keep track of the changes. + /// + /// + /// This event will never fire for connections that disable automatic recovery. + /// + event EventHandler QueueNameChangeAfterRecovery; + event EventHandler ConnectionUnblocked; /// diff --git a/projects/RabbitMQ.Client/client/impl/AutorecoveringConnection.cs b/projects/RabbitMQ.Client/client/impl/AutorecoveringConnection.cs index 5a9e846040..ff39ba4a95 100644 --- a/projects/RabbitMQ.Client/client/impl/AutorecoveringConnection.cs +++ b/projects/RabbitMQ.Client/client/impl/AutorecoveringConnection.cs @@ -44,7 +44,7 @@ namespace RabbitMQ.Client.Framing.Impl { - internal sealed class AutorecoveringConnection : IAutorecoveringConnection + internal sealed class AutorecoveringConnection : IConnection { private bool _disposed = false; private readonly object _eventLock = new object(); diff --git a/projects/RabbitMQ.Client/client/impl/Connection.cs b/projects/RabbitMQ.Client/client/impl/Connection.cs index 3b9753257e..6e2dc2aa67 100644 --- a/projects/RabbitMQ.Client/client/impl/Connection.cs +++ b/projects/RabbitMQ.Client/client/impl/Connection.cs @@ -119,6 +119,7 @@ public Connection(IConnectionFactory factory, bool insist, IFrameHandler frameHa public event EventHandler CallbackException; public event EventHandler ConnectionBlocked; + public event EventHandler ConnectionUnblocked; public event EventHandler ConnectionShutdown { @@ -149,10 +150,37 @@ public event EventHandler ConnectionShutdown } } + /// + /// This event is never fired by non-recovering connections but it is a part of the interface. + /// + public event EventHandler RecoverySucceeded { + add { } + remove { } + } + /// + /// This event is never fired by non-recovering connections but it is a part of the interface. + /// + public event EventHandler ConnectionRecoveryError { + add { } + remove { } + } - public event EventHandler ConnectionUnblocked; + /// + /// This event is never fired by non-recovering connections but it is a part of the interface. + /// + public event EventHandler ConsumerTagChangeAfterRecovery { + add { } + remove { } + } + /// + /// This event is never fired by non-recovering connections but it is a part of the interface. + /// + public event EventHandler QueueNameChangeAfterRecovery { + add { } + remove { } + } public string ClientProvidedName { get; } diff --git a/projects/Unit/APIApproval.Approve.verified.txt b/projects/Unit/APIApproval.Approve.verified.txt index 75ceac3259..9400c9a247 100644 --- a/projects/Unit/APIApproval.Approve.verified.txt +++ b/projects/Unit/APIApproval.Approve.verified.txt @@ -231,13 +231,6 @@ namespace RabbitMQ.Client string Name { get; } RabbitMQ.Client.IAuthMechanism GetInstance(); } - public interface IAutorecoveringConnection : RabbitMQ.Client.IConnection, RabbitMQ.Client.INetworkConnection, System.IDisposable - { - event System.EventHandler ConnectionRecoveryError; - event System.EventHandler ConsumerTagChangeAfterRecovery; - event System.EventHandler QueueNameChangeAfterRecovery; - event System.EventHandler RecoverySucceeded; - } public interface IBasicConsumer { RabbitMQ.Client.IModel Model { get; } @@ -316,8 +309,12 @@ namespace RabbitMQ.Client System.Collections.Generic.IList ShutdownReport { get; } event System.EventHandler CallbackException; event System.EventHandler ConnectionBlocked; + event System.EventHandler ConnectionRecoveryError; event System.EventHandler ConnectionShutdown; event System.EventHandler ConnectionUnblocked; + event System.EventHandler ConsumerTagChangeAfterRecovery; + event System.EventHandler QueueNameChangeAfterRecovery; + event System.EventHandler RecoverySucceeded; void Abort(); void Abort(System.TimeSpan timeout); void Abort(ushort reasonCode, string reasonText);