public CloudQueueFactoryTest()
        {
            // Note: the tests here heavily depend on "real" Azure.Storage entities - we do mock the virtual methods,
            // but all constructors are "real" code.
            // Therefore, a change in next version of Azure.Storage SDK may break our tests (in that case maybe wrap any Azure.Storage entity
            // in a proxy or a wrapper class with the public interface and test that)

            _cloudQueueClientFactoryMock = Substitute.For <ICloudQueueClientFactory>();

            // Mock entire CloudQueueClient - the factory code for it havily depends on MS Azure.Storage entities
            // whose logic we do not want to test
            // What we do want to test is how many times .GetCloudQueueClient() or .GetQueueReference() has been called
            {
                _cloudQueueClientMock = Substitute.ForPartsOf <CloudQueueClient>(
                    new StorageUri(new Uri("https://test.com")),
                    new Microsoft.Azure.Storage.Auth.StorageCredentials(),
                    null);

                _cloudQueueClientMock.When(c => c.GetQueueReference(Arg.Any <string>())).DoNotCallBase();
                _cloudQueueClientMock.GetQueueReference(Arg.Any <string>())
                .Returns(x =>
                {
                    CloudQueue queue = Substitute.ForPartsOf <CloudQueue>(new Uri($"http://test.com/{x.Arg<string>()}"));
                    queue.When(q => q.CreateIfNotExistsAsync()).DoNotCallBase();
                    queue.CreateIfNotExistsAsync().Returns(Task.FromResult(true));
                    return(queue);
                });

                _cloudQueueClientFactoryMock.GetCloudQueueClient().Returns(_ => _cloudQueueClientMock);
            }

            _cloudQueueFactory = new CloudQueueFactory(_cloudQueueClientFactoryMock);
        }
        /// <summary>
        /// Constructs the transport using a <see cref="CloudStorageAccount"/>
        /// </summary>
        public GooglePubSubTransport(CloudStorageAccount storageAccount, string inputQueueName, IRebusLoggerFactory rebusLoggerFactory, GooglePubSubTransportOptions options, IRebusTime rebusTime)
        {
            if (storageAccount == null)
            {
                throw new ArgumentNullException(nameof(storageAccount));
            }
            if (rebusLoggerFactory == null)
            {
                throw new ArgumentNullException(nameof(rebusLoggerFactory));
            }

            _options   = options;
            _rebusTime = rebusTime;
            _log       = rebusLoggerFactory.GetLogger <GooglePubSubTransport>();
            _initialVisibilityDelay = options.InitialVisibilityDelay;

            var queueClient = storageAccount.CreateCloudQueueClient();

            _queueFactory = new CloudQueueClientQueueFactory(queueClient);

            if (inputQueueName != null)
            {
                if (!Regex.IsMatch(inputQueueName, QueueNameValidationRegex))
                {
                    throw new ArgumentException($"The inputQueueName {inputQueueName} is not valid - it can contain only alphanumeric characters and hyphens, and must not have 2 consecutive hyphens.", nameof(inputQueueName));
                }
                Address = inputQueueName.ToLowerInvariant();
            }
        }
Example #3
0
        /// <summary>
        /// Constructs the transport using a <see cref="ICloudQueueFactory"/>
        /// </summary>
        public AzureStorageQueuesTransport(ICloudQueueFactory queueFactory, string inputQueueName, IRebusLoggerFactory rebusLoggerFactory, AzureStorageQueuesTransportOptions options, IRebusTime rebusTime)
        {
            if (rebusLoggerFactory == null)
            {
                throw new ArgumentNullException(nameof(rebusLoggerFactory));
            }

            _options   = options ?? throw new ArgumentNullException(nameof(options));
            _rebusTime = rebusTime;
            _log       = rebusLoggerFactory.GetLogger <AzureStorageQueuesTransport>();
            _initialVisibilityDelay = options.InitialVisibilityDelay;
            _queueFactory           = queueFactory ?? throw new ArgumentNullException(nameof(queueFactory));

            if (inputQueueName != null)
            {
                if (!Regex.IsMatch(inputQueueName, QueueNameValidationRegex))
                {
                    throw new ArgumentException($"The inputQueueName {inputQueueName} is not valid - it can contain only alphanumeric characters and hyphens, and must not have 2 consecutive hyphens.", nameof(inputQueueName));
                }
                Address = inputQueueName.ToLowerInvariant();
            }
        }
        /// <summary>
        /// Configures Rebus to use Azure Storage Queues to transport messages as a one-way client (i.e. will not be able to receive any messages)
        /// </summary>
        public static void UseAzureStorageQueuesAsOneWayClient(this StandardConfigurer <ITransport> configurer, ICloudQueueFactory queueFactory, AzureStorageQueuesTransportOptions options = null)
        {
            Register(configurer, null, queueFactory, options);

            OneWayClientBackdoor.ConfigureOneWayClient(configurer);
        }
 /// <summary>
 /// Configures Rebus to use Azure Storage Queues to transport messages
 /// </summary>
 public static void UseAzureStorageQueues(this StandardConfigurer <ITransport> configurer, ICloudQueueFactory queueFactory, string inputQueueAddress, AzureStorageQueuesTransportOptions options = null)
 {
     Register(configurer, inputQueueAddress, queueFactory, options);
 }
        static void Register(StandardConfigurer <ITransport> configurer, string inputQueueAddress, ICloudQueueFactory queueFactory, AzureStorageQueuesTransportOptions optionsOrNull)
        {
            if (configurer == null)
            {
                throw new ArgumentNullException(nameof(configurer));
            }
            if (queueFactory == null)
            {
                throw new ArgumentNullException(nameof(queueFactory));
            }

            var options = optionsOrNull ?? new AzureStorageQueuesTransportOptions();

            configurer.Register(c =>
            {
                var rebusLoggerFactory = c.Get <IRebusLoggerFactory>();
                var rebusTime          = c.Get <IRebusTime>();
                return(new AzureStorageQueuesTransport(queueFactory, inputQueueAddress, rebusLoggerFactory, options, rebusTime));
            });

            if (options.UseNativeDeferredMessages)
            {
                configurer.OtherService <ITimeoutManager>().Register(c => new DisabledTimeoutManager(), description: AsqTimeoutManagerText);

                configurer.OtherService <IPipeline>().Decorate(c =>
                {
                    var pipeline = c.Get <IPipeline>();

                    return(new PipelineStepRemover(pipeline)
                           .RemoveIncomingStep(s => s.GetType() == typeof(HandleDeferredMessagesStep)));
                });
            }
        }
Example #7
0
        /// <summary>
        /// Configures Rebus to use Google Pub/Sub to transport messages as a one-way client (i.e. will not be able to receive any messages)
        /// </summary>
        public static void UseGooglePubSubAsOneWayClient(this StandardConfigurer <ITransport> configurer, ICloudQueueFactory queueFactory, GooglePubSubTransportOptions options = null)
        {
            Register(configurer, null, queueFactory, options);

            OneWayClientBackdoor.ConfigureOneWayClient(configurer);
        }
Example #8
0
 /// <summary>
 /// Configures Rebus to use Google Pub/Sub to transport messages
 /// </summary>
 public static void UseGooglePubSub(this StandardConfigurer <ITransport> configurer, ICloudQueueFactory queueFactory, string inputQueueAddress, GooglePubSubTransportOptions options = null)
 {
     Register(configurer, inputQueueAddress, queueFactory, options);
 }
Example #9
0
 public CloudQueueService(IMessageSerializer messageSerializer, ICloudQueueFactory cloudQueueClientFactory)
 {
     this._messageSerializer       = messageSerializer;
     this._cloudQueueClientFactory = cloudQueueClientFactory;
 }