Пример #1
0
        private void SubscribeInstanceSubscription(InstanceSubscriptionInformation information)
        {
            foreach (var message in information.ConsumedMessages)
            {
                bool subscribed = false;
                foreach (var owner in messageOwners.Of(message))
                {
                    logger.DebugFormat("Instance subscribition for {0} on {1}",
                                       message.FullName,
                                       owner.Endpoint);

                    subscribed = true;
                    var endpoint = endpointRouter.GetRoutedEndpoint(owner.Endpoint);
                    endpoint.Transactional = owner.Transactional;
                    Send(endpoint, new AddInstanceSubscription
                    {
                        Endpoint = Endpoint.Uri.ToString(),
                        Type     = message.FullName,
                        InstanceSubscriptionKey = information.InstanceSubscriptionKey
                    });
                }
                if (subscribed == false)
                {
                    throw new SubscriptionException("Could not find any owner for message " + message +
                                                    " that we could subscribe for");
                }
            }
        }
Пример #2
0
 public void UnsubscribeInstanceSubscription(InstanceSubscriptionInformation information)
 {
     foreach (var message in information.ConsumedMessages)
     {
         foreach (var owner in messageOwners.Of(message))
         {
             var endpoint = endpointRouter.GetRoutedEndpoint(owner.Endpoint);
             endpoint.Transactional = owner.Transactional;
             Send(endpoint, new RemoveInstanceSubscription
             {
                 Endpoint = Endpoint.Uri.ToString(),
                 Type     = message.FullName,
                 InstanceSubscriptionKey = information.InstanceSubscriptionKey
             });
         }
     }
 }
Пример #3
0
        public IDisposable AddInstanceSubscription(IMessageConsumer consumer)
        {
            var information = new InstanceSubscriptionInformation
            {
                Consumer = consumer,
                InstanceSubscriptionKey = Guid.NewGuid(),
                ConsumedMessages        = reflection.GetMessagesConsumed(consumer),
            };

            subscriptionStorage.AddLocalInstanceSubscription(consumer);
            SubscribeInstanceSubscription(information);

            return(new DisposableAction(() =>
            {
                subscriptionStorage.RemoveLocalInstanceSubscription(information.Consumer);
                UnsubscribeInstanceSubscription(information);
                information.Dispose();
            }));
        }