Exemplo n.º 1
0
 public void OnNewNotificationRequest(object?sender, NotificationEventArgs args)
 {
     // Find the subscribers who's subscriptions match the pattern.
     foreach (var matchingSubscriptions in _repository.GetSubscribersToFeed(args.Feed))
     {
         // Tell the requestor about subscribers that are interested in this topic.
         foreach (var subscriber in matchingSubscriptions.Value)
         {
             var message = new ForwardedSubscriptionRequest(
                 subscriber.UserForFeed(args.Feed),
                 subscriber.HostForFeed(args.Feed),
                 subscriber.Id,
                 args.Feed,
                 matchingSubscriptions.Key, true);
             try
             {
                 args.Interactor.SendMessage(message);
             }
             catch (Exception error)
             {
                 _logger.LogDebug(error, "Failed to inform {subscriber} regarding {Message}", message);
             }
         }
     }
 }
Exemplo n.º 2
0
        internal void ForwardSubscription(IInteractor subscriber, SubscriptionRequest subscriptionRequest)
        {
            // Find all the interactors that wish to be notified of subscriptions to this topic.
            var notifiables = _repository.FindNotifiables(subscriptionRequest.Feed);

            if (notifiables == null)
            {
                return;
            }

            var forwardedSubscriptionRequest = new ForwardedSubscriptionRequest(subscriber.User, subscriber.Address, subscriber.Id, subscriptionRequest.Feed, subscriptionRequest.Topic, subscriptionRequest.IsAdd);

            Log.Debug($"Notifying interactors[{string.Join(",", notifiables)}] of subscription {forwardedSubscriptionRequest}");

            // Inform each notifiable interactor of the subscription request.
            foreach (var notifiable in notifiables)
            {
                try
                {
                    notifiable.SendMessage(forwardedSubscriptionRequest);
                }
                catch (Exception exception)
                {
                    Log.Debug($"Failed to notify {notifiable} regarding {forwardedSubscriptionRequest}", exception);
                }
            }
        }
        internal void ForwardSubscription(Interactor subscriber, SubscriptionRequest subscriptionRequest)
        {
            // Find all the interactors that wish to be notified of subscriptions to this topic.
            var notifiables = _repository.FindNotifiables(subscriptionRequest.Feed);

            if (notifiables == null)
            {
                return;
            }

            subscriber.Metrics.ForwardedSubscriptions[subscriptionRequest.Feed].Inc();

            var forwardedSubscriptionRequest = new ForwardedSubscriptionRequest(
                subscriber.UserForFeed(subscriptionRequest.Feed),
                subscriber.HostForFeed(subscriptionRequest.Feed),
                subscriber.Id,
                subscriptionRequest.Feed,
                subscriptionRequest.Topic,
                subscriptionRequest.IsAdd);

            _logger.LogDebug("Notifying interactors[{Interactors}] of subscription {Message}", string.Join(",", notifiables), forwardedSubscriptionRequest);

            // Inform each notifiable interactor of the subscription request.
            foreach (var notifiable in notifiables)
            {
                try
                {
                    notifiable.SendMessage(forwardedSubscriptionRequest);
                }
                catch (Exception error)
                {
                    _logger.LogDebug(error, "Failed to notify {Notifiable} regarding {Message}", notifiable, forwardedSubscriptionRequest);
                }
            }
        }
Exemplo n.º 4
0
 public void TestRemoveForwardedSubscriptionRequest()
 {
     using (var stream = new MemoryStream())
     {
         var source = new ForwardedSubscriptionRequest("USER", "HOST", Guid.NewGuid(), "FOO", "bar", false);
         source.Write(new DataWriter(stream));
         stream.Seek(0, SeekOrigin.Begin);
         var dest = Message.Read(new DataReader(stream));
         Assert.AreEqual(source, dest);
     }
 }
Exemplo n.º 5
0
 private void RaiseOnForwardedSubscriptionRequest(ForwardedSubscriptionRequest message)
 {
     OnForwardedSubscription?.Invoke(
         this,
         new ForwardedSubscriptionEventArgs(
             message.User,
             message.Host,
             message.ClientId,
             message.Feed,
             message.Topic,
             message.IsAdd));
 }
Exemplo n.º 6
0
        public void ForwardSubscription(ForwardedSubscriptionRequest forwardedSubscriptionRequest)
        {
            // Find all the interactors that wish to be notified of subscriptions to this topic.
            var notifiables = _repository.FindNotifiables(forwardedSubscriptionRequest.Feed);

            if (notifiables == null)
            {
                return;
            }

            Log.Debug($"Notifying interactors[{string.Join(",", notifiables)}] of subscription {forwardedSubscriptionRequest}");

            // Inform each notifiable interactor of the subscription request.
            foreach (var notifiable in notifiables)
            {
                notifiable.SendMessage(forwardedSubscriptionRequest);
            }
        }
Exemplo n.º 7
0
 internal void OnNewNotificationRequest(object sender, NotificationEventArgs args)
 {
     // Find the subscribers whoes subscriptions match the pattern.
     foreach (var matchingSubscriptions in _repository.GetSubscribersToFeed(args.Feed))
     {
         // Tell the requestor about subscribers that are interested in this topic.
         foreach (var subscriber in matchingSubscriptions.Value)
         {
             var message = new ForwardedSubscriptionRequest(subscriber.User, subscriber.Address, subscriber.Id, args.Feed, matchingSubscriptions.Key, true);
             try
             {
                 args.Interactor.SendMessage(message);
             }
             catch (Exception exception)
             {
                 Log.Debug($"Failed to inform {subscriber} regarding {message}", exception);
             }
         }
     }
 }