Skip to content

Commit 31175f2

Browse files
merge default into bug26133
2 parents 269a499 + 65a3848 commit 31175f2

File tree

3 files changed

+22
-121
lines changed

3 files changed

+22
-121
lines changed

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

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

206-
protected virtual IConnection FollowRedirectChain
207-
(int maxRedirects,
208-
IDictionary<AmqpTcpEndpoint, int> connectionAttempts,
209-
IDictionary<AmqpTcpEndpoint, Exception> connectionErrors,
210-
ref AmqpTcpEndpoint[] mostRecentKnownHosts,
211-
AmqpTcpEndpoint endpoint)
206+
///<summary>Create a connection to the specified endpoint
207+
///No broker-originated redirects are permitted.</summary>
208+
public virtual IConnection CreateConnection()
212209
{
213-
AmqpTcpEndpoint candidate = endpoint;
214-
try {
215-
while (true) {
216-
int attemptCount =
217-
connectionAttempts.ContainsKey(candidate)
218-
? (int) connectionAttempts[candidate]
219-
: 0;
220-
connectionAttempts[candidate] = attemptCount + 1;
221-
bool insist = attemptCount >= maxRedirects;
222-
223-
IProtocol p = Protocol;
224-
IFrameHandler fh = p.CreateFrameHandler(candidate,
225-
SocketFactory,
226-
RequestedConnectionTimeout);
227-
228-
// At this point, we may be able to create
229-
// and fully open a successful connection,
230-
// in which case we're done, and the
231-
// connection should be returned.
232-
return p.CreateConnection(this, insist, fh);
233-
}
234-
} catch (Exception e) {
235-
connectionErrors[candidate] = e;
236-
return null;
237-
}
238-
}
210+
IDictionary<AmqpTcpEndpoint, int> attempts = new Dictionary<AmqpTcpEndpoint, int>();
211+
Dictionary<AmqpTcpEndpoint, Exception> errors = new Dictionary<AmqpTcpEndpoint, Exception>();
239212

240-
protected virtual IConnection CreateConnection(int maxRedirects,
241-
IDictionary<AmqpTcpEndpoint, int> connectionAttempts,
242-
IDictionary<AmqpTcpEndpoint, Exception> connectionErrors,
243-
params AmqpTcpEndpoint[] endpoints)
244-
{
245-
foreach (AmqpTcpEndpoint endpoint in endpoints)
213+
IConnection conn = null;
214+
try
215+
{
216+
IProtocol p = Protocols.DefaultProtocol;
217+
IFrameHandler fh = p.CreateFrameHandler(Endpoint,
218+
SocketFactory,
219+
RequestedConnectionTimeout);
220+
conn = p.CreateConnection(this, false, fh);
221+
attempts[Endpoint] = 1;
222+
} catch (Exception e)
246223
{
247-
AmqpTcpEndpoint[] mostRecentKnownHosts = new AmqpTcpEndpoint[0];
248-
// ^^ holds a list of known-hosts that came back with
249-
// a connection.redirect. If, once we reach the end of
250-
// a chain of redirects, we still haven't managed to
251-
// get a usable connection, we recurse on
252-
// mostRecentKnownHosts, trying each of those in
253-
// turn. Finally, if neither the initial
254-
// chain-of-redirects for the current endpoint, nor
255-
// the chains-of-redirects for each of the
256-
// mostRecentKnownHosts gives us a usable connection,
257-
// we give up on this particular endpoint, and
258-
// continue with the foreach loop, trying the
259-
// remainder of the array we were given.
260-
IConnection conn = FollowRedirectChain(maxRedirects,
261-
connectionAttempts,
262-
connectionErrors,
263-
ref mostRecentKnownHosts,
264-
endpoint);
265-
if (conn != null) {
266-
return conn;
267-
}
268224

269-
// Connection to this endpoint failed at some point
270-
// down the redirection chain - either the first
271-
// entry, or one of the re.Host values from subsequent
272-
// RedirectExceptions. We recurse into
273-
// mostRecentKnownHosts, to see if one of those is
274-
// suitable.
275-
if (mostRecentKnownHosts.Length > 0) {
276-
// Only bother recursing if we know of some
277-
// hosts. If we were to recurse with no endpoints
278-
// in the array, we'd stomp on
279-
// mostRecentException, which makes debugging
280-
// connectivity problems needlessly more
281-
// difficult.
282-
conn = CreateConnection(maxRedirects,
283-
connectionAttempts,
284-
connectionErrors,
285-
mostRecentKnownHosts);
286-
if (conn != null) {
287-
return conn;
288-
}
289-
}
225+
errors[Endpoint] = e;
290226
}
291-
return null;
292-
}
293227

294-
///<summary>Create a connection to the first available
295-
///endpoint in the list provided. Up to a maximum of
296-
///maxRedirects broker-originated redirects are permitted for
297-
///each endpoint tried.</summary>
298-
public virtual IConnection CreateConnection(int maxRedirects)
299-
{
300-
IDictionary<AmqpTcpEndpoint, int> connectionAttempts = new Dictionary<AmqpTcpEndpoint, int>();
301-
Dictionary<AmqpTcpEndpoint, Exception> connectionErrors = new Dictionary<AmqpTcpEndpoint, Exception>();
302-
IConnection conn = CreateConnection(maxRedirects,
303-
connectionAttempts,
304-
connectionErrors,
305-
new AmqpTcpEndpoint[]{Endpoint});
306-
if (conn != null) {
228+
if(conn != null)
229+
{
307230
return conn;
231+
} else
232+
{
233+
Exception cause = errors[Endpoint] as Exception;
234+
throw new BrokerUnreachableException(attempts, errors, cause);
308235
}
309-
Exception Inner = connectionErrors[Endpoint] as Exception;
310-
throw new BrokerUnreachableException(connectionAttempts, connectionErrors, Inner);
311-
}
312-
313-
///<summary>Create a connection to the specified endpoint
314-
///No broker-originated redirects are permitted.</summary>
315-
public virtual IConnection CreateConnection()
316-
{
317-
return CreateConnection(0);
318236
}
319237

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

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -928,13 +928,6 @@ void _Private_ConnectionOpen(string virtualHost,
928928
void HandleConnectionOpenOk([AmqpFieldMapping("RabbitMQ.Client.Framing.v0_9_1", "reserved1")]
929929
string knownHosts);
930930

931-
///<summary>Handle an incoming Connection.Redirect.
932-
/// (not available in AMQP 0-9-1)
933-
///</summary>
934-
[AmqpMethodDoNotImplement("RabbitMQ.Client.Framing.v0_9_1")]
935-
void HandleConnectionRedirect(string host,
936-
string knownHosts);
937-
938931
///<summary>Used to send a Connection.Close. Called during
939932
///connection shutdown.</summary>
940933
[AmqpMethodMapping(null, "connection", "close")]

projects/client/RabbitMQ.Client/src/client/impl/ModelBase.cs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1507,16 +1507,6 @@ public void HandleConnectionOpenOk(string knownHosts)
15071507
k.HandleCommand(null); // release the continuation.
15081508
}
15091509

1510-
public void HandleConnectionRedirect(string host,
1511-
string knownHosts)
1512-
{
1513-
ConnectionOpenContinuation k = (ConnectionOpenContinuation)m_continuationQueue.Next();
1514-
k.m_redirect = true;
1515-
k.m_host = host;
1516-
k.m_knownHosts = knownHosts;
1517-
k.HandleCommand(null); // release the continuation.
1518-
}
1519-
15201510
public abstract void _Private_ConnectionClose(ushort replyCode,
15211511
string replyText,
15221512
ushort classId,

0 commit comments

Comments
 (0)