public void SetUp()
        {
            feedChainFactory = new Mock<IFeedChainFactory>();
            syndication = new Mock<ISyndicationFormatter>();
            messageReceivedHandler = new Mock<EventHandler<Message>>(MockBehavior.Strict);
            _persistance = new Mock<ISubscriptionPersistance>();

            target = new EventFeedObserver(new Uri("https://feeds.sample.com/"), syndication.Object, feedChainFactory.Object, _persistance.Object);
            target.EventReceived += messageReceivedHandler.Object;
        }
예제 #2
0
        public static IEventFeedSubscription AsASubscriber(string endpoint, string connectionStringName, Type[] eventTypes, Type[] handlerTypes)
        {
            var handlerCollection = new HandlerCollection();
            handlerCollection.AddRange(handlerTypes);

            var deserializer = new SimpleXmlMessageSerializaion { MessageTypes = eventTypes };

            var subscriberPersistance = new Subscriber.Persistance.SqlPersistance(connectionStringName);

            var failureChannel = new FailureChannel(subscriberPersistance)
            {
                PollingInterval = new TimeSpan(0, 1, 0)
            };

            var processingChannel = new ProcessingChannel(deserializer, handlerCollection);

            var subscription = new EventFeedObserver(new Uri(endpoint), new AtomFormatter(), new FeedChainFactory(), subscriberPersistance)
            {
                PollingInterval = new TimeSpan(0, 1, 0)
            };

            //deadletter messages when they fail
            processingChannel.MessageFailed += (sender, args) => failureChannel.DeadLetter(args.Message, args.Exception);

            //process messages in handlers when they're picked up from the feed
            subscription.EventReceived += processingChannel.ProcessEvent;

            //process failed messages again when they're reader
            failureChannel.MessageReadyForRetry += processingChannel.ProcessEvent;

            //remove failed messages once they're successfully processed
            processingChannel.MessageProcessed += (sender, message) => failureChannel.ClearFailure(message);

            failureChannel.Poll();

            return subscription;
        }