public ITransport Create(string inputQueueAddress)
        {
            var consoleLoggerFactory = new ConsoleLoggerFactory(false);
            var asyncTaskFactory = new TplAsyncTaskFactory(consoleLoggerFactory);

            if (inputQueueAddress == null)
            {
                var transport = new AzureServiceBusTransport(ConnectionString, null, consoleLoggerFactory, asyncTaskFactory);

                transport.Initialize();

                return transport;
            }

            return _queuesToDelete.GetOrAdd(inputQueueAddress, () =>
            {
                var transport = new AzureServiceBusTransport(ConnectionString, inputQueueAddress, consoleLoggerFactory, asyncTaskFactory);

                transport.PurgeInputQueue();

                transport.Initialize();

                return transport;
            });
        }
        public ITransport Create(string inputQueueAddress)
        {
            return _queuesToDelete.GetOrAdd(inputQueueAddress, () =>
            {
                var transport = new AzureServiceBusTransport(ConnectionString, inputQueueAddress);

                transport.PurgeInputQueue();

                transport.Initialize();

                return transport;
            });
        }
        public ITransport Create(string inputQueueAddress)
        {
            if (inputQueueAddress == null)
            {
                var transport = new AzureServiceBusTransport(ConnectionString, null, new ConsoleLoggerFactory(false));

                transport.Initialize();

                return transport;
            }

            return _queuesToDelete.GetOrAdd(inputQueueAddress, () =>
            {
                var transport = new BasicAzureServiceBusTransport(ConnectionString, inputQueueAddress, new ConsoleLoggerFactory(false));

                transport.PurgeInputQueue();

                transport.Initialize();

                return transport;
            });
        }
        ITransport GetTransport()
        {
            var consoleLoggerFactory = new ConsoleLoggerFactory(false);
            var asyncTaskFactory = new TplAsyncTaskFactory(consoleLoggerFactory);
            var connectionString = StandardAzureServiceBusTransportFactory.ConnectionString;
            var busLifetimeEvents = new BusLifetimeEvents();

            if (_mode == AzureServiceBusMode.Basic)
            {
                var basicTransport = new BasicAzureServiceBusTransport(connectionString, _queueName, consoleLoggerFactory, asyncTaskFactory, busLifetimeEvents);
                Using(basicTransport);
                basicTransport.Initialize();
                basicTransport.PurgeInputQueue();
                return basicTransport;
            }
            var transport = new AzureServiceBusTransport(connectionString, _queueName, consoleLoggerFactory, asyncTaskFactory, busLifetimeEvents);
            Using(transport);
            transport.Initialize();
            transport.PurgeInputQueue();
            return transport;
        }
 ITransport GetTransport()
 {
     if (_mode == AzureServiceBusMode.Basic)
     {
         var basicTransport = new BasicAzureServiceBusTransport(StandardAzureServiceBusTransportFactory.ConnectionString, _queueName, new ConsoleLoggerFactory(false));
         basicTransport.Initialize();
         basicTransport.PurgeInputQueue();
         return basicTransport;
     }
     var transport = new AzureServiceBusTransport(StandardAzureServiceBusTransportFactory.ConnectionString, _queueName, new ConsoleLoggerFactory(false));
     Using(transport);
     transport.Initialize();
     transport.PurgeInputQueue();
     return transport;
 }
        public async Task DoesntIgnoreDefinedTimeoutWhenReceiving(int operationTimeoutInSeconds)
        {
            var operationTimeout = TimeSpan.FromSeconds(operationTimeoutInSeconds);

            var connString = AsbTestConfig.ConnectionString;
            var builder    = new ServiceBusConnectionStringBuilder(connString)
            {
                //    OperationTimeout = operationTimeout,
            };

            var newConnString = builder.ToString();

            var consoleLoggerFactory = new ConsoleLoggerFactory(false);
            var transport            = new AzureServiceBusTransport(newConnString, QueueName, consoleLoggerFactory, new TplAsyncTaskFactory(consoleLoggerFactory), new AzureServiceBusNameHelper());

            Using(transport);

            transport.Initialize();

            transport.PurgeInputQueue();
            //Create the queue for the receiver since it cannot create it self beacuse of lacking rights on the namespace
            transport.CreateQueue(QueueName);

            var senderActivator = new BuiltinHandlerActivator();

            var senderBus = Configure.With(senderActivator)
                            .Transport(t => t.UseAzureServiceBus(newConnString, "sender"))
                            .Start();

            Using(senderBus);

            // queue 3 messages
            await senderBus.Advanced.Routing.Send(QueueName, "message to receiver");

            await senderBus.Advanced.Routing.Send(QueueName, "message to receiver2");

            await senderBus.Advanced.Routing.Send(QueueName, "message to receiver3");

            //await Task.Delay(TimeSpan.FromSeconds(2)); // wait a bit to make sure the messages are queued.

            // receive 1
            using (var scope = new RebusTransactionScope())
            {
                var sw  = System.Diagnostics.Stopwatch.StartNew();
                var msg = await transport.Receive(scope.TransactionContext, CancellationToken.None);

                sw.Stop();
                await scope.CompleteAsync();

                Assert.That(msg, Is.Not.Null);
                Assert.That(sw.Elapsed, Is.LessThan(TimeSpan.FromMilliseconds(1500)));
            }

            // receive 2
            using (var scope = new RebusTransactionScope())
            {
                var sw  = System.Diagnostics.Stopwatch.StartNew();
                var msg = await transport.Receive(scope.TransactionContext, CancellationToken.None);

                sw.Stop();
                await scope.CompleteAsync();

                Assert.That(msg, Is.Not.Null);
                Assert.That(sw.Elapsed, Is.LessThan(TimeSpan.FromMilliseconds(1500)));
            }

            // receive 3
            using (var scope = new RebusTransactionScope())
            {
                var sw  = System.Diagnostics.Stopwatch.StartNew();
                var msg = await transport.Receive(scope.TransactionContext, CancellationToken.None);

                sw.Stop();
                await scope.CompleteAsync();

                Assert.That(msg, Is.Not.Null);
                Assert.That(sw.Elapsed, Is.LessThan(TimeSpan.FromMilliseconds(1500)));
            }

            // receive 4 - NOTHING
            using (var scope = new RebusTransactionScope())
            {
                var sw  = System.Diagnostics.Stopwatch.StartNew();
                var msg = await transport.Receive(scope.TransactionContext, CancellationToken.None);

                sw.Stop();
                await scope.CompleteAsync();

                Assert.That(msg, Is.Null);
                Assert.That(sw.Elapsed, Is.LessThan(operationTimeout.Add(TimeSpan.FromSeconds(2))).And.GreaterThan(operationTimeout.Subtract(TimeSpan.FromSeconds(2))));
            }

            // put 1 more message
            await senderBus.Advanced.Routing.Send(QueueName, "message to receiver5");

            await Task.Delay(TimeSpan.FromSeconds(2)); // wait a bit to make sure the messages are queued.

            // receive 5
            using (var scope = new RebusTransactionScope())
            {
                var sw  = System.Diagnostics.Stopwatch.StartNew();
                var msg = await transport.Receive(scope.TransactionContext, CancellationToken.None);

                sw.Stop();
                await scope.CompleteAsync();

                Assert.That(msg, Is.Not.Null);
                Assert.That(sw.Elapsed, Is.LessThan(TimeSpan.FromMilliseconds(1500)));
            }

            // receive 6 - NOTHING
            using (var scope = new RebusTransactionScope())
            {
                var sw  = System.Diagnostics.Stopwatch.StartNew();
                var msg = await transport.Receive(scope.TransactionContext, CancellationToken.None);

                sw.Stop();
                await scope.CompleteAsync();

                Assert.That(msg, Is.Null);
                Assert.That(sw.Elapsed, Is.LessThan(operationTimeout.Add(TimeSpan.FromSeconds(2))).And.GreaterThan(operationTimeout.Subtract(TimeSpan.FromSeconds(2))));
            }
        }
 static AzureServiceBusTransport GetTransport()
 {
     var transport = new AzureServiceBusTransport(AzureServiceBusTransportFactory.ConnectionString, QueueName);
     transport.Initialize();
     transport.PurgeInputQueue();
     return transport;
 }