Skip to content

Commit

Permalink
Fold IAutorecoveringConnection [back] into IConnection
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
michaelklishin committed Sep 17, 2020
1 parent 52979d9 commit 22133d2
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 62 deletions.
53 changes: 0 additions & 53 deletions projects/RabbitMQ.Client/client/api/IAutorecoveringConnection.cs

This file was deleted.

37 changes: 37 additions & 0 deletions projects/RabbitMQ.Client/client/api/IConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,43 @@ public interface IConnection : INetworkConnection, IDisposable
/// </remarks>
event EventHandler<ShutdownEventArgs> ConnectionShutdown;

/// <summary>
/// Raised when the connection completes recovery.
/// </summary>
/// <remarks>
/// This event will never fire for connections that disable automatic recovery.
/// </remarks>
event EventHandler<EventArgs> RecoverySucceeded;

/// <summary>
/// Raised when the connection recovery fails, e.g. because reconnection or topology
/// recovery failed.
/// </summary>
/// <remarks>
/// This event will never fire for connections that disable automatic recovery.
/// </remarks>
event EventHandler<ConnectionRecoveryErrorEventArgs> ConnectionRecoveryError;

/// <summary>
/// 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.
/// </summary>
/// <remarks>
/// This event will never fire for connections that disable automatic recovery.
/// </remarks>
event EventHandler<ConsumerTagChangedAfterRecoveryEventArgs> ConsumerTagChangeAfterRecovery;

/// <summary>
/// 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.
/// </summary>
/// <remarks>
/// This event will never fire for connections that disable automatic recovery.
/// </remarks>
event EventHandler<QueueNameChangedAfterRecoveryEventArgs> QueueNameChangeAfterRecovery;

event EventHandler<EventArgs> ConnectionUnblocked;

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
30 changes: 29 additions & 1 deletion projects/RabbitMQ.Client/client/impl/Connection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ public Connection(IConnectionFactory factory, bool insist, IFrameHandler frameHa
public event EventHandler<CallbackExceptionEventArgs> CallbackException;

public event EventHandler<ConnectionBlockedEventArgs> ConnectionBlocked;
public event EventHandler<EventArgs> ConnectionUnblocked;

public event EventHandler<ShutdownEventArgs> ConnectionShutdown
{
Expand Down Expand Up @@ -149,10 +150,37 @@ public event EventHandler<ShutdownEventArgs> ConnectionShutdown
}
}

/// <summary>
/// This event is never fired by non-recovering connections but it is a part of the <see cref="IConnection"/> interface.
/// </summary>
public event EventHandler<EventArgs> RecoverySucceeded {
add { }
remove { }
}

/// <summary>
/// This event is never fired by non-recovering connections but it is a part of the <see cref="IConnection"/> interface.
/// </summary>
public event EventHandler<ConnectionRecoveryErrorEventArgs> ConnectionRecoveryError {
add { }
remove { }
}

public event EventHandler<EventArgs> ConnectionUnblocked;
/// <summary>
/// This event is never fired by non-recovering connections but it is a part of the <see cref="IConnection"/> interface.
/// </summary>
public event EventHandler<ConsumerTagChangedAfterRecoveryEventArgs> ConsumerTagChangeAfterRecovery {
add { }
remove { }
}

/// <summary>
/// This event is never fired by non-recovering connections but it is a part of the <see cref="IConnection"/> interface.
/// </summary>
public event EventHandler<QueueNameChangedAfterRecoveryEventArgs> QueueNameChangeAfterRecovery {
add { }
remove { }
}

public string ClientProvidedName { get; }

Expand Down
11 changes: 4 additions & 7 deletions projects/Unit/APIApproval.Approve.verified.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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<RabbitMQ.Client.Events.ConnectionRecoveryErrorEventArgs> ConnectionRecoveryError;
event System.EventHandler<RabbitMQ.Client.Events.ConsumerTagChangedAfterRecoveryEventArgs> ConsumerTagChangeAfterRecovery;
event System.EventHandler<RabbitMQ.Client.Events.QueueNameChangedAfterRecoveryEventArgs> QueueNameChangeAfterRecovery;
event System.EventHandler<System.EventArgs> RecoverySucceeded;
}
public interface IBasicConsumer
{
RabbitMQ.Client.IModel Model { get; }
Expand Down Expand Up @@ -316,8 +309,12 @@ namespace RabbitMQ.Client
System.Collections.Generic.IList<RabbitMQ.Client.ShutdownReportEntry> ShutdownReport { get; }
event System.EventHandler<RabbitMQ.Client.Events.CallbackExceptionEventArgs> CallbackException;
event System.EventHandler<RabbitMQ.Client.Events.ConnectionBlockedEventArgs> ConnectionBlocked;
event System.EventHandler<RabbitMQ.Client.Events.ConnectionRecoveryErrorEventArgs> ConnectionRecoveryError;
event System.EventHandler<RabbitMQ.Client.ShutdownEventArgs> ConnectionShutdown;
event System.EventHandler<System.EventArgs> ConnectionUnblocked;
event System.EventHandler<RabbitMQ.Client.Events.ConsumerTagChangedAfterRecoveryEventArgs> ConsumerTagChangeAfterRecovery;
event System.EventHandler<RabbitMQ.Client.Events.QueueNameChangedAfterRecoveryEventArgs> QueueNameChangeAfterRecovery;
event System.EventHandler<System.EventArgs> RecoverySucceeded;
void Abort();
void Abort(System.TimeSpan timeout);
void Abort(ushort reasonCode, string reasonText);
Expand Down

0 comments on commit 22133d2

Please sign in to comment.