Ejemplo n.º 1
0
 internal MessageDispatcher(IServiceScopeFactory scopeFactory, IReceiverClient client, MessageHandlerRegistry registry, LogCorrelationHandler logCorrelationHandler)
 {
     LogCorrelationHandler = logCorrelationHandler;
     ScopeFactory          = scopeFactory;
     Client   = client;
     Registry = registry;
 }
Ejemplo n.º 2
0
        private static IServiceCollection ConfigureMessaging(this IServiceCollection services, LogCorrelationHandler logCorrelationHandler, Assembly[] assemblies)
        {
            if (logCorrelationHandler == null)
            {
                throw new ArgumentNullException(nameof(logCorrelationHandler));
            }
            MessageHandlerTypes
            .GetAll(assemblies)
            .ToList()
            .ForEach(t => services.AddTransient(t));
            services
            .AddSingleton <MessagingConfiguration>()
            .AddSingleton(p => new MessageHandlerRegistry(() => MessageHandlerTypes.GetAll(assemblies)))
            .AddSingleton(logCorrelationHandler)
            .AddHostedService <MessagingService>();

            return(services);
        }
Ejemplo n.º 3
0
        public static IServiceCollection ConfigureMessagingWithCorrelationLogging(this IServiceCollection services, LogCorrelationOptions logCorrelationOptions)
        {
            var logCorrelationHandler = new LogCorrelationHandler(true, logCorrelationOptions);

            return(services.ConfigureMessaging(logCorrelationHandler, new[] { Assembly.GetCallingAssembly() }));
        }
Ejemplo n.º 4
0
        public static IServiceCollection ConfigureMessagingWithCorrelationLogging(this IServiceCollection services, LogCorrelationOptions logCorrelationOptions, params Assembly[] assemblies)
        {
            var logCorrelationHandler = new LogCorrelationHandler(true, logCorrelationOptions);

            return(services.ConfigureMessaging(logCorrelationHandler, assemblies));
        }
Ejemplo n.º 5
0
        public static IServiceCollection ConfigureMessaging(this IServiceCollection services, params Assembly[] assemblies)
        {
            var logCorrelationHandler = new LogCorrelationHandler(false);

            return(services.ConfigureMessaging(logCorrelationHandler, assemblies));
        }
Ejemplo n.º 6
0
        /// Scan the given assembly or the calling assembly for MessageHandlers
        /// and register them in the .NET Core IoC.
        /// Fishbus framework classes are also registered
        /// <param name="assembly">Assembly that contains the MessageHandlers</param>
        public static IServiceCollection ConfigureMessaging(this IServiceCollection services)
        {
            var logCorrelationHandler = new LogCorrelationHandler(false);

            return(services.ConfigureMessaging(logCorrelationHandler, new[] { Assembly.GetCallingAssembly() }));
        }
Ejemplo n.º 7
0
        public static IServiceCollection ConfigureMessagingWithCorrelationLogging(this IServiceCollection services, Assembly assembly = null)
        {
            var logCorrelationHandler = new LogCorrelationHandler(true);

            return(services.ConfigureMessaging(logCorrelationHandler, assembly ?? Assembly.GetCallingAssembly()));
        }
Ejemplo n.º 8
0
        public MessagingConfiguration(IOptions <MessageSources> messageSources, MessageHandlerRegistry registry, IServiceScopeFactory scopeFactory, LogCorrelationHandler logCorrelationHandler)
        {
            ServiceBusClient CreateClient(MessageSource s)
            {
                if (!string.IsNullOrEmpty(s.ConnectionString))
                {
                    return(new ServiceBusClient(s.ConnectionString));
                }
                if (s.CredentialType == nameof(AzureCliCredential))
                {
                    return(new ServiceBusClient(s.Namespace, new AzureCliCredential()));
                }
                if (s.CredentialType == nameof(DefaultAzureCredential))
                {
                    return(new ServiceBusClient(s.Namespace, new DefaultAzureCredential()));
                }
                throw new InvalidOperationException("Could not create ServiceBusClient");
            }

            string GetEntityName(MessageSource s) =>
            string.IsNullOrEmpty(s.EntityName) ?
            ServiceBusConnectionStringProperties.Parse(s.ConnectionString).EntityPath :
            s.EntityName;

            (ServiceBusClient, ServiceBusProcessor) CreateSubscriptionClient(Subscription s)
            {
                var client = CreateClient(s);

                return(client, client.CreateProcessor(GetEntityName(s), s.Name,
                                                      new ServiceBusProcessorOptions
                {
                    AutoCompleteMessages = false,
                    MaxConcurrentCalls = s.MaxConcurrentCalls
                }));
            }

            (ServiceBusClient, ServiceBusProcessor) CreateQueueClient(Queue q)
            {
                var client = CreateClient(q);

                return(client, client.CreateProcessor(GetEntityName(q),
                                                      new ServiceBusProcessorOptions
                {
                    AutoCompleteMessages = false,
                    MaxConcurrentCalls = q.MaxConcurrentCalls
                }));
            }

            Dispatchers = messageSources
                          .Value
                          .Subscriptions
                          .Select(subscription => new MessageDispatcher(scopeFactory, CreateSubscriptionClient(subscription), registry, logCorrelationHandler))
                          .Concat(
                messageSources
                .Value
                .Queues
                .Select(queue => new MessageDispatcher(scopeFactory, CreateQueueClient(queue), registry, logCorrelationHandler))
                )
                          .ToList();
        }
Ejemplo n.º 9
0
        public MessagingConfiguration(IOptions <MessageSources> messageSources, MessageHandlerRegistry registry, IServiceScopeFactory scopeFactory, LogCorrelationHandler logCorrelationHandler)
        {
            SubscriptionClient CreateSubscriptionClient(Subscription s) =>
            new SubscriptionClient(new ServiceBusConnectionStringBuilder(s.ConnectionString), s.Name);

            QueueClient CreateQueueClient(Queue q) =>
            new QueueClient(new ServiceBusConnectionStringBuilder(q.ConnectionString));

            Dispatchers = messageSources
                          .Value
                          .Subscriptions
                          .Select(subscription => new MessageDispatcher(scopeFactory, CreateSubscriptionClient(subscription), registry, logCorrelationHandler))
                          .Concat(
                messageSources
                .Value
                .Queues
                .Select(queue => new MessageDispatcher(scopeFactory, CreateQueueClient(queue), registry, logCorrelationHandler))
                )
                          .ToList();
        }