コード例 #1
0
        public async Task Receives_incoming_messages_from_endpoint_queue()
        {
            var cts = new CancellationTokenSource(TimeSpan.FromSeconds(60));

            // cleanup
            await TestUtility.Delete("sales");

            // setting up the environment
            var container = new TransportPartsContainer();

            var topology = await SetupEndpointOrientedTopology(container, "sales");

            // setup the operator
            var topologyOperator = (IOperateTopology)container.Resolve(typeof(TopologyOperator));

            var completed = new AsyncManualResetEvent(false);
            var error     = new AsyncManualResetEvent(false);

            var       received = false;
            Exception ex       = null;

            topologyOperator.OnIncomingMessage((message, context) =>
            {
                received = true;

                completed.Set();

                return(TaskEx.Completed);
            });
            topologyOperator.OnError(exception =>
            {
                ex = exception;

                error.Set();

                return(TaskEx.Completed);
            });

            // execute
            topologyOperator.Start(topology.DetermineReceiveResources("sales"), 1);

            // send message to queue
            var senderFactory = (MessageSenderCreator)container.Resolve(typeof(MessageSenderCreator));
            var sender        = await senderFactory.Create("sales", null, "namespace");

            await sender.Send(new BrokeredMessage());

            await Task.WhenAny(completed.WaitAsync(cts.Token).IgnoreCancellation(), error.WaitAsync(cts.Token).IgnoreCancellation());


            // validate
            Assert.IsTrue(received);
            Assert.IsNull(ex);

            await topologyOperator.Stop();
        }
コード例 #2
0
        public async Task Calls_on_error_when_error_during_processing()
        {
            var cts = new CancellationTokenSource(TimeSpan.FromSeconds(60));

            // cleanup
            await TestUtility.Delete("sales");

            // setting up the environment
            var container = new TransportPartsContainer();

            var topology = await SetupEndpointOrientedTopology(container, "sales");

            // setup the operator
            var topologyOperator = (IOperateTopology)container.Resolve(typeof(TopologyOperator));

            var error = new AsyncManualResetEvent(false);

            var received      = false;
            var errorOccurred = false;

            topologyOperator.OnIncomingMessage(async(message, context) =>
            {
                received = true;
                await Task.Delay(1).ConfigureAwait(false);
                throw new Exception("Something went wrong");
            });
            topologyOperator.OnError(exception =>
            {
                errorOccurred = true;

                error.Set();

                return(TaskEx.Completed);
            });

            // execute
            topologyOperator.Start(topology.DetermineReceiveResources("sales"), 1);

            // send message to queue
            var senderFactory = (MessageSenderCreator)container.Resolve(typeof(MessageSenderCreator));
            var sender        = await senderFactory.Create("sales", null, "namespace");

            await sender.Send(new BrokeredMessage());

            await error.WaitAsync(cts.Token);

            // validate
            Assert.IsTrue(received);
            Assert.IsTrue(errorOccurred);

            await topologyOperator.Stop();
        }
コード例 #3
0
        async Task SetupAsync(TransportPartsContainer container, SettingsHolder settings)
        {
            await TestUtility.Delete(SourceQueueName, DestinationQueueName);

            topology = await SetupEndpointOrientedTopology(container, SourceQueueName, settings);

            // create the destination queue
            var namespaceLifeCycle = (IManageNamespaceManagerLifeCycle)container.Resolve(typeof(IManageNamespaceManagerLifeCycle));
            var creator            = (ICreateAzureServiceBusQueues)container.Resolve(typeof(ICreateAzureServiceBusQueues));

            namespaceManager = namespaceLifeCycle.Get("namespaceName");
            await creator.Create(DestinationQueueName, namespaceManager);
        }
        public void Creates_subscription_on_each_topic_in_bundle()
        {
            var container = new TransportPartsContainer();

            var settings = new SettingsHolder();

            container.Register(typeof(SettingsHolder), () => settings);
            var extensions = new TransportExtensions <AzureServiceBusTransport>(settings);

            settings.SetDefault("NServiceBus.Routing.EndpointName", "sales");
            extensions.UseForwardingTopology().NamespacePartitioning().AddNamespace(Name, Connectionstring);

            var topology = new ForwardingTopology(container);

            topology.Initialize(settings);

            var sectionManager = container.Resolve <ITopologySectionManager>();

            sectionManager.DetermineResourcesToCreate(new QueueBindings());

            var section = sectionManager.DetermineResourcesToSubscribeTo(typeof(SomeTestEvent));

            Assert.That(section.Entities.Count(), Is.EqualTo(2));
            // TODO: need to verify that subscription is done on each topic
        }
        public void Determines_there_should_be_a_topic_bundle_created()
        {
            var container = new TransportPartsContainer();

            var settings = new SettingsHolder();

            container.Register(typeof(SettingsHolder), () => settings);
            var extensions = new TransportExtensions <AzureServiceBusTransport>(settings);

            settings.SetDefault("NServiceBus.Routing.EndpointName", "sales");
            extensions.NamespacePartitioning().AddNamespace(Name, Connectionstring);

            var topology = new ForwardingTopology(container);

            topology.Initialize(settings);

            var sectionManager = container.Resolve <ITopologySectionManager>();
            var definition     = sectionManager.DetermineResourcesToCreate(new QueueBindings());

            var result = definition.Entities.Where(ei => ei.Type == EntityType.Topic && ei.Namespace.ConnectionString == Connectionstring && ei.Path.StartsWith("bundle-"));

            Assert.That(result.Count(), Is.EqualTo(2));
            Assert.That(result, Has.Exactly(1).Matches <EntityInfo>(x => x.Path == "bundle-1"));
            Assert.That(result, Has.Exactly(1).Matches <EntityInfo>(x => x.Path == "bundle-2"));
        }
        public async Task Pushes_received_message_into_pipeline()
        {
            var cts = new CancellationTokenSource(TimeSpan.FromSeconds(60));

            await TestUtility.Delete("sales");

            var settings = new SettingsHolder();

            settings.Set("NServiceBus.SharedQueue", "sales");
            new DefaultConfigurationValues().Apply(settings);

            // setting up the environment
            var container = new TransportPartsContainer();

            var topology = await SetupEndpointOrientedTopology(container, "sales");

            // setup the operator
            var pump = new MessagePump(topology, container, settings);

            var completed = new AsyncManualResetEvent(false);
            //var error = new AsyncManualResetEvent(false);

            var       received = false;
            Exception ex       = null;

            // Dummy CriticalError
            var criticalError = new CriticalError(ctx => TaskEx.Completed);

            await pump.Init(context =>
            {
                received = true;

                completed.Set();

                return(TaskEx.Completed);
            }, null, criticalError, new PushSettings("sales", "error", false, TransportTransactionMode.ReceiveOnly));

            // execute
            pump.Start(new PushRuntimeSettings(1));

            // send message to queue
            var senderFactory = (MessageSenderCreator)container.Resolve(typeof(MessageSenderCreator));
            var sender        = await senderFactory.Create("sales", null, "namespaceName");

            await sender.Send(new BrokeredMessage());

            await completed.WaitAsync(cts.Token).IgnoreCancellation(); // Task.WhenAny(completed.WaitOne(), error.WaitOne());

            // validate
            Assert.IsTrue(received);
            Assert.IsNull(ex);

            // cleanup
            await pump.Stop();
        }
#pragma warning disable 618
        static TopologySection DetermineResourcesToCreate(SettingsHolder settings, TransportPartsContainer container)
        {
            var topology = new EndpointOrientedTopology(container);

            topology.Initialize(settings);

            var sectionManager = container.Resolve <ITopologySectionManager>();

            var definition = sectionManager.DetermineResourcesToCreate(new QueueBindings());

            return(definition);
        }
コード例 #8
0
        async Task <ITopologySectionManager> SetupEndpointOrientedTopology(TransportPartsContainer container, string endpointName, SettingsHolder settings)
        {
            container.Register(typeof(SettingsHolder), () => settings);
            settings.SetDefault("NServiceBus.Routing.EndpointName", endpointName);
            settings.Set <Conventions>(new Conventions());

            var extensions = new TransportExtensions <AzureServiceBusTransport>(settings);

            extensions.NamespacePartitioning().AddNamespace("namespaceName", AzureServiceBusConnectionString.Value);

            var endpointOrientedTopology = new EndpointOrientedTopology(container);

            endpointOrientedTopology.Initialize(settings);

            // create the topologySectionManager
            var topologyCreator = (ICreateTopology)container.Resolve(typeof(TopologyCreator));
            var sectionManager  = container.Resolve <ITopologySectionManager>();
            await topologyCreator.Create(sectionManager.DetermineResourcesToCreate(new QueueBindings()));

            container.RegisterSingleton <TopologyOperator>();
            return(sectionManager);
        }
#pragma warning disable 618
        ITopologySectionManager SetupForwardingTopology(TransportPartsContainer container, string enpointname)
        {
            var settings = new SettingsHolder();

            container.Register(typeof(SettingsHolder), () => settings);
            var extensions = new TransportExtensions <AzureServiceBusTransport>(settings);

            settings.SetDefault("NServiceBus.Routing.EndpointName", enpointname);
            extensions.NamespacePartitioning().AddNamespace("namespace1", AzureServiceBusConnectionString.Value);

            var topology = new ForwardingTopology(container);

            topology.Initialize(settings);

            return(container.Resolve <ITopologySectionManager>());
        }
        ITopologySectionManager SetupEndpointOrientedTopologyWithFailoverNamespace(TransportPartsContainer container, string enpointname)
        {
            var settings = new SettingsHolder();

            settings.Set <Conventions>(new Conventions());
            container.Register(typeof(SettingsHolder), () => settings);
            var extensions = new TransportExtensions <AzureServiceBusTransport>(settings);

            settings.SetDefault("NServiceBus.Routing.EndpointName", enpointname);
            extensions.NamespacePartitioning().AddNamespace("namespace1", AzureServiceBusConnectionString.Value);
            extensions.NamespacePartitioning().AddNamespace("namespace2", AzureServiceBusConnectionString.Fallback);
            extensions.NamespacePartitioning().UseStrategy <FailOverNamespacePartitioning>();

            var topology = new EndpointOrientedTopology(container);

            topology.Initialize(settings);

            return(container.Resolve <ITopologySectionManager>());
        }
        public void Should_fail_sanitization_for_invalid_endpoint_name(string reasonToFail, string endpointName)
        {
            var container = new TransportPartsContainer();

            var settings = new SettingsHolder();

            container.Register(typeof(SettingsHolder), () => settings);
            var extensions = new TransportExtensions <AzureServiceBusTransport>(settings);

            settings.SetDefault("NServiceBus.Routing.EndpointName", endpointName);
            extensions.NamespacePartitioning().AddNamespace(Name, Connectionstring);

            var topology = new ForwardingTopology(container);

            topology.Initialize(settings);

            var sectionManager = container.Resolve <ITopologySectionManager>();

            Assert.Throws <Exception>(() => sectionManager.DetermineResourcesToCreate(new QueueBindings()), "Was expected to fail: " + reasonToFail);
        }
コード例 #12
0
        public void SetUp()
        {
            tokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(60));
            completed   = new AsyncManualResetEvent(false);
            container   = new TransportPartsContainer();
            var settings = new SettingsHolder();

            settings.Set("NServiceBus.SharedQueue", SourceQueueName);
            criticalError = new CriticalError(ctx => TaskEx.Completed);

            var extensions = new TransportExtensions <AzureServiceBusTransport>(settings);

            extensions.SendViaReceiveQueue(true);

            SetupAsync(container, settings).GetAwaiter().GetResult();

            dispatcher = (IDispatchMessages)container.Resolve(typeof(IDispatchMessages));

            timeToWaitBeforeTriggeringTheCircuitBreaker = TimeSpan.FromSeconds(5);
            pump = new MessagePump(topology, container, settings, timeToWaitBeforeTriggeringTheCircuitBreaker);
        }
        public void Determines_there_should_be_a_queue_with_same_name_as_endpointname()
        {
            var container = new TransportPartsContainer();

            var settings = new SettingsHolder();

            container.Register(typeof(SettingsHolder), () => settings);
            var extensions = new TransportExtensions <AzureServiceBusTransport>(settings);

            settings.SetDefault("NServiceBus.Routing.EndpointName", "sales");
            extensions.NamespacePartitioning().AddNamespace(Name, Connectionstring);

            var topology = new ForwardingTopology(container);

            topology.Initialize(settings);

            var sectionManager = container.Resolve <ITopologySectionManager>();
            var definition     = sectionManager.DetermineResourcesToCreate(new QueueBindings());

            Assert.AreEqual(1, definition.Entities.Count(ei => ei.Path == "sales" && ei.Type == EntityType.Queue && ei.Namespace.ConnectionString == Connectionstring));
        }
        public void Determines_the_namespace_from_partitioning_strategy()
        {
            var container = new TransportPartsContainer();

            var settings = new SettingsHolder();

            container.Register(typeof(SettingsHolder), () => settings);
            var extensions = new TransportExtensions <AzureServiceBusTransport>(settings);

            settings.SetDefault("NServiceBus.Routing.EndpointName", "sales");
            extensions.NamespacePartitioning().AddNamespace(Name, Connectionstring);

            var topology = new ForwardingTopology(container);

            topology.Initialize(settings);

            var sectionManager = container.Resolve <ITopologySectionManager>();
            var definition     = sectionManager.DetermineResourcesToCreate(new QueueBindings());

            // ReSharper disable once RedundantArgumentDefaultValue
            var namespaceInfo = new RuntimeNamespaceInfo(Name, Connectionstring);

            Assert.IsTrue(definition.Namespaces.Any(nsi => nsi == namespaceInfo));
        }
        public void Should_creates_subscription_entities_marked_as_not_be_listened_to()
        {
            var container = new TransportPartsContainer();

            var settings = new SettingsHolder();

            container.Register(typeof(SettingsHolder), () => settings);
            var extensions = new TransportExtensions <AzureServiceBusTransport>(settings);

            settings.SetDefault("NServiceBus.Routing.EndpointName", "sales");
            extensions.UseForwardingTopology().NamespacePartitioning().AddNamespace(Name, Connectionstring);

            var topology = new ForwardingTopology(container);

            topology.Initialize(settings);

            var sectionManager = container.Resolve <ITopologySectionManager>();

            sectionManager.DetermineResourcesToCreate(new QueueBindings());

            var section = sectionManager.DetermineResourcesToSubscribeTo(typeof(SomeTestEvent));

            Assert.IsFalse(section.Entities.Any(x => x.ShouldBeListenedTo));
        }
        public void Creates_subscription_path_matching_the_subscribing_endpoint_name()
        {
            var container = new TransportPartsContainer();

            var settings = new SettingsHolder();

            container.Register(typeof(SettingsHolder), () => settings);
            var extensions = new TransportExtensions <AzureServiceBusTransport>(settings);

            settings.SetDefault("NServiceBus.Routing.EndpointName", "sales");
            extensions.UseForwardingTopology().NamespacePartitioning().AddNamespace(Name, Connectionstring);

            var topology = new ForwardingTopology(container);

            topology.Initialize(settings);

            var sectionManager = container.Resolve <ITopologySectionManager>();

            sectionManager.DetermineResourcesToCreate(new QueueBindings());

            var section = sectionManager.DetermineResourcesToSubscribeTo(typeof(SomeTestEvent));

            Assert.IsTrue(section.Entities.All(e => e.Path == "sales"), "Subscription name should be matching subscribing endpoint name, but it wasn't.");
        }