Ejemplo n.º 1
0
        public async Task Verify_can_create_dynamic_shovel2()
        {
            var services = GetContainerBuilder().BuildServiceProvider();
            var result   = await services.GetService <IBrokerObjectFactory>()
                           .CreateShovel("test-shovel1", "amqp://user1@localhost", "TestHareDu", x =>
            {
                x.Source("queue1", c =>
                {
                    c.DeleteAfter(DeleteShovelMode.QueueLength);
                });
                x.Destination("queue2");
            });

            Assert.Multiple(() =>
            {
                Assert.IsFalse(result.HasFaulted);
                Assert.IsNotNull(result.DebugInfo);

                ShovelRequest request = result.DebugInfo.Request.ToObject <ShovelRequest>();

                Assert.IsNotNull(request.Value);
                Assert.AreEqual(1000, request.Value.SourcePrefetchCount);
                Assert.AreEqual(ShovelProtocolType.Amqp091, request.Value.SourceProtocol);
                Assert.AreEqual("queue1", request.Value.SourceQueue);
                Assert.AreEqual("amqp://user1@localhost", request.Value.SourceUri);
                Assert.AreEqual(DeleteShovelMode.QueueLength.ConvertTo(), request.Value.SourceDeleteAfter.ToString());
                Assert.AreEqual("queue2", request.Value.DestinationQueue);
                Assert.AreEqual("amqp://user1@localhost", request.Value.DestinationUri);
            });
        }
Ejemplo n.º 2
0
            public ShovelRequest BuildRequest()
            {
                var requestParams = new ShovelRequestParams
                {
                    AcknowledgeMode               = _acknowledgeMode,
                    SourceExchange                = _sourceExchangeName,
                    SourceProtocol                = _sourceProtocol,
                    SourceQueue                   = _sourceQueue,
                    SourceUri                     = _uri,
                    SourceDeleteAfter             = _deleteShovelAfter,
                    SourcePrefetchCount           = _sourcePrefetchCount,
                    SourceExchangeRoutingKey      = _sourceExchangeRoutingKey,
                    ReconnectDelay                = _reconnectDelay,
                    DestinationExchange           = _destinationExchangeName,
                    DestinationProtocol           = _destinationProtocol,
                    DestinationQueue              = _destinationQueue,
                    DestinationUri                = _uri,
                    DestinationExchangeKey        = _destinationExchangeRoutingKey,
                    DestinationAddForwardHeaders  = _destinationAddForwardHeaders,
                    DestinationAddTimestampHeader = _destinationAddTimestampHeader
                };
                var request = new ShovelRequest
                {
                    Value = requestParams
                };

                return(request);
            }
Ejemplo n.º 3
0
        public async Task <Result> Create(string shovel, string uri, string vhost,
                                          Action <ShovelConfigurator> configurator, CancellationToken cancellationToken = default)
        {
            cancellationToken.RequestCanceled();

            var errors = new List <Error>();

            if (configurator.IsNull())
            {
                errors.Add(new (){ Reason = "The shovel configurator is missing." });
            }

            if (errors.Any())
            {
                return new FaultedResult {
                           DebugInfo = new (){ Errors = errors }
                }
            }
            ;

            if (string.IsNullOrWhiteSpace(uri))
            {
                errors.Add(new(){ Reason = "The connection URI is missing." });
            }

            var impl = new ShovelConfiguratorImpl(uri);

            configurator?.Invoke(impl);

            impl.Validate();

            ShovelRequest request = impl.BuildRequest();

            Debug.Assert(request != null);

            errors.AddRange(impl.Errors.Value);

            if (string.IsNullOrWhiteSpace(shovel))
            {
                errors.Add(new (){ Reason = "The name of the shovel is missing." });
            }

            if (string.IsNullOrWhiteSpace(vhost))
            {
                errors.Add(new (){ Reason = "The name of the virtual host is missing." });
            }

            string url = $"api/parameters/shovel/{vhost.ToSanitizedName()}/{shovel}";

            if (errors.Any())
            {
                return new FaultedResult {
                           DebugInfo = new (){ URL = url, Request = request.ToJsonString(Deserializer.Options), Errors = errors }
                }
            }
            ;

            return(await PutRequest(url, request, cancellationToken).ConfigureAwait(false));
        }
Ejemplo n.º 4
0
            public ShovelRequest BuildRequest()
            {
                var requestParams = new ShovelRequestParams(_acknowledgeMode,
                                                            _reconnectDelay,
                                                            _sourceProtocol,
                                                            _uri,
                                                            _sourceQueue,
                                                            _sourceExchangeName,
                                                            _sourceExchangeRoutingKey,
                                                            _sourcePrefetchCount,
                                                            _deleteShovelAfter,
                                                            _destinationProtocol,
                                                            _uri,
                                                            _destinationExchangeName,
                                                            _destinationExchangeRoutingKey,
                                                            _destinationQueue,
                                                            _destinationAddForwardHeaders,
                                                            _destinationAddTimestampHeader);
                var request = new ShovelRequest(requestParams);

                return(request);
            }
Ejemplo n.º 5
0
        public async Task Verify_can_create_dynamic_shovel7()
        {
            var services = GetContainerBuilder().BuildServiceProvider();
            var result   = await services.GetService <IBrokerObjectFactory>()
                           .Object <Shovel>()
                           .Create("test-shovel1", "amqp://user1@localhost", "TestHareDu", x =>
            {
                x.Source("queue2", c =>
                {
                    c.Exchange("exchange2", null);
                    c.DeleteAfter(DeleteShovelMode.QueueLength);
                });
                x.Destination(string.Empty, c =>
                {
                    c.Exchange(string.Empty, null);
                });
            });

            Assert.Multiple(() =>
            {
                Assert.IsTrue(result.HasFaulted);
                Assert.IsNotNull(result.DebugInfo);
                Assert.AreEqual(2, result.DebugInfo.Errors.Count);

                ShovelRequest request = result.DebugInfo.Request.ToObject <ShovelRequest>(Deserializer.Options);

                Assert.IsNotNull(request.Value);
                Assert.AreEqual(1000, request.Value.SourcePrefetchCount);
                Assert.AreEqual(ShovelProtocolType.Amqp091, request.Value.SourceProtocol);
                Assert.AreEqual("queue2", request.Value.SourceQueue);
                Assert.AreEqual("amqp://user1@localhost", request.Value.SourceUri);
                Assert.AreEqual(DeleteShovelMode.QueueLength.Convert(), request.Value.SourceDeleteAfter.ToString());
                Assert.AreEqual("amqp://user1@localhost", request.Value.DestinationUri);
                Assert.AreEqual("exchange2", request.Value.SourceExchange);
                Assert.That(request.Value.DestinationQueue, Is.Empty.Or.Null);
                Assert.That(request.Value.DestinationExchange, Is.Empty.Or.Null);
            });
        }