public async Task Should_throw_if_at_least_one_batch_fails() { // cleanup await TestUtility.Delete("myqueue", "myqueue2"); // default settings var settings = DefaultConfigurationValues.Apply(SettingsHolderFactory.BuildWithSerializer()); settings.Set(new TopologySettings()); var namespacesDefinition = settings.Get <NamespaceConfigurations>(WellKnownConfigurationKeys.Topology.Addressing.Namespaces); namespacesDefinition.Add("namespace", AzureServiceBusConnectionString.Value, NamespacePurpose.Partitioning); // setup the infrastructure var namespaceManagerCreator = new NamespaceManagerCreator(settings); var namespaceLifecycleManager = new NamespaceManagerLifeCycleManagerInternal(namespaceManagerCreator); var messagingFactoryCreator = new MessagingFactoryCreator(namespaceLifecycleManager, settings); var messagingFactoryLifeCycleManager = new MessagingFactoryLifeCycleManager(messagingFactoryCreator, settings); var messageSenderCreator = new MessageSenderCreator(messagingFactoryLifeCycleManager, settings); var clientLifecycleManager = new MessageSenderLifeCycleManager(messageSenderCreator, settings); var router = new OutgoingBatchRouter(new BatchedOperationsToBrokeredMessagesConverter(settings), clientLifecycleManager, settings, new ThrowOnOversizedBrokeredMessages()); // create the queue var creator = new AzureServiceBusQueueCreator(settings.Get <TopologySettings>().QueueSettings, settings); var namespaceManager = namespaceLifecycleManager.Get("namespace"); await creator.Create("myqueue", namespaceManager); // perform the test var dispatcher = new Dispatcher(router, new FakeBatcher()); // validate Assert.ThrowsAsync <MessagingEntityNotFoundException>(async() => await dispatcher.Dispatch(new TransportOperations(), new TransportTransaction(), new ContextBag())); }
public async Task Should_throw_exception_for_a_message_that_exceeds_maximum_size() { // default settings var settings = DefaultConfigurationValues.Apply(SettingsHolderFactory.BuildWithSerializer()); settings.Set(new TopologySettings()); var namespacesDefinition = settings.Get <NamespaceConfigurations>(WellKnownConfigurationKeys.Topology.Addressing.Namespaces); namespacesDefinition.Add("namespace", AzureServiceBusConnectionString.Value, NamespacePurpose.Partitioning); // setup the infrastructure var namespaceManagerCreator = new NamespaceManagerCreator(settings); var namespaceLifecycleManager = new NamespaceManagerLifeCycleManagerInternal(namespaceManagerCreator); var messagingFactoryCreator = new MessagingFactoryCreator(namespaceLifecycleManager, settings); var messagingFactoryLifeCycleManager = new MessagingFactoryLifeCycleManager(messagingFactoryCreator, settings); var messageSenderCreator = new MessageSenderCreator(messagingFactoryLifeCycleManager, settings); var clientLifecycleManager = new MessageSenderLifeCycleManager(messageSenderCreator, settings); var router = new OutgoingBatchRouter(new BatchedOperationsToBrokeredMessagesConverter(settings), clientLifecycleManager, settings, new ThrowOnOversizedBrokeredMessages()); // create the queue var creator = new AzureServiceBusQueueCreator(settings.Get <TopologySettings>().QueueSettings, settings); var namespaceManager = namespaceLifecycleManager.Get("namespace"); await creator.Create("myqueue", namespaceManager); // setup the batch var @namespace = new RuntimeNamespaceInfo("namespace", AzureServiceBusConnectionString.Value); var bytes = Enumerable.Range(0, settings.Get <int>(WellKnownConfigurationKeys.Connectivity.MessageSenders.MaximumMessageSizeInKilobytes) * 1024).Select(x => (byte)(x % 256)).ToArray(); var batch = new BatchInternal { Destinations = new TopologySectionInternal { Entities = new List <EntityInfoInternal> { new EntityInfoInternal { Namespace = @namespace, Path = "MyQueue", Type = EntityType.Queue } }, Namespaces = new List <RuntimeNamespaceInfo> { @namespace } }, RequiredDispatchConsistency = DispatchConsistency.Default, Operations = new List <BatchedOperationInternal> { new BatchedOperationInternal { Message = new OutgoingMessage("Id-1", new Dictionary <string, string>(), bytes), DeliveryConstraints = new List <DeliveryConstraint>() } } }; // perform the test Assert.That(async() => await router.RouteBatch(batch, null, DispatchConsistency.Default), Throws.Exception.TypeOf <MessageTooLargeException>()); }
public async Task Should_dispatch_multiple_batches() { // cleanup await TestUtility.Delete("myqueue", "myqueue2"); // default settings var settings = DefaultConfigurationValues.Apply(SettingsHolderFactory.BuildWithSerializer()); settings.Set(new TopologySettings()); settings.Set("NServiceBus.Routing.EndpointName", "myqueue"); var namespacesDefinition = settings.Get <NamespaceConfigurations>(WellKnownConfigurationKeys.Topology.Addressing.Namespaces); namespacesDefinition.Add("namespace", AzureServiceBusConnectionString.Value, NamespacePurpose.Partitioning); // setup the infrastructure var namespaceManagerCreator = new NamespaceManagerCreator(settings); var namespaceLifecycleManager = new NamespaceManagerLifeCycleManagerInternal(namespaceManagerCreator); var messagingFactoryCreator = new MessagingFactoryCreator(namespaceLifecycleManager, settings); var messagingFactoryLifeCycleManager = new MessagingFactoryLifeCycleManager(messagingFactoryCreator, settings); var messageSenderCreator = new MessageSenderCreator(messagingFactoryLifeCycleManager, settings); var clientLifecycleManager = new MessageSenderLifeCycleManager(messageSenderCreator, settings); var router = new OutgoingBatchRouter(new BatchedOperationsToBrokeredMessagesConverter(settings), clientLifecycleManager, settings, new ThrowOnOversizedBrokeredMessages()); // create the queue var creator = new AzureServiceBusQueueCreator(settings.Get <TopologySettings>().QueueSettings, settings); var namespaceManager = namespaceLifecycleManager.Get("namespace"); await creator.Create("myqueue", namespaceManager); await creator.Create("myqueue2", namespaceManager); // perform the test var dispatcher = new Dispatcher(router, new FakeBatcher()); await dispatcher.Dispatch(new TransportOperations(), new TransportTransaction(), new ContextBag()); //validate var queue = await namespaceManager.GetQueue("myqueue"); Assert.IsTrue(queue.MessageCount == 2, $"'myqueue' was expected to have 2 message, but it didn't ({queue.MessageCount} found)"); queue = await namespaceManager.GetQueue("myqueue2"); Assert.IsTrue(queue.MessageCount == 2, $"'myqueue2' was expected to have 2 message, but it didn't ({queue.MessageCount} found)"); }
public async Task Can_route_an_outgoing_batch_of_messages() { // default settings var settings = DefaultConfigurationValues.Apply(SettingsHolderFactory.BuildWithSerializer()); settings.Set <TopologySettings>(new TopologySettings()); var namespacesDefinition = settings.Get <NamespaceConfigurations>(WellKnownConfigurationKeys.Topology.Addressing.Namespaces); namespacesDefinition.Add("namespace", AzureServiceBusConnectionString.Value, NamespacePurpose.Partitioning); // setup the infrastructure var namespaceManagerCreator = new NamespaceManagerCreator(settings); var namespaceLifecycleManager = new NamespaceManagerLifeCycleManagerInternal(namespaceManagerCreator); var messagingFactoryCreator = new MessagingFactoryCreator(namespaceLifecycleManager, settings); var messagingFactoryLifeCycleManager = new MessagingFactoryLifeCycleManager(messagingFactoryCreator, settings); var messageSenderCreator = new MessageSenderCreator(messagingFactoryLifeCycleManager, settings); var clientLifecycleManager = new MessageSenderLifeCycleManager(messageSenderCreator, settings); var router = new OutgoingBatchRouter(new BatchedOperationsToBrokeredMessagesConverter(settings), clientLifecycleManager, settings, new ThrowOnOversizedBrokeredMessages()); // create the queue var creator = new AzureServiceBusQueueCreator(settings.Get <TopologySettings>().QueueSettings, settings); var namespaceManager = namespaceLifecycleManager.Get("namespace"); await creator.Create("myqueue", namespaceManager); // setup the batch var @namespace = new RuntimeNamespaceInfo("namespace", AzureServiceBusConnectionString.Value); var bytes = Encoding.UTF8.GetBytes("Whatever"); var batch = new BatchInternal { Destinations = new TopologySectionInternal { Entities = new List <EntityInfoInternal> { new EntityInfoInternal { Namespace = @namespace, Path = "MyQueue", Type = EntityType.Queue } }, Namespaces = new List <RuntimeNamespaceInfo> { @namespace } }, RequiredDispatchConsistency = DispatchConsistency.Default, Operations = new List <BatchedOperationInternal> { new BatchedOperationInternal { Message = new OutgoingMessage("Id-1", new Dictionary <string, string>(), bytes), DeliveryConstraints = new List <DeliveryConstraint>() }, new BatchedOperationInternal { Message = new OutgoingMessage("Id-2", new Dictionary <string, string>(), bytes), DeliveryConstraints = new List <DeliveryConstraint>() } } }; // perform the test await router.RouteBatch(batch, null, DispatchConsistency.Default); //validate var queue = await namespaceManager.GetQueue("myqueue"); Assert.IsTrue(queue.MessageCount == 2); //cleanup await namespaceManager.DeleteQueue("myqueue"); }
public async Task Should_invoke_non_throwing_oversized_brokered_message_handler_for_a_message_that_exceeds_maximum_size_only_once_even_if_fallback_namespace_is_set() { // default settings var settings = DefaultConfigurationValues.Apply(SettingsHolderFactory.BuildWithSerializer()); settings.Set <TopologySettings>(new TopologySettings()); var namespacesDefinition = settings.Get <NamespaceConfigurations>(WellKnownConfigurationKeys.Topology.Addressing.Namespaces); namespacesDefinition.Add("primary", AzureServiceBusConnectionString.Value, NamespacePurpose.Partitioning); namespacesDefinition.Add("fallback", AzureServiceBusConnectionString.Fallback, NamespacePurpose.Partitioning); var oversizedHandler = new MyOversizedBrokeredMessageHandler(); // setup the infrastructure var namespaceManagerCreator = new NamespaceManagerCreator(settings); var namespaceLifecycleManager = new NamespaceManagerLifeCycleManagerInternal(namespaceManagerCreator); var messagingFactoryCreator = new MessagingFactoryCreator(namespaceLifecycleManager, settings); var messagingFactoryLifeCycleManager = new MessagingFactoryLifeCycleManager(messagingFactoryCreator, settings); var messageSenderCreator = new MessageSenderCreator(messagingFactoryLifeCycleManager, settings); var clientLifecycleManager = new MessageSenderLifeCycleManager(messageSenderCreator, settings); var router = new OutgoingBatchRouter(new BatchedOperationsToBrokeredMessagesConverter(settings), clientLifecycleManager, settings, oversizedHandler); // create the queue & fallback queue var creator = new AzureServiceBusQueueCreator(settings.Get <TopologySettings>().QueueSettings, settings); var namespaceManager = namespaceLifecycleManager.Get("primary"); await creator.Create("myqueue", namespaceManager); var fallbackNamespaceManager = namespaceLifecycleManager.Get("fallback"); await creator.Create("myqueue", fallbackNamespaceManager); // setup the batch var @namespace = new RuntimeNamespaceInfo("primary", AzureServiceBusConnectionString.Value); var @fallback = new RuntimeNamespaceInfo("fallback", AzureServiceBusConnectionString.Value, mode: NamespaceMode.Passive); var bytes = Enumerable.Range(0, settings.Get <int>(WellKnownConfigurationKeys.Connectivity.MessageSenders.MaximumMessageSizeInKilobytes) * 1024).Select(x => (byte)(x % 256)).ToArray(); var batch = new BatchInternal { Destinations = new TopologySectionInternal { Entities = new List <EntityInfoInternal> { new EntityInfoInternal { Namespace = @namespace, Path = "myqueue", Type = EntityType.Queue } }, Namespaces = new List <RuntimeNamespaceInfo> { @namespace, @fallback } }, RequiredDispatchConsistency = DispatchConsistency.Default, Operations = new List <BatchedOperationInternal> { new BatchedOperationInternal { Message = new OutgoingMessage("Id-1", new Dictionary <string, string>(), bytes), DeliveryConstraints = new List <DeliveryConstraint>() } } }; // perform the test await router.RouteBatch(batch, null, DispatchConsistency.Default); // validate Assert.True(oversizedHandler.InvocationCount == 1); //cleanup await fallbackNamespaceManager.DeleteQueue("myqueue"); await namespaceManager.DeleteQueue("myqueue"); }
public async Task Should_route_via_active_namespace_first() { // default settings var settings = DefaultConfigurationValues.Apply(SettingsHolderFactory.BuildWithSerializer()); settings.Set <TopologySettings>(new TopologySettings()); var namespacesDefinition = settings.Get <NamespaceConfigurations>(WellKnownConfigurationKeys.Topology.Addressing.Namespaces); namespacesDefinition.Add("primary", AzureServiceBusConnectionString.Value, NamespacePurpose.Partitioning); namespacesDefinition.Add("fallback", AzureServiceBusConnectionString.Fallback, NamespacePurpose.Partitioning); // setup the infrastructure var namespaceManagerCreator = new NamespaceManagerCreator(settings); var namespaceLifecycleManager = new NamespaceManagerLifeCycleManagerInternal(namespaceManagerCreator); var messagingFactoryCreator = new MessagingFactoryCreator(namespaceLifecycleManager, settings); var messagingFactoryLifeCycleManager = new MessagingFactoryLifeCycleManager(messagingFactoryCreator, settings); var messageSenderCreator = new MessageSenderCreator(messagingFactoryLifeCycleManager, settings); var clientLifecycleManager = new MessageSenderLifeCycleManager(messageSenderCreator, settings); var router = new OutgoingBatchRouter(new BatchedOperationsToBrokeredMessagesConverter(settings), clientLifecycleManager, settings, new ThrowOnOversizedBrokeredMessages()); // create the fallback queue (but not the queue in the primary to emulate that it is down) var creator = new AzureServiceBusQueueCreator(settings.Get <TopologySettings>().QueueSettings, settings); var primaryNamespaceManager = namespaceLifecycleManager.Get("primary"); var fallbackNamespaceManager = namespaceLifecycleManager.Get("fallback"); await creator.Create("myqueue", primaryNamespaceManager); await creator.Create("myqueue", fallbackNamespaceManager); // setup the batch var @namespace = new RuntimeNamespaceInfo("primary", AzureServiceBusConnectionString.Value); var fallback = new RuntimeNamespaceInfo("fallback", AzureServiceBusConnectionString.Fallback, mode: NamespaceMode.Passive); var bytes = Encoding.UTF8.GetBytes("Whatever"); var batch = new BatchInternal { Destinations = new TopologySectionInternal { Entities = new List <EntityInfoInternal> { new EntityInfoInternal { Namespace = @namespace, Path = "MyQueue", Type = EntityType.Queue }, new EntityInfoInternal { Namespace = fallback, Path = "MyQueue", Type = EntityType.Queue } }, Namespaces = new List <RuntimeNamespaceInfo> { @namespace, fallback } }, RequiredDispatchConsistency = DispatchConsistency.Default, Operations = new List <BatchedOperationInternal> { new BatchedOperationInternal { Message = new OutgoingMessage("SomeId", new Dictionary <string, string>(), bytes), DeliveryConstraints = new List <DeliveryConstraint>() }, } }; // perform the test await router.RouteBatch(batch, null, DispatchConsistency.Default); //validate var queueOnPrimaryNamespace = await primaryNamespaceManager.GetQueue("myqueue"); Assert.IsTrue(queueOnPrimaryNamespace.MessageCount > 0, "expected to have messages in the primary queue, but there were no messages"); var queueOnSecondaryNamespace = await fallbackNamespaceManager.GetQueue("myqueue"); Assert.IsTrue(queueOnSecondaryNamespace.MessageCount == 0, "expected NOT to have messages in the secondary queue, but there were no messages"); //cleanup await primaryNamespaceManager.DeleteQueue("myqueue"); await fallbackNamespaceManager.DeleteQueue("myqueue"); }