public CancellationTokenSource Start(SubscriptionInfo subscriptionInfo, Action<Message> messageHandler)
        {
            Validate.That(subscriptionInfo).IsNotNull();

            var source = new CancellationTokenSource();
            Task.Factory.StartNew(o =>
                                      {
                                          while (!source.Token.IsCancellationRequested)
                                          {
                                              foreach (var message in amazonFacade.ReadQueue(subscriptionInfo.Subscriber.QueueUrl))
                                              {
                                                  if (messageHandler != null && subscriptionInfo.IsSubscribed)
                                                  {
                                                      messageHandler(message);
                                                  }
                                                  amazonFacade.DeleteMessage(subscriptionInfo.Subscriber.QueueUrl,
                                                                             message.ReceiptHandle);
                                              }
                                          }
                                      }, source.Token);
            return source;
        }
 private SubscriptionInfo UpdateSubscription(SubscriptionInfo subscriptionInfo, Action<Message> messageHandler)
 {
     if (subscriptionInfo.IsSubscribed)
     {
         return subscriptionInfo;
     }
     subscriptionInfo.SubscriptionArn = amazonSnsFacade.SubscribeQueueToTopic(subscriptionInfo.Subscriber.QueueArn, subscriptionInfo.Topic.TopicArn);
     subscriptionInfo.CancelToken = queuePoller.Start(subscriptionInfo, messageHandler);
     return subscriptionInfo;
 }
        private SubscriptionInfo AddSubscription(Topic topic, Subscriber subscriber, Action<Message> messageHandler)
        {
            var subscriptionInfo = new SubscriptionInfo
            {
                Topic=topic,
                Subscriber=subscriber
            };

            amazonSqsFacade.SetSqsPolicyForSnsPublish(subscriber.QueueUrl, subscriber.QueueArn, topic.TopicArn);
            subscriptionInfo.SubscriptionArn = amazonSnsFacade.SubscribeQueueToTopic(subscriptionInfo.Subscriber.QueueArn, subscriptionInfo.Topic.TopicArn);
            if (subscriptionInfo.Subscriber.LongLived)
            {
                resourceCounter.Increment(subscriptionInfo.Subscriber.Name);
            }
            subscriptionInfo.CancelToken = queuePoller.Start(subscriptionInfo, messageHandler);

            return subscriptionInfo;

        }