Ejemplo n.º 1
0
        /// <summary>
        /// Executes the notification task
        /// </summary>
        /// <param name="publication">The publication.</param>
        /// <returns></returns>
        public async Task PublishDirect(Publication publication)
        {
            CheckDispose();

            if (publication.HubLocation != _hubLocation)
            {
                throw new RequestedHubMismatchException(string.Format(Strings.Error_HubLocationMismatch, _hubLocation, publication.HubLocation));
            }

            var subscriptions = await _subscriptionStore.GetSubscriptions(publication.Topic);

            var subscriberList = subscriptions.ToList();

            if (!subscriberList.Any())
            {
                return;
            }

            var notifyTasks = subscriberList
                              .Select(sub => Notify(publication, sub, publication.Payload))
                              .ToList();

            // TODO: notify if timeout
            await Task.WhenAll(notifyTasks);

            Debug.WriteLine($"Processed {notifyTasks.Count} notifications.");
        }
Ejemplo n.º 2
0
        public void Publish <TPayload>(string[] topics, Envelope <TPayload> envelope)
        {
            Assert.ArgumentNotNull(envelope, nameof(envelope));
            if (topics == null || topics.Length == 0)
            {
                return;
            }

            var subscriptions = _store.GetSubscriptions <TPayload>(topics);

            foreach (var subscription in subscriptions)
            {
                PublishSubscription(subscription, envelope);
            }
        }