/// <summary> /// Registers this endpoint as a subscriber by creating a subscription for the given topic, setting up /// auto-forwarding from that subscription to this endpoint's input queue /// </summary> public async Task RegisterSubscriber(string topic, string subscriberAddress) { VerifyIsOwnInputQueueAddress(subscriberAddress); topic = _nameFormatter.FormatTopicName(topic); _log.Debug("Registering subscription for topic {topicName}", topic); await _subscriptionExceptionIgnorant.Execute(async() => { var topicDescription = await EnsureTopicExists(topic).ConfigureAwait(false); var messageSender = GetMessageSender(Address); var inputQueuePath = messageSender.Path; var topicPath = topicDescription.Path; var subscription = await GetOrCreateSubscription(topicPath, _subscriptionName).ConfigureAwait(false); // if it looks fine, just skip it if (subscription.ForwardTo == inputQueuePath) { return; } subscription.ForwardTo = inputQueuePath; await _managementClient.UpdateSubscriptionAsync(subscription, _cancellationToken).ConfigureAwait(false); _log.Info("Subscription {subscriptionName} for topic {topicName} successfully registered", _subscriptionName, topic); }, _cancellationToken); }
/// <summary> /// Formats the topic name into a usable name on ASB, normalizing if needed. /// </summary> public string FormatTopicName(string topicName) { return(_innerFormatter.FormatTopicName(_prefix + topicName)); }