Skip to content

Commit c4a62a3

Browse files
Remove re-connection attempts from BrokerUnreachableException
1 parent 31175f2 commit c4a62a3

File tree

3 files changed

+9
-75
lines changed

3 files changed

+9
-75
lines changed

projects/client/RabbitMQ.Client/src/client/api/ConnectionFactory.cs

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -203,36 +203,24 @@ public String Uri
203203
///their respective defaults.</summary>
204204
public ConnectionFactory() { }
205205

206-
///<summary>Create a connection to the specified endpoint
207-
///No broker-originated redirects are permitted.</summary>
206+
///<summary>Create a connection to the specified endpoint.</summary>
208207
public virtual IConnection CreateConnection()
209208
{
210-
IDictionary<AmqpTcpEndpoint, int> attempts = new Dictionary<AmqpTcpEndpoint, int>();
211-
Dictionary<AmqpTcpEndpoint, Exception> errors = new Dictionary<AmqpTcpEndpoint, Exception>();
212-
213209
IConnection conn = null;
214210
try
215211
{
216212
IProtocol p = Protocols.DefaultProtocol;
217213
IFrameHandler fh = p.CreateFrameHandler(Endpoint,
218-
SocketFactory,
219-
RequestedConnectionTimeout);
214+
SocketFactory,
215+
RequestedConnectionTimeout);
220216
conn = p.CreateConnection(this, false, fh);
221-
attempts[Endpoint] = 1;
222217
} catch (Exception e)
223218
{
224219

225-
errors[Endpoint] = e;
220+
throw new BrokerUnreachableException(e);
226221
}
227222

228-
if(conn != null)
229-
{
230-
return conn;
231-
} else
232-
{
233-
Exception cause = errors[Endpoint] as Exception;
234-
throw new BrokerUnreachableException(attempts, errors, cause);
235-
}
223+
return conn;
236224
}
237225

238226
///<summary>Given a list of mechanism names supported by the

projects/client/RabbitMQ.Client/src/client/exceptions/BrokerUnreachableException.cs

Lines changed: 3 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -48,61 +48,11 @@ namespace RabbitMQ.Client.Exceptions {
4848

4949
///<summary>Thrown when no connection could be opened during a
5050
///ConnectionFactory.CreateConnection attempt.</summary>
51-
///<remarks>
52-
/// CreateConnection (optionally) handles redirections, so even a
53-
/// single-endpoint connection attempt may end up attempting to
54-
/// connect to multiple TCP endpoints. This exception contains
55-
/// information on how many times each endpoint was tried, and the
56-
/// outcome of the most recent attempt against each endpoint. See
57-
/// the ConnectionAttempts and ConnectionErrors properties.
58-
///</remarks>
5951
public class BrokerUnreachableException: IOException
6052
{
61-
private IDictionary<AmqpTcpEndpoint, int> m_connectionAttempts;
62-
private IDictionary<AmqpTcpEndpoint, Exception> m_connectionErrors;
63-
64-
///<summary>A map from AmqpTcpEndpoint to int, counting the
65-
///number of attempts that were made against each
66-
///endpoint.</summary>
67-
public IDictionary<AmqpTcpEndpoint, int> ConnectionAttempts { get { return m_connectionAttempts; } }
68-
69-
///<summary>A map from AmqpTcpEndpoint to Exception, recording
70-
///the outcome of the most recent connection attempt against
71-
///each endpoint.</summary>
72-
public IDictionary<AmqpTcpEndpoint, Exception> ConnectionErrors { get { return m_connectionErrors; } }
73-
74-
///<summary>same as ConnectionErrors property</summary>
75-
public override IDictionary Data { get { return new Dictionary<AmqpTcpEndpoint, Exception>(m_connectionErrors); } }
76-
77-
///<summary>Construct a BrokerUnreachableException. Expects
78-
///maps as per the description of the ConnectionAttempts and
79-
///ConnectionErrors properties. The inner exception is associated
53+
///<summary>Construct a BrokerUnreachableException. The inner exception is associated
8054
///with only one connection attempt.</summary>
81-
public BrokerUnreachableException(IDictionary<AmqpTcpEndpoint, int> connectionAttempts,
82-
IDictionary<AmqpTcpEndpoint, Exception> connectionErrors,
83-
Exception Inner)
84-
: base("None of the specified endpoints were reachable", Inner)
85-
{
86-
m_connectionAttempts = connectionAttempts;
87-
m_connectionErrors = connectionErrors;
88-
}
89-
90-
///<summary>Provide a full description of the various
91-
///connection attempts that were made, as well as the usual
92-
///Exception stack trace.</summary>
93-
public override string ToString() {
94-
StringBuilder sb = new StringBuilder(base.Message);
95-
sb.Append("\nEndpoints attempted:\n");
96-
foreach (KeyValuePair<AmqpTcpEndpoint, int> entry in m_connectionAttempts) {
97-
sb.Append("------------------------------------------------\n");
98-
sb.Append("endpoint=").Append(entry.Key);
99-
sb.Append(", attempts=").Append(entry.Value).Append("\n");
100-
sb.Append(m_connectionErrors[entry.Key] as Exception);
101-
}
102-
sb.Append("\n================================================\n");
103-
sb.Append("Stack trace:\n");
104-
sb.Append(base.StackTrace);
105-
return sb.ToString();
106-
}
55+
public BrokerUnreachableException(Exception Inner)
56+
: base("None of the specified endpoints were reachable", Inner) {}
10757
}
10858
}

projects/client/Unit/src/unit/TestAuth.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,7 @@ public void TestAuthFailure()
7070
}
7171
catch (BrokerUnreachableException bue)
7272
{
73-
foreach (Object failureReason in bue.ConnectionErrors.Values)
74-
{
75-
Assert.IsInstanceOf<AuthenticationFailureException>(
76-
failureReason);
77-
}
73+
Assert.IsInstanceOf<AuthenticationFailureException>(bue.InnerException);
7874
}
7975
}
8076
}

0 commit comments

Comments
 (0)