Esempio n. 1
0
        public void Subscribe_SubscriptionsAreProvided_EventTypesAreAdjustedAndSubscriptionsAreApplied()
        {
            //prepare

            var mockSubscriber = new Mock <ISubscriber>();

            IDictionary <string, ISubscription> actualSubscriptions = null;

            mockSubscriber.Setup(x => x.Subscribe(It.IsAny <IDictionary <string, ISubscription> >()))
            .Callback <IDictionary <string, ISubscription> > (
                (subscriptions) => { actualSubscriptions = subscriptions; });

            var mockModelNamingConventionController = new Mock <IModelNamingConventionController>();

            mockModelNamingConventionController.Setup(x => x.GetDeadLetterQueueMessageEventType(It.IsAny <string>()))
            .Returns((string subscriberName) => string.Concat("deadletter.", subscriberName));
            mockModelNamingConventionController.Setup(x => x.GetTrackingMessageEventType(It.IsAny <string>()))
            .Returns((string originalEventType) => string.Concat("ok.", originalEventType));
            IModelNamingConventionController defaultNamingConvensionController = mockModelNamingConventionController.Object;

            DefaultTracker tracker = new DefaultTracker(mockSubscriber.Object, defaultNamingConvensionController);

            //act
            IDictionary <string, ISubscription> successfulProcessingSubscriptions = new Dictionary <string, ISubscription>();
            IDictionary <string, ISubscription> failedProcessingSubscriptions     = new Dictionary <string, ISubscription>();

            string eventType1 = "eventType1";
            string eventType2 = "eventType2";

            var mockEventType1SuccessfulSubscription = new Mock <ISubscription>();
            var mockEventType2SuccessfulSubscription = new Mock <ISubscription>();
            var mockEventType1FailedSubscription     = new Mock <ISubscription>();
            var mockEventType2FailedfulSubscription  = new Mock <ISubscription>();

            successfulProcessingSubscriptions.Add(eventType1, mockEventType1SuccessfulSubscription.Object);
            successfulProcessingSubscriptions.Add(eventType2, mockEventType2SuccessfulSubscription.Object);

            failedProcessingSubscriptions.Add(eventType1, mockEventType1FailedSubscription.Object);
            failedProcessingSubscriptions.Add(eventType2, mockEventType2FailedfulSubscription.Object);

            tracker.Subscribe(successfulProcessingSubscriptions, failedProcessingSubscriptions);

            //check
            IDictionary <string, ISubscription> expecteEffectiveSubscriptions = new Dictionary <string, ISubscription>();

            expecteEffectiveSubscriptions.Add(defaultNamingConvensionController.GetTrackingMessageEventType(eventType1),
                                              mockEventType1SuccessfulSubscription.Object);
            expecteEffectiveSubscriptions.Add(defaultNamingConvensionController.GetTrackingMessageEventType(eventType2),
                                              mockEventType2SuccessfulSubscription.Object);

            expecteEffectiveSubscriptions.Add(defaultNamingConvensionController.GetDeadLetterQueueMessageEventType(eventType1),
                                              mockEventType1FailedSubscription.Object);
            expecteEffectiveSubscriptions.Add(defaultNamingConvensionController.GetDeadLetterQueueMessageEventType(eventType2),
                                              mockEventType2FailedfulSubscription.Object);

            expecteEffectiveSubscriptions.ShouldBeEquivalentTo(actualSubscriptions);
        }
Esempio n. 2
0
        private async Task SendMessageToDeadLetterQueueAsync(MessageExecutionContext messageExecutionContext,
                                                             int retrycount)
        {
            IntegrationEvent <JObject> integrationEvent = null;

            if (!string.IsNullOrEmpty(messageExecutionContext.SerializedMessage))
            {
                integrationEvent = JsonConvert.DeserializeObject <IntegrationEvent <JObject> >(messageExecutionContext.SerializedMessage);
            }

            var deadLetterEventDescriptor =
                new DeadLetterEventDescriptor <JObject>
            {
                CountOfAttempts  = retrycount,
                LastAttemptError = messageExecutionContext.Exception.ToString(),
                Original         = integrationEvent
            };

            messageExecutionContext.DeadLetterIntegrationEvent = new IntegrationEvent <DeadLetterEventDescriptor <JObject> >
            {
                EventType = _modelNamingConventionController.GetDeadLetterQueueMessageEventType(
                    integrationEvent?.EventType),
                Content = deadLetterEventDescriptor
            };

            await _failedExecutionHandler(messageExecutionContext);
        }
 public TrackingEventsSubscriptionSelector(IModelNamingConventionController modelNamingConventionController)
 {
     _modelNamingConventionController        = modelNamingConventionController;
     _defaultTrackingMessageEventType        = _modelNamingConventionController.GetTrackingMessageEventType("*");
     _defaultDeadLetterQueueMessageEventType =
         _modelNamingConventionController.GetDeadLetterQueueMessageEventType("*");
 }
        public void Subscribe(IDictionary <string, ISubscription> deadletterSubscriptions)
        {
            //We have to look through all the subscriptions and change the event types according the conversion
            IDictionary <string, ISubscription> finalSubscriptionDictionary = new Dictionary <string, ISubscription>();

            foreach (var deadletterSubscription in deadletterSubscriptions)
            {
                finalSubscriptionDictionary.Add(
                    _modelNamingConventionController.GetDeadLetterQueueMessageEventType(deadletterSubscription.Key),
                    new DeadLetterSubscriptionWrapper(deadletterSubscription.Value, _publisher, _targetSubscriberDeadLetterQueueName));
            }

            _subscriber.Subscribe(finalSubscriptionDictionary);
        }
Esempio n. 5
0
        public void Subscribe(IDictionary <string, ISubscription> succesfulMessagesSubscriptions,
                              IDictionary <string, ISubscription> failedMessagesSubscriptions)
        {
            //We have to look through all the subscriptions and change the event types according the conversion
            IDictionary <string, ISubscription> finalSubscriptionDictionary = new Dictionary <string, ISubscription>();

            foreach (var failedMessagesSubscription in failedMessagesSubscriptions)
            {
                finalSubscriptionDictionary.Add(
                    _modelNamingConventionController.GetDeadLetterQueueMessageEventType(failedMessagesSubscription.Key), failedMessagesSubscription.Value);
            }

            foreach (var succesfulMessagesSubscription in succesfulMessagesSubscriptions)
            {
                finalSubscriptionDictionary.Add(
                    _modelNamingConventionController.GetTrackingMessageEventType(succesfulMessagesSubscription.Key), succesfulMessagesSubscription.Value);
            }

            _subscriber.Subscribe(finalSubscriptionDictionary);
        }