static void CloseLink(RequestResponseAmqpLink link) { AmqpSession session = link.SendingLink?.Session; link.Abort(); session?.SafeClose(); }
/// <summary> /// Opens a <see cref="AmqpSession"/> in the connection. /// </summary> /// <param name="sessionSettings">The session settings.</param> /// <returns>A task that returns an AmqpSession on completion.</returns> public async Task <AmqpSession> OpenSessionAsync(AmqpSessionSettings sessionSettings) { AmqpSession session = this.CreateSession(sessionSettings); try { await session.OpenAsync().ConfigureAwait(false); return(session); } catch { session.SafeClose(); throw; } }
async Task <RequestResponseAmqpLink> CreateCbsLinkAsync(TimeSpan timeout) { string address = CbsConstants.CbsAddress; TimeoutHelper timeoutHelper = new TimeoutHelper(timeout); AmqpSession session = null; RequestResponseAmqpLink link = null; Exception lastException = null; while (timeoutHelper.RemainingTime() > TimeSpan.Zero) { try { AmqpSessionSettings sessionSettings = new AmqpSessionSettings() { Properties = new Fields() }; session = this.connection.CreateSession(sessionSettings); await session.OpenAsync(timeoutHelper.RemainingTime()).ConfigureAwait(false); Fields properties = new Fields(); properties.Add(CbsConstants.TimeoutName, (uint)timeoutHelper.RemainingTime().TotalMilliseconds); link = new RequestResponseAmqpLink("cbs", session, address, properties); await link.OpenAsync(timeoutHelper.RemainingTime()).ConfigureAwait(false); AmqpTrace.Provider.AmqpOpenEntitySucceeded(this, link.Name, address); return(link); } catch (Exception exception) { if (this.connection.IsClosing()) { throw new OperationCanceledException("Connection is closing or closed.", exception); } lastException = exception; AmqpTrace.Provider.AmqpOpenEntityFailed(this, this.GetType().Name, address, exception); } await Task.Delay(1000).ConfigureAwait(false); } link?.Abort(); session?.SafeClose(); throw new TimeoutException(AmqpResources.GetString(AmqpResources.AmqpTimeout, timeout, address), lastException); }