private async Task <(ReceiverLink receiverLink, string address)> CreateReceiverLink(CancellationToken cancellationToken) { var tcs = TaskUtil.CreateTaskCompletionSource <string>(cancellationToken); var receiverLink = new ReceiverLink(_session, Guid.NewGuid().ToString(), new Source { Dynamic = true }, OnAttached); receiverLink.AddClosedCallback(OnClosed); var address = await tcs.Task.ConfigureAwait(false); receiverLink.Closed -= OnClosed; return(receiverLink, address); void OnAttached(ILink link, Attach attach) { if (attach != null && attach.Source is Source source) { tcs.TrySetResult(source.Address); } } void OnClosed(IAmqpObject sender, Error error) { if (error != null) { tcs.TrySetException(new CreateRpcClientException(error.Description, error.Condition)); } } }
public Task Attach() { Target target = new Target(); Source source = CreateSource(); Attach attach = new Attach { Target = target, Source = source, RcvSettleMode = ReceiverSettleMode.First, SndSettleMode = (info.IsBrowser) ? SenderSettleMode.Settled : SenderSettleMode.Unsettled, }; string name; if (info.IsDurable) { name = info.SubscriptionName; } else { string destinationAddress = source.Address ?? ""; name = "nms:receiver:" + info.Id + (destinationAddress.Length == 0 ? "" : (":" + destinationAddress)); } // TODO: Add timeout var tsc = new TaskCompletionSource <bool>(TaskCreationOptions.RunContinuationsAsynchronously); receiverLink = new ReceiverLink(session.UnderlyingSession, name, attach, HandleOpened(tsc)); receiverLink.AddClosedCallback(HandleClosed(tsc)); return(tsc.Task); }
public Task Attach() { Target target = new Target(); Source source = CreateSource(); Attach attach = new Attach { Target = target, Source = source, RcvSettleMode = ReceiverSettleMode.First, SndSettleMode = (info.IsBrowser) ? SenderSettleMode.Settled : SenderSettleMode.Unsettled, }; string name; if (info.IsDurable) { name = info.SubscriptionName; } else { string destinationAddress = source.Address ?? ""; name = "nms:receiver:" + info.Id + (destinationAddress.Length == 0 ? "" : (":" + destinationAddress)); } var taskCompletionSource = new TaskCompletionSource <bool>(TaskCreationOptions.RunContinuationsAsynchronously); link = new ReceiverLink(session.UnderlyingSession, name, attach, (link1, attach1) => { taskCompletionSource.SetResult(true); }); link.AddClosedCallback((sender, error) => { NMSException exception = ExceptionSupport.GetException(error, "Received Amqp link detach with Error for link {0}", info.Id); if (!taskCompletionSource.TrySetException(exception)) { session.RemoveConsumer(info.Id); // If session is not closed it means that the link was remotely detached if (!link.Session.IsClosed) { session.Connection.Provider.FireResourceClosed(info, exception); } } }); return(taskCompletionSource.Task); }
public async Task <IConsumer> CreateAsync(ConsumerConfiguration configuration, CancellationToken cancellationToken) { CheckConfiguration(configuration); cancellationToken.ThrowIfCancellationRequested(); cancellationToken.Register(() => _tcs.TrySetCanceled()); var source = new Source { Address = GetAddress(configuration), Capabilities = GetCapabilities(configuration), FilterSet = GetFilterSet(configuration.FilterExpression, configuration.NoLocalFilter), }; var receiverLink = new ReceiverLink(_session, Guid.NewGuid().ToString(), source, OnAttached); receiverLink.AddClosedCallback(OnClosed); await _tcs.Task.ConfigureAwait(false); receiverLink.Closed -= OnClosed; return(new Consumer(_loggerFactory, receiverLink, _transactionsManager, configuration)); }
public Task Attach() { Target target = new Target(); Source source = CreateSource(); Attach attach = new Attach { Target = target, Source = source, RcvSettleMode = ReceiverSettleMode.First, SndSettleMode = (info.IsBrowser) ? SenderSettleMode.Settled : SenderSettleMode.Unsettled, }; string receiverLinkName = null; string subscriptionName = info.SubscriptionName; if (!string.IsNullOrEmpty(subscriptionName)) { AmqpConnection connection = session.Connection; if (info.IsShared && !connection.Info.SharedSubsSupported) { validateSharedSubsLinkCapability = true; } AmqpSubscriptionTracker subTracker = connection.SubscriptionTracker; // Validate subscriber type allowed given existing active subscriber types. if (info.IsShared && info.IsDurable) { if (subTracker.IsActiveExclusiveDurableSub(subscriptionName)) { // Don't allow shared sub if there is already an active exclusive durable sub throw new NMSException("A non-shared durable subscription is already active with name '" + subscriptionName + "'"); } } else if (!info.IsShared && info.IsDurable) { if (subTracker.IsActiveExclusiveDurableSub(subscriptionName)) { // Exclusive durable sub is already active throw new NMSException("A non-shared durable subscription is already active with name '" + subscriptionName + "'"); } else if (subTracker.IsActiveSharedDurableSub(subscriptionName)) { // Don't allow exclusive durable sub if there is already an active shared durable sub throw new NMSException("A shared durable subscription is already active with name '" + subscriptionName + "'"); } } // Get the link name for the subscription. Throws if certain further validations fail. receiverLinkName = subTracker.ReserveNextSubscriptionLinkName(subscriptionName, info); } if (receiverLinkName == null) { string destinationAddress = source.Address ?? ""; receiverLinkName = "nms:receiver:" + info.Id + (destinationAddress.Length == 0 ? "" : (":" + destinationAddress)); } // TODO: Add timeout var tsc = new TaskCompletionSource <bool>(TaskCreationOptions.RunContinuationsAsynchronously); receiverLink = new ReceiverLink(session.UnderlyingSession, receiverLinkName, attach, HandleOpened(tsc)); receiverLink.AddClosedCallback(HandleClosed(tsc)); return(tsc.Task); }