Beispiel #1
0
        private async Task PublishInternalAsync(PipelineEvent pipelineEvent, IEnumerable <Subscription> subscriptions)
        {
            _logger.PublishingEvent(pipelineEvent);

            var eventsSubscriptions = _subscriptionsMatchingService
                                      .GetMatchingSubscriptionsForEvent(subscriptions, pipelineEvent.Event);

            var exceptions = new List <Exception>();

            foreach (var eventsSubscription in eventsSubscriptions)
            {
                var exception = await eventsSubscription.PublishEventAsync(pipelineEvent).ConfigureAwait(false);

                if (exception != null)
                {
                    exceptions.Add(exception);
                    _logger.EventHandlerThrew(exception);
                }
            }

            if (exceptions.Any())
            {
                throw new SubscriptionPublishAggregateException(exceptions);
            }
        }
Beispiel #2
0
        public void SetUp()
        {
            _eventsQueue = new EventsQueue(_eventsQueueName);
            var pipelineEvent = new PipelineEvent(new object());

            _queuedPipelineEvent = new QueuedPipelineEvent(() => Task.CompletedTask);
        }
Beispiel #3
0
        public bool IsSatisfiedBy(PipelineEvent pipelineEvent)
        {
            Guard.AgainstNull(pipelineEvent, "pipelineEvent");

            return(_assessors.All(assessor => assessor.Invoke(pipelineEvent))
                   &&
                   _specifications.All(specification => specification.IsSatisfiedBy(pipelineEvent)));
        }
Beispiel #4
0
 public DeserializationExceptionEventArgs(PipelineEvent pipelineEvent, IQueue workQueue, IQueue errorQueue,
                                          Exception exception)
     : base(pipelineEvent)
 {
     WorkQueue  = workQueue;
     ErrorQueue = errorQueue;
     Exception  = exception;
 }
        public void PublishEventAsync_WithEventTypeMismatch_ShouldThrow()
        {
            var pipelineEvent = new PipelineEvent(123);

            Assert.That(async() =>
            {
                await _subscription.PublishEventAsync(pipelineEvent);
            }, Throws.TypeOf <EventTypeMismatchException>());
        }
Beispiel #6
0
        public void SetUp()
        {
            _originalEvent = new TestEvent
            {
                Property1 = 20
            };
            _pipelineEvent = new PipelineEvent(_originalEvent);

            _jsonEventsSerializationService = new JsonEventsSerializationService();
        }
        public void SetUp()
        {
            _pipelineEvent = new PipelineEvent(new TestEvent());

            _subscription      = new Subscription(typeof(TestEvent), new Action <object>(HandlerAction));
            _asyncSubscription = new Subscription(typeof(TestEvent), new Func <object, Task>(HandlerActionAsync));

            _isThrowingEnabled  = false;
            _handlerActionEvent = null;
        }
 public HandlerExceptionEventArgs(PipelineEvent pipelineEvent,
                                  TransportMessage transportMessage, object message, IQueue workQueue,
                                  IQueue errorQueue, Exception exception)
     : base(pipelineEvent)
 {
     TransportMessage = transportMessage;
     Message          = message;
     WorkQueue        = workQueue;
     ErrorQueue       = errorQueue;
     Exception        = exception;
 }
Beispiel #9
0
        public Task PublishEventToScopedSubscriptionsAsync(PipelineEvent pipelineEvent, IEventsScope eventsScope)
        {
            if (eventsScope == null)
            {
                throw new ArgumentNullException(nameof(eventsScope));
            }

            var subscriptions = eventsScope.GetSubscriptionsFeature().GetSubscriptions(_scopedSubscriptionsService);

            return(PublishInternalAsync(pipelineEvent, subscriptions));
        }
 private void DisposeDatabaseContext(PipelineEvent pipelineEvent)
 {
     if (_projectionConfiguration.IsSharedConnection)
     {
         pipelineEvent.Pipeline.State.Get <IDatabaseContext>().AttemptDispose();
     }
     else
     {
         pipelineEvent.Pipeline.State.Get <IDatabaseContext>("EventProjectionDatabaseContext").AttemptDispose();
         pipelineEvent.Pipeline.State.Get <IDatabaseContext>("EventStoreDatabaseContext").AttemptDispose();
     }
 }
Beispiel #11
0
        public async Task SendAsync(PipelineEvent pipelineEvent)
        {
            var serializedEvent = _eventsSerializationService.SerializeEvent(pipelineEvent);
            var message         = new Message(serializedEvent)
            {
                MessageId = Guid.NewGuid().ToString()
            };

            await _topicClient.SendAsync(message).ConfigureAwait(false);

            _logger.MessageSent(message.MessageId);
        }
Beispiel #12
0
		public MessageHandlerInvokeResult Invoke(PipelineEvent pipelineEvent)
		{
			var messageType = pipelineEvent.Pipeline.State.GetTransportMessage().MessageType;

			if (!_invokeCounts.ContainsKey(messageType))
			{
				_invokeCounts.Add(messageType,0);
			}

			_invokeCounts[messageType] = _invokeCounts[messageType] + 1;

			return MessageHandlerInvokeResult.InvokedHandler(this);
		}
        private static Task InvokeEventHandlerAsync(PipelineEvent pipelineEvent, Delegate eventHandler)
        {
            var isAsync = eventHandler.Method.ReturnType == typeof(Task);

            if (isAsync)
            {
                return((Task)eventHandler.DynamicInvoke(pipelineEvent.Event));
            }

            eventHandler.DynamicInvoke(pipelineEvent.Event);

            return(Task.CompletedTask);
        }
Beispiel #14
0
        public Task InvokeAsync(
            ProjectionPipelineModuleConfig config,
            PipelineContext pipelineContext,
            NextModuleDelegate invokeNextModule
            )
        {
            var projectedEvent = config.EventProjection.Convert(pipelineContext.PipelineEvent.Event);

            var projectedPipelineEvent = new PipelineEvent(projectedEvent);

            pipelineContext.PipelineEvent = projectedPipelineEvent;

            return(invokeNextModule(pipelineContext));
        }
Beispiel #15
0
 public void RaisedEvent(PipelineEvent pEvent)
 {
     if (OnEventRaised == null)
     {
         return;
     }
     Parallel.ForEach(OnEventRaised.GetInvocationList(), t => {
         ((EventHandler <PipelineEventEventArgs>)t).BeginInvoke(
             this, new PipelineEventEventArgs()
         {
             Event = pEvent
         }, null, null);
     });
 }
Beispiel #16
0
        /// <inheritdoc />
        public async Task RouteEventAsync(PipelineEvent pipelineEvent, IEventsScope eventsScope)
        {
            using (_logger.BeginEventRoutingScope(pipelineEvent))
            {
                var pipelines = _pipelinesService.GetPipelines(pipelineEvent.EventType);

                foreach (var pipeline in pipelines)
                {
                    _logger.EventRoutedToPipeline();

                    await pipeline.ProcessEventAsync(pipelineEvent, eventsScope).ConfigureAwait(false);
                }
            }
        }
        public void SetUp()
        {
            _appServiceProviderMock       = new Mock <IRootAppServiceProvider>(MockBehavior.Strict);
            _eventsContextMock            = new Mock <IEventsContext>(MockBehavior.Strict);
            _pipelineMock                 = new Mock <IPipeline>(MockBehavior.Strict);
            _eventsQueueNamesServiceMock  = new Mock <IEventsQueueNamesService>(MockBehavior.Strict);
            _eventsScopeMock              = new Mock <IEventsScope>(MockBehavior.Strict);
            _eventsScopeQueuesFeatureMock = new Mock <IEventsScopeQueuesFeature>(MockBehavior.Strict);

            _eventsQueue   = new EventsQueue(_queueName);
            _pipelineEvent = MakeNewPipelineEvent();

            _eventsQueuesService = new EventsQueuesService(_eventsContextMock.Object, _eventsQueueNamesServiceMock.Object);
        }
        public void SetUp()
        {
            _loggerMock           = new Mock <ILogger <RoutingService> >(MockBehavior.Strict);
            _loggerScopeMock      = new Mock <IDisposable>(MockBehavior.Strict);
            _pipelineMock         = new Mock <IPipeline>(MockBehavior.Strict);
            _pipelinesServiceMock = new Mock <IPipelinesService>(MockBehavior.Strict);
            _eventsScopeMock      = new Mock <IEventsScope>(MockBehavior.Strict);

            _routingService = new RoutingService(
                _loggerMock.Object,
                _pipelinesServiceMock.Object
                );
            _pipelineEvent = new PipelineEvent(new object());
        }
        public MessageNotHandledEventArgs(PipelineEvent pipelineEvent, IQueue workQueue, IQueue errorQueue,
                                          TransportMessage transportMessage, object message)
            : base(pipelineEvent)
        {
            Guard.AgainstNull(pipelineEvent, "pipelineEvent");
            Guard.AgainstNull(workQueue, "workQueue");
            Guard.AgainstNull(errorQueue, "errorQueue");
            Guard.AgainstNull(transportMessage, "transportMessage");
            Guard.AgainstNull(message, "message");

            WorkQueue        = workQueue;
            ErrorQueue       = errorQueue;
            TransportMessage = transportMessage;
            Message          = message;
        }
        public void SetUp()
        {
            _serviceProviderMock     = new Mock <IServiceProvider>(MockBehavior.Strict);
            _eventsQueuesServiceMock = new Mock <IEventsQueuesService>(MockBehavior.Strict);
            _eventsScopeMock         = new Mock <IEventsScope>(MockBehavior.Strict);

            _enqueuePipelineModuleConfig = new EnqueuePipelineModuleConfig
            {
                QueueName = QueueName
            };
            _pipelineEvent   = new PipelineEvent(new object());
            _pipelineContext = new PipelineContext(_pipelineEvent, _eventsScopeMock.Object, _serviceProviderMock.Object);

            _enqueuePipelineModule = new EnqueuePipelineModule(_eventsQueuesServiceMock.Object);
        }
Beispiel #21
0
        public void SetUp()
        {
            _azureSignalRClientMock = new Mock <IEventSendingService>(MockBehavior.Strict);
            _serviceProviderMock    = new Mock <IServiceProvider>(MockBehavior.Strict);
            _eventsScopeMock        = new Mock <IEventsScope>(MockBehavior.Strict);

            _azureSignalRPipelineModuleConfig = new AzureSignalRPipelineModuleConfig
            {
                HubMethodName             = nameof(AzureSignalRPipelineModuleConfig.HubMethodName),
                HubName                   = nameof(AzureSignalRPipelineModuleConfig.HubName),
                PublicationMethod         = PublicationMethod.User,
                ReceiverIdsProviderAction = e => _receiverIds
            };
            _pipelineEvent   = new PipelineEvent(typeof(object));
            _pipelineContext = new PipelineContext(_pipelineEvent, _eventsScopeMock.Object, _serviceProviderMock.Object);

            _azureSignalRPipelineModule = new AzureSignalRPipelineModule(_azureSignalRClientMock.Object);
        }
        public async Task MessageHandler_ShouldDeserializeAndPublishEventToGlobalSubscriptions()
        {
            await _azureTopicEventReceiver.StartReceivingAsync(CancellationToken.None);

            var messageBytes  = new byte[] { 1, 2, 3, 4, 5 };
            var pipelineEvent = new PipelineEvent(typeof(object));

            _eventsSerializationServiceMock
            .Setup(x => x.DeserializeEvent(It.Is <byte[]>(y => y.SequenceEqual(messageBytes))))
            .Returns(pipelineEvent)
            .Verifiable();

            _publishingServiceMock
            .Setup(x => x.PublishEventToGlobalSubscriptionsAsync(pipelineEvent))
            .Returns(Task.CompletedTask)
            .Verifiable();

            await _messageHandler(new Message(messageBytes), CancellationToken.None);
        }
Beispiel #23
0
        public void SetUp()
        {
            _loggerMock = new Mock <ILogger <PublishingService> >(MockBehavior.Strict);
            _globalSubscriptionsServiceMock   = new Mock <IGlobalSubscriptionsService>(MockBehavior.Strict);
            _scopedSubscriptionsServiceMock   = new Mock <IScopedSubscriptionsService>(MockBehavior.Strict);
            _subscriptionsMatchingServiceMock = new Mock <ISubscriptionsMatchingService>(MockBehavior.Strict);

            _eventsScopeMock = new Mock <IEventsScope>(MockBehavior.Strict);
            _eventsScopeSubscriptionsFeatureMock = new Mock <IEventsScopeSubscriptionsFeature>(MockBehavior.Strict);

            _publishingService = new PublishingService(
                _loggerMock.Object,
                _globalSubscriptionsServiceMock.Object,
                _scopedSubscriptionsServiceMock.Object,
                _subscriptionsMatchingServiceMock.Object
                );

            Action <object> subscription0HandlerAction = args =>
            {
                ThrowIfEnabled();
                _subscription0Event = args;
            };

            Action <object> subscription1HandlerAction = args =>
            {
                ThrowIfEnabled();
                _subscription1Event = args;
            };

            _subscriptions = new[]
            {
                new Subscription(typeof(object), subscription0HandlerAction.GetInvocationList()[0]),
                new Subscription(typeof(object), subscription1HandlerAction.GetInvocationList()[0]),
            };

            _pipelineEvent = new PipelineEvent(typeof(object));

            _subscription1Event = null;
            _subscription0Event = null;
            _isThrowingEnabled  = false;
        }
Beispiel #24
0
        public MessageHandlerInvokeResult Invoke(PipelineEvent pipelineEvent)
        {
            Guard.AgainstNull(pipelineEvent, "pipelineEvent");

            var state   = pipelineEvent.Pipeline.State;
            var bus     = state.GetServiceBus();
            var message = state.GetMessage();
            var handler = bus.Configuration.MessageHandlerFactory.GetHandler(message);

            if (handler == null)
            {
                return(MessageHandlerInvokeResult.InvokeFailure());
            }

            try
            {
                var transportMessage = state.GetTransportMessage();
                var messageType      = message.GetType();
                var contextType      = typeof(HandlerContext <>).MakeGenericType(messageType);
                var method           = handler.GetType().GetMethod("ProcessMessage", new[] { contextType });

                if (method == null)
                {
                    throw new ProcessMessageMethodMissingException(string.Format(
                                                                       EsbResources.ProcessMessageMethodMissingException,
                                                                       handler.GetType().FullName,
                                                                       messageType.FullName));
                }

                var handlerContext = Activator.CreateInstance(contextType, bus, transportMessage, message, state.GetActiveState());

                method.Invoke(handler, new[] { handlerContext });
            }
            finally
            {
                bus.Configuration.MessageHandlerFactory.ReleaseHandler(handler);
            }

            return(MessageHandlerInvokeResult.InvokedHandler(handler));
        }
        internal async Task <Exception> PublishEventAsync(PipelineEvent pipelineEvent)
        {
            if (pipelineEvent == null)
            {
                throw new ArgumentNullException(nameof(pipelineEvent));
            }
            if (!EventType.IsInstanceOfType(pipelineEvent.Event))
            {
                throw new EventTypeMismatchException();
            }

            try
            {
                await InvokeEventHandlerAsync(pipelineEvent, _eventsHandler).ConfigureAwait(false);

                return(null);
            }
            catch (TargetInvocationException ex)
            {
                return(ex.InnerException);
            }
        }
        public void SetUp()
        {
            _pipelineEvent   = new PipelineEvent(new object());
            _topicClientMock = new Mock <ITopicClient>(MockBehavior.Strict);
            _loggerMock      = new Mock <ILogger <AzureTopicEventSender> >(MockBehavior.Strict);
            _eventsSerializationServiceMock = new Mock <IEventsSerializationService>(MockBehavior.Strict);
            _topicClientFactoryMock         = new Mock <ITopicClientFactory>(MockBehavior.Strict);
            _topicClientFactoryMock
            .Setup(x => x.GetNew(Constants.ValidConnectionString))
            .Returns(_topicClientMock.Object)
            .Verifiable();

            _azureTopicEventSender = new AzureTopicEventSender(
                _loggerMock.Object,
                Options.Create(new AzureTopicEventSenderOptions
            {
                SendConnectionString = Constants.ValidConnectionString
            }),
                _eventsSerializationServiceMock.Object,
                _topicClientFactoryMock.Object
                );
        }
Beispiel #27
0
        public void EnqueueEvent(IEventsScope eventsScope, PipelineEvent pipelineEvent, string queueName, Func <Task> invokeNextModule)
        {
            if (eventsScope == null)
            {
                throw new ArgumentNullException(nameof(eventsScope));
            }
            if (pipelineEvent == null)
            {
                throw new ArgumentNullException(nameof(pipelineEvent));
            }
            if (queueName == null)
            {
                throw new ArgumentNullException(nameof(queueName));
            }

            if (!_eventsQueueNamesService.IsQueueNameExisting(queueName))
            {
                throw new EventsQueueNotFoundException();
            }

            var queue = eventsScope.GetQueuesFeature().GetOrAddEventsQueue(_eventsContext, queueName);

            queue.Enqueue(new QueuedPipelineEvent(invokeNextModule));
        }
 public QueueEmptyEventArgs(PipelineEvent pipelineEvent, IQueue queue)
     : base(pipelineEvent)
 {
     Queue = queue;
 }
Beispiel #29
0
 public Task PublishEventToGlobalSubscriptionsAsync(PipelineEvent pipelineEvent)
 => PublishInternalAsync(pipelineEvent, _globalSubscriptionsService.GetGlobalSubscriptions());
 public PipelineEventEventArgs(PipelineEvent pipelineEvent)
 {
     PipelineEvent = pipelineEvent;
 }
Beispiel #31
0
 private static void DisposeDatabaseContext(PipelineEvent pipelineEvent)
 {
     pipelineEvent.Pipeline.State.Get <IDatabaseContext>().AttemptDispose();
 }
        /// <inheritdoc />
        public byte[] SerializeEvent(PipelineEvent pipelineEvent)
        {
            var data = JsonConvert.SerializeObject(pipelineEvent, pipelineEvent.EventType, _serializerSettings);

            return(Encoding.UTF8.GetBytes(data));
        }