Beispiel #1
0
 private async Task CreateHandledQueuesAsync(IEnumerable <Type> handlerTypes, ServiceBusWithHandlers bus)
 {
     foreach (var handlerType in handlerTypes)
     {
         await bus.CreateHandledQueueAsync(handlerType);
     }
 }
Beispiel #2
0
 private async Task CreateQueuesAsync(IEnumerable <Type> commandTypes, ServiceBusWithHandlers bus)
 {
     foreach (var commandType in commandTypes)
     {
         await bus.CreateQueueAsync(commandType);
     }
 }
Beispiel #3
0
 private async Task CreateEventsAsync(IEnumerable <Type> eventTypes, ServiceBusWithHandlers bus)
 {
     foreach (var eventType in eventTypes)
     {
         await bus.CreateTopicAsync(eventType);
     }
 }
Beispiel #4
0
 private async Task CreateSpecificHandledEventsAsync(ServiceBusWithHandlers bus)
 {
     if (_eventHandlerTypes != null)
     {
         await CreateHandledEventsAsync(_eventHandlerTypes, bus);
     }
 }
Beispiel #5
0
 private async Task CreateSpecificHandledQueuesAsync(ServiceBusWithHandlers bus)
 {
     if (_messageHandlerTypes != null)
     {
         await CreateHandledQueuesAsync(_messageHandlerTypes, bus);
     }
 }
Beispiel #6
0
        public async Task <ServiceBusWithHandlers> BuildAsync()
        {
            var bus = new ServiceBusWithHandlers(_serviceBus, _handlerActivator, _logger);

            // set multiple deployments first because json serialization is true in ServiceBus by default
            // this will prevent any exception
            bus.HasMultipleDeployments(_hasMultipleDeployments);
            bus.UseJsonMessageSerialization(_useJsonSerialization);

            await CreateHandledQueuesInAssembliesAsync(bus);

            await CreateSpecificHandledQueuesAsync(bus);

            await CreateQueuesInAssembliesAsync(bus);

            await CreateSpecificQueuesAsync(bus);

            await CreateHandledEventsInAssembliesAsync(bus);

            await CreateSpecificHandledEventsAsync(bus);

            await CreateEventsInAssembliesAsync(bus);

            await CreateSpecificEventsAsync(bus);

            await bus.StartHandlers();

            return(bus);
        }
Beispiel #7
0
        private async Task CreateHandledQueuesInAssembliesAsync(ServiceBusWithHandlers bus)
        {
            if (_messageHandlerAssembliesToScan != null)
            {
                var assemblies = GetAssemblies(_messageHandlerAssembliesToScan);

                var handlerTypesInAssemblies = assemblies
                                               .SelectMany(assembly => assembly.GetTypes())
                                               .Where(type => type.DoesTypeImplementInterface(typeof(ICommandHandler <>)));

                var found = string.Join(",", handlerTypesInAssemblies.Select(e => e.Name));
                _logger.Debug(ServiceBusWithHandlers.LoggerContext, "Found the following command handlers: {0}", found);

                await CreateHandledQueuesAsync(handlerTypesInAssemblies, bus);
            }
        }
Beispiel #8
0
        private async Task CreateEventsInAssembliesAsync(ServiceBusWithHandlers bus)
        {
            if (_eventAssembliesToScan != null)
            {
                var assemblies = GetAssemblies(_eventAssembliesToScan);

                var eventTypesInAssemblies = assemblies
                                             .SelectMany(assembly => assembly.GetTypes())
                                             .Where(type => type.DoesTypeImplementInterface(typeof(IEvent)));

                var found = string.Join(",", eventTypesInAssemblies.Select(e => e.Name));
                _logger.Debug(ServiceBusWithHandlers.LoggerContext, "Found the following events: {0}", found);

                await CreateEventsAsync(eventTypesInAssemblies, bus);
            }
        }