Exemple #1
0
        private ServiceBusProcessor GetOrAddProcessor(string entityPath, string connectionString)
        {
            ServiceBusClient client = _clientCache.GetOrAdd(connectionString, (_) => CreateClient(connectionString));

            return(_processorCache.GetOrAdd(entityPath, (_) =>
            {
                ServiceBusProcessor processor;
                if (ServiceBusEntityPathHelper.ParseEntityType(entityPath) == EntityType.Topic)
                {
                    // entityPath for a subscription is "{TopicName}/Subscriptions/{SubscriptionName}"
                    ServiceBusEntityPathHelper.ParseTopicAndSubscription(entityPath, out string topic, out string subscription);
                    processor = client.CreateProcessor(topic, subscription, _options.ToProcessorOptions());
                }
        private ClientEntity GetOrAddClientEntity(string entityPath, string connectionString)
        {
            string cacheKey = $"{entityPath}-{connectionString}";

            if (ServiceBusEntityPathHelper.ParseEntityType(entityPath) == EntityType.Topic)
            {
                string topic, subscription;

                // entityPath for a subscription is "{TopicName}/Subscriptions/{SubscriptionName}"
                ServiceBusEntityPathHelper.ParseTopicAndSubscription(entityPath, out topic, out subscription);
                return(_clientEntityCache.GetOrAdd(cacheKey, new SubscriptionClient(connectionString, topic, subscription)
                {
                    PrefetchCount = _options.PrefetchCount
                }));
            }
            else
            {
                // entityPath for a queue is "{QueueName}"
                return(_clientEntityCache.GetOrAdd(cacheKey, new QueueClient(connectionString, entityPath)
                {
                    PrefetchCount = _options.PrefetchCount
                }));
            }
        }