/// <summary> /// Configures Rebus to use Azure Service Bus to transport messages as a one-way client (i.e. will not be able to receive any messages) /// </summary> public static void UseAzureServiceBusAsOneWayClient(this StandardConfigurer<ITransport> configurer, string connectionStringNameOrConnectionString, AzureServiceBusMode mode = AzureServiceBusMode.Standard) { var connectionString = GetConnectionString(connectionStringNameOrConnectionString); if (mode == AzureServiceBusMode.Basic) { configurer.Register(c => { var rebusLoggerFactory = c.Get<IRebusLoggerFactory>(); var asyncTaskFactory = c.Get<IAsyncTaskFactory>(); return new BasicAzureServiceBusTransport(connectionString, null, rebusLoggerFactory, asyncTaskFactory); }); OneWayClientBackdoor.ConfigureOneWayClient(configurer); return; } configurer .OtherService<AzureServiceBusTransport>() .Register(c => { var rebusLoggerFactory = c.Get<IRebusLoggerFactory>(); var asyncTaskFactory = c.Get<IAsyncTaskFactory>(); return new AzureServiceBusTransport(connectionString, null, rebusLoggerFactory, asyncTaskFactory); }); configurer .OtherService<ISubscriptionStorage>() .Register(c => c.Get<AzureServiceBusTransport>(), description: AsbSubStorageText); configurer.Register(c => c.Get<AzureServiceBusTransport>()); configurer.OtherService<ITimeoutManager>().Register(c => new DisabledTimeoutManager(), description: AsbTimeoutManagerText); OneWayClientBackdoor.ConfigureOneWayClient(configurer); }
public void ShouldNotCreateInputQueueWhenConfiguredNotTo(AzureServiceBusMode mode) { var manager = NamespaceManager.CreateFromConnectionString(StandardAzureServiceBusTransportFactory.ConnectionString); var queueName = Guid.NewGuid().ToString("N"); Assert.IsFalse(manager.QueueExists(queueName)); var recieverActivator = new BuiltinHandlerActivator(); var bus = Configure.With(recieverActivator) .Logging(l => l.ColoredConsole()) .Transport(t => t.UseAzureServiceBus(StandardAzureServiceBusTransportFactory.ConnectionString, queueName, mode) .DoNotCreateQueues()) .Start(); Assert.IsFalse(manager.QueueExists(queueName)); Using(recieverActivator); Using(bus); }
public void FoundWayToCancelAllPendingReceiveOperations(AzureServiceBusMode mode) { var stopwatch = new Stopwatch(); using (var activator = new BuiltinHandlerActivator()) { Configure.With(activator) .Transport(t => t.UseAzureServiceBus(ConnectionString, QueueName, mode: mode)) .Start(); Thread.Sleep(1000); stopwatch.Start(); } stopwatch.Stop(); var shutdownDuration = stopwatch.Elapsed; Console.WriteLine($"Shutdown took {shutdownDuration}"); }
public async Task ShouldBeAbleToRecieveEvenWhenNotCreatingQueue(AzureServiceBusMode mode) { var consoleLoggerFactory = new ConsoleLoggerFactory(false); var transport = new AzureServiceBusTransport(StandardAzureServiceBusTransportFactory.ConnectionString, QueueName, consoleLoggerFactory, new TplAsyncTaskFactory(consoleLoggerFactory)); 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 recieverActivator = new BuiltinHandlerActivator(); var senderActivator = new BuiltinHandlerActivator(); var receiverBus = Configure.With(recieverActivator) .Logging(l => l.ColoredConsole()) .Transport(t => t.UseAzureServiceBus(StandardAzureServiceBusTransportFactory.ConnectionString, QueueName) .DoNotCreateQueues()) .Start(); var senderBus = Configure.With(senderActivator) .Transport(t => t.UseAzureServiceBus(StandardAzureServiceBusTransportFactory.ConnectionString, "sender", mode)) .Start(); Using(receiverBus); Using(senderBus); var gotMessage = new ManualResetEvent(false); recieverActivator.Handle <string>(async(bus, context, message) => { gotMessage.Set(); Console.WriteLine("got message in readonly mode"); }); await senderBus.Advanced.Routing.Send(QueueName, "message to receiver"); gotMessage.WaitOrDie(TimeSpan.FromSeconds(10)); }
/// <summary> /// Configures Rebus to use Azure Service Bus queues to transport messages, connecting to the service bus instance pointed to by the connection string /// (or the connection string with the specified name from the current app.config) /// </summary> public static AzureServiceBusTransportSettings UseAzureServiceBus(this StandardConfigurer <ITransport> configurer, string connectionStringNameOrConnectionString, string inputQueueAddress, AzureServiceBusMode mode = AzureServiceBusMode.Standard) { var connectionString = GetConnectionString(connectionStringNameOrConnectionString); var settingsBuilder = new AzureServiceBusTransportSettings(); if (mode == AzureServiceBusMode.Basic) { RegisterBasicTransport(configurer, inputQueueAddress, connectionString, settingsBuilder); } else { RegisterStandardTransport(configurer, inputQueueAddress, connectionString, settingsBuilder); } return(settingsBuilder); }
/// <summary> /// Configures Rebus to use Azure Service Bus to transport messages as a one-way client (i.e. will not be able to receive any messages) /// </summary> public static void UseAzureServiceBusAsOneWayClient(this StandardConfigurer <ITransport> configurer, string connectionStringNameOrConnectionString, AzureServiceBusMode mode = AzureServiceBusMode.Standard) { var connectionString = GetConnectionString(connectionStringNameOrConnectionString); if (mode == AzureServiceBusMode.Basic) { configurer.Register(c => { var rebusLoggerFactory = c.Get <IRebusLoggerFactory>(); var asyncTaskFactory = c.Get <IAsyncTaskFactory>(); return(new BasicAzureServiceBusTransport(connectionString, null, rebusLoggerFactory, asyncTaskFactory)); }); OneWayClientBackdoor.ConfigureOneWayClient(configurer); return; } configurer .OtherService <AzureServiceBusTransport>() .Register(c => { var rebusLoggerFactory = c.Get <IRebusLoggerFactory>(); var asyncTaskFactory = c.Get <IAsyncTaskFactory>(); return(new AzureServiceBusTransport(connectionString, null, rebusLoggerFactory, asyncTaskFactory)); }); configurer .OtherService <ISubscriptionStorage>() .Register(c => c.Get <AzureServiceBusTransport>(), description: AsbSubStorageText); configurer.Register(c => c.Get <AzureServiceBusTransport>()); configurer.OtherService <ITimeoutManager>().Register(c => new DisabledTimeoutManager(), description: AsbTimeoutManagerText); OneWayClientBackdoor.ConfigureOneWayClient(configurer); }
/// <summary> /// Configures Rebus to use Azure Service Bus queues to transport messages, connecting to the service bus instance pointed to by the connection string /// (or the connection string with the specified name from the current app.config) /// </summary> public static AzureServiceBusTransportSettings UseAzureServiceBus(this StandardConfigurer<ITransport> configurer, string connectionStringNameOrConnectionString, string inputQueueAddress, AzureServiceBusMode mode = AzureServiceBusMode.Standard) { var connectionString = GetConnectionString(connectionStringNameOrConnectionString); var settingsBuilder = new AzureServiceBusTransportSettings(); if (mode == AzureServiceBusMode.Basic) { configurer.Register(c => { var rebusLoggerFactory = c.Get<IRebusLoggerFactory>(); var asyncTaskFactory = c.Get<IAsyncTaskFactory>(); var transport = new BasicAzureServiceBusTransport(connectionString, inputQueueAddress, rebusLoggerFactory, asyncTaskFactory); if (settingsBuilder.PrefetchingEnabled) { transport.PrefetchMessages(settingsBuilder.NumberOfMessagesToPrefetch); } transport.AutomaticallyRenewPeekLock = settingsBuilder.AutomaticPeekLockRenewalEnabled; transport.PartitioningEnabled = settingsBuilder.PartitioningEnabled; return transport; }); return settingsBuilder; } configurer .OtherService<AzureServiceBusTransport>() .Register(c => { var rebusLoggerFactory = c.Get<IRebusLoggerFactory>(); var asyncTaskFactory = c.Get<IAsyncTaskFactory>(); var transport = new AzureServiceBusTransport(connectionString, inputQueueAddress, rebusLoggerFactory, asyncTaskFactory); if (settingsBuilder.PrefetchingEnabled) { transport.PrefetchMessages(settingsBuilder.NumberOfMessagesToPrefetch); } transport.AutomaticallyRenewPeekLock = settingsBuilder.AutomaticPeekLockRenewalEnabled; transport.PartitioningEnabled = settingsBuilder.PartitioningEnabled; return transport; }); configurer .OtherService<ISubscriptionStorage>() .Register(c => c.Get<AzureServiceBusTransport>(), description: AsbSubStorageText); configurer.Register(c => c.Get<AzureServiceBusTransport>()); configurer.OtherService<IPipeline>().Decorate(c => { var pipeline = c.Get<IPipeline>(); return new PipelineStepRemover(pipeline) .RemoveIncomingStep(s => s.GetType() == typeof(HandleDeferredMessagesStep)); }); configurer.OtherService<ITimeoutManager>().Register(c => new DisabledTimeoutManager(), description: AsbTimeoutManagerText); return settingsBuilder; }
public AzureServiceBusPrefetchTest(AzureServiceBusMode mode) { _mode = mode; }
public async void DoesntIgnoreDefinedTimeoutWhenReceiving(AzureServiceBusMode mode, int operationTimeoutInSeconds) { var operationTimeout = TimeSpan.FromSeconds(operationTimeoutInSeconds); var connString = StandardAzureServiceBusTransportFactory.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 BusLifetimeEvents()); Using(transport); 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", mode)) .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 transactionContext = new DefaultTransactionContext()) { var sw = System.Diagnostics.Stopwatch.StartNew(); var msg = await transport.Receive(transactionContext); sw.Stop(); await transactionContext.Complete(); msg.Should().NotBeNull(); sw.Elapsed.Should().BeLessThan(TimeSpan.FromMilliseconds(1500)); } // receive 2 using (var transactionContext = new DefaultTransactionContext()) { var sw = System.Diagnostics.Stopwatch.StartNew(); var msg = await transport.Receive(transactionContext); sw.Stop(); await transactionContext.Complete(); msg.Should().NotBeNull(); sw.Elapsed.Should().BeLessThan(TimeSpan.FromMilliseconds(1500)); } // receive 3 using (var transactionContext = new DefaultTransactionContext()) { var sw = System.Diagnostics.Stopwatch.StartNew(); var msg = await transport.Receive(transactionContext); sw.Stop(); await transactionContext.Complete(); msg.Should().NotBeNull(); sw.Elapsed.Should().BeLessThan(TimeSpan.FromMilliseconds(1500)); } // receive 4 - NOTHING using (var transactionContext = new DefaultTransactionContext()) { var sw = System.Diagnostics.Stopwatch.StartNew(); var msg = await transport.Receive(transactionContext); sw.Stop(); await transactionContext.Complete(); msg.Should().BeNull(); sw.Elapsed.Should().BeCloseTo(operationTimeout, 2000); } // 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 transactionContext = new DefaultTransactionContext()) { var sw = System.Diagnostics.Stopwatch.StartNew(); var msg = await transport.Receive(transactionContext); sw.Stop(); await transactionContext.Complete(); msg.Should().NotBeNull(); sw.Elapsed.Should().BeLessThan(TimeSpan.FromMilliseconds(1500)); } // receive 6 - NOTHING using (var transactionContext = new DefaultTransactionContext()) { var sw = System.Diagnostics.Stopwatch.StartNew(); var msg = await transport.Receive(transactionContext); sw.Stop(); await transactionContext.Complete(); msg.Should().BeNull(); sw.Elapsed.Should().BeCloseTo(operationTimeout, 2000); } }
public async void ShouldBeAbleToRecieveEvenWhenNotCreatingQueue(AzureServiceBusMode mode) { var consoleLoggerFactory = new ConsoleLoggerFactory(false); var transport = new AzureServiceBusTransport(StandardAzureServiceBusTransportFactory.ConnectionString, QueueName, consoleLoggerFactory, new TplAsyncTaskFactory(consoleLoggerFactory), new BusLifetimeEvents()); 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 recieverActivator = new BuiltinHandlerActivator(); var senderActivator = new BuiltinHandlerActivator(); var receiverBus = Configure.With(recieverActivator) .Logging(l => l.ColoredConsole()) .Transport(t => t.UseAzureServiceBus(StandardAzureServiceBusTransportFactory.ConnectionString, QueueName) .DoNotCreateQueues()) .Start(); var senderBus = Configure.With(senderActivator) .Transport(t => t.UseAzureServiceBus(StandardAzureServiceBusTransportFactory.ConnectionString, "sender", mode)) .Start(); Using(receiverBus); Using(senderBus); var gotMessage = new ManualResetEvent(false); recieverActivator.Handle<string>(async (bus, context, message) => { gotMessage.Set(); Console.WriteLine("got message in readonly mode"); }); await senderBus.Advanced.Routing.Send(QueueName, "message to receiver"); gotMessage.WaitOrDie(TimeSpan.FromSeconds(10)); }
protected AzureServiceBusBusFactory(AzureServiceBusMode mode) { _mode = mode; }
/// <summary> /// Configures Rebus to use Azure Service Bus queues to transport messages, connecting to the service bus instance pointed to by the connection string /// (or the connection string with the specified name from the current app.config) /// </summary> public static AzureServiceBusTransportSettings UseAzureServiceBus(this StandardConfigurer <ITransport> configurer, string connectionStringNameOrConnectionString, string inputQueueAddress, AzureServiceBusMode mode = AzureServiceBusMode.Standard) { var connectionString = GetConnectionString(connectionStringNameOrConnectionString); var settingsBuilder = new AzureServiceBusTransportSettings(); if (mode == AzureServiceBusMode.Basic) { configurer.Register(c => { var rebusLoggerFactory = c.Get <IRebusLoggerFactory>(); var transport = new BasicAzureServiceBusTransport(connectionString, inputQueueAddress, rebusLoggerFactory); if (settingsBuilder.PrefetchingEnabled) { transport.PrefetchMessages(settingsBuilder.NumberOfMessagesToPrefetch); } transport.AutomaticallyRenewPeekLock = settingsBuilder.AutomaticPeekLockRenewalEnabled; transport.PartitioningEnabled = settingsBuilder.PartitioningEnabled; return(transport); }); return(settingsBuilder); } configurer .OtherService <AzureServiceBusTransport>() .Register(c => { var rebusLoggerFactory = c.Get <IRebusLoggerFactory>(); var transport = new AzureServiceBusTransport(connectionString, inputQueueAddress, rebusLoggerFactory); if (settingsBuilder.PrefetchingEnabled) { transport.PrefetchMessages(settingsBuilder.NumberOfMessagesToPrefetch); } transport.AutomaticallyRenewPeekLock = settingsBuilder.AutomaticPeekLockRenewalEnabled; transport.PartitioningEnabled = settingsBuilder.PartitioningEnabled; return(transport); }); configurer .OtherService <ISubscriptionStorage>() .Register(c => c.Get <AzureServiceBusTransport>(), description: AsbSubStorageText); configurer.Register(c => c.Get <AzureServiceBusTransport>()); configurer.OtherService <IPipeline>().Decorate(c => { var pipeline = c.Get <IPipeline>(); return(new PipelineStepRemover(pipeline) .RemoveIncomingStep(s => s.GetType() == typeof(HandleDeferredMessagesStep))); }); configurer.OtherService <ITimeoutManager>().Register(c => new DisabledTimeoutManager(), description: AsbTimeoutManagerText); return(settingsBuilder); }
public async Task DoesntIgnoreDefinedTimeoutWhenReceiving(AzureServiceBusMode mode, int operationTimeoutInSeconds) { var operationTimeout = TimeSpan.FromSeconds(operationTimeoutInSeconds); var connString = StandardAzureServiceBusTransportFactory.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)); Using(transport); 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", mode)) .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); sw.Stop(); await scope.CompleteAsync(); msg.Should().NotBeNull(); sw.Elapsed.Should().BeLessThan(TimeSpan.FromMilliseconds(1500)); } // receive 2 using (var scope = new RebusTransactionScope()) { var sw = System.Diagnostics.Stopwatch.StartNew(); var msg = await transport.Receive(scope.TransactionContext, _cancellationToken); sw.Stop(); await scope.CompleteAsync(); msg.Should().NotBeNull(); sw.Elapsed.Should().BeLessThan(TimeSpan.FromMilliseconds(1500)); } // receive 3 using (var scope = new RebusTransactionScope()) { var sw = System.Diagnostics.Stopwatch.StartNew(); var msg = await transport.Receive(scope.TransactionContext, _cancellationToken); sw.Stop(); await scope.CompleteAsync(); msg.Should().NotBeNull(); sw.Elapsed.Should().BeLessThan(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); sw.Stop(); await scope.CompleteAsync(); msg.Should().BeNull(); sw.Elapsed.Should().BeCloseTo(operationTimeout, 2000); } // 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); sw.Stop(); await scope.CompleteAsync(); msg.Should().NotBeNull(); sw.Elapsed.Should().BeLessThan(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); sw.Stop(); await scope.CompleteAsync(); msg.Should().BeNull(); sw.Elapsed.Should().BeCloseTo(operationTimeout, 2000); } }
public AzureServiceBusPeekLockRenewalTest(AzureServiceBusMode azureServiceBusMode) { _azureServiceBusMode = azureServiceBusMode; }