internal MessageDispatcher(IServiceScopeFactory scopeFactory, IReceiverClient client, MessageHandlerRegistry registry, LogCorrelationHandler logCorrelationHandler) { LogCorrelationHandler = logCorrelationHandler; ScopeFactory = scopeFactory; Client = client; Registry = registry; }
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(); }
public MessagingConfiguration(IOptions <MessageSources> messageSources, MessageHandlerRegistry registry, IServiceScopeFactory scopeFactory) { SubscriptionClient CreateSubscriptionClient(Subscription s) { var(connectionString, entityPath) = ConnectionStringSplitter.Split(s.ConnectionString); return(new SubscriptionClient(connectionString, entityPath, s.Name)); } QueueClient CreateQueueClient(Queue q) { var(connectionString, entityPath) = ConnectionStringSplitter.Split(q.ConnectionString); return(new QueueClient(connectionString, entityPath)); } Dispatchers = messageSources .Value .Subscriptions .Select(subscription => new MessageDispatcher(scopeFactory, CreateSubscriptionClient(subscription), registry)) .Concat( messageSources .Value .Queues .Select(queue => new MessageDispatcher(scopeFactory, CreateQueueClient(queue), registry)) ) .ToList(); }
public MessagingConfiguration(IOptions <MessageSources> messageSources, MessageHandlerRegistry registry, IServiceScopeFactory scopeFactory, LogCorrelationOptions logCorrelationOptions) { 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, logCorrelationOptions)) .Concat( messageSources .Value .Queues .Select(queue => new MessageDispatcher(scopeFactory, CreateQueueClient(queue), registry, logCorrelationOptions)) ) .ToList(); }
public MessageDispatcher(IServiceScopeFactory scopeFactory, IReceiverClient client, MessageHandlerRegistry registry) { ScopeFactory = scopeFactory; Client = client; Registry = registry; }