コード例 #1
0
        public void SetUp()
        {
            _deserializer = new Mock<IMessageDeserializer>();
            _handlers = new Mock<IHandler<object>>();
            _messageFailedHandler = new Mock<EventHandler<MessageFailedEventArgs>>(MockBehavior.Strict);
            target = new ProcessingChannel(_deserializer.Object, _handlers.Object);

            target.MessageFailed += _messageFailedHandler.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;
        }