Exemple #1
0
        public AddQueueOperation AddQueue(string name)
        {
            var addQueueOperation = new AddQueueOperation()
                                    .SetName(name);

            Operations.Add(addQueueOperation);

            return(addQueueOperation);
        }
        public void PropertySettersMinimalTest()
        {
            var operation = new AddQueueOperation()
                            .SetName("bar");

            Assert.AreEqual("bar", operation.Name);
            Assert.IsFalse(operation.AutoDelete);
            Assert.IsFalse(operation.Durable);
            Assert.IsFalse(operation.Exclusive);
            Assert.AreEqual(0, operation.Arguments.Count);
            Assert.AreEqual(0, operation.BindQueueOperations.Count);
        }
Exemple #3
0
        public void ExecuteTest()
        {
            var addBarQueueOperation = new AddQueueOperation()
                                       .SetName("bar");
            var addFooExchangeOperation = new AddExchangeOperation()
                                          .SetName("foo");
            var addTstQueueOperation = new AddQueueOperation()
                                       .SetName("tst")
                                       .AddQueueBind("foo", "bar");
            var moveDataOperation = new MoveDataToExchangeOperation()
                                    .SetSourceQueueName("bar")
                                    .SetDestinationExchangeName("foo");

            var server            = new RabbitServer();
            var connectionFactory = new FakeConnectionFactory(server);

            using (var connection = connectionFactory.CreateConnection())
            {
                addBarQueueOperation.Execute(connection, string.Empty);
                addFooExchangeOperation.Execute(connection, string.Empty);
                addTstQueueOperation.Execute(connection, string.Empty);

                using (var channel = connection.CreateModel())
                {
                    channel.ExchangeDeclare("", ExchangeType.Direct, true);
                    channel.QueueBind("bar", "", "bar", null);

                    for (int i = 0; i < 10; i++)
                    {
                        var props = channel.CreateBasicProperties();
                        props.Headers = new Dictionary <string, object>();

                        channel.BasicPublish("", "bar", false, props, Encoding.UTF8.GetBytes($"message{i}"));
                    }
                }

                Assert.AreEqual(10, server.Queues.Values.First(x => x.Name == "bar").Messages.Count);
                Assert.AreEqual(0, server.Queues.Values.First(x => x.Name == "tst").Messages.Count);

                moveDataOperation.Execute(connection, string.Empty);

                Assert.AreEqual(0, server.Queues.Values.First(x => x.Name == "bar").Messages.Count);
                Assert.AreEqual(10, server.Queues.Values.First(x => x.Name == "tst").Messages.Count);
            }
        }
        public void ExecuteTest()
        {
            var addOperation = new AddQueueOperation()
                               .SetName("bar");
            var delOperation = new DeleteQueueOperation()
                               .SetName("bar");

            var server            = new RabbitServer();
            var connectionFactory = new FakeConnectionFactory(server);

            using (var connection = connectionFactory.CreateConnection())
            {
                addOperation.Execute(connection, string.Empty);
                delOperation.Execute(connection, string.Empty);
            }

            Assert.AreEqual(0, server.Queues.Count);
        }
        public void ExecuteFullTest()
        {
            var exchangeOperation = new AddExchangeOperation()
                                    .SetName("foo")
                                    .SetType(ExchangeType.Topic);

            var operation = new AddQueueOperation()
                            .SetName("bar")
                            .SetAutoDelete()
                            .SetDurable(true)
                            .SetExclusive()
                            .AddArgument("foo", "foo-bar")
                            .AddQueueBind("foo", "#");

            var server            = new RabbitServer();
            var connectionFactory = new FakeConnectionFactory(server);

            using (var connection = connectionFactory.CreateConnection())
            {
                exchangeOperation.Execute(connection, string.Empty);
                operation.Execute(connection, string.Empty);
            }

            Assert.AreEqual(1, server.Queues.Count);
            var queue = server.Queues.Values.First();

            Assert.AreEqual("bar", queue.Name);
            Assert.IsTrue(queue.IsAutoDelete);
            Assert.IsTrue(queue.IsDurable);
            Assert.IsTrue(queue.IsExclusive);
            Assert.AreEqual(1, queue.Arguments.Count);
            Assert.IsTrue(queue.Arguments.ContainsKey("foo"));
            Assert.AreEqual("foo-bar", queue.Arguments["foo"]);
            Assert.AreEqual(1, queue.Bindings.Count);
            var binding = queue.Bindings.First();

            Assert.AreEqual("foo", binding.Value.Exchange.Name);
            Assert.AreEqual("bar", binding.Value.Queue.Name);
            Assert.AreEqual("#", binding.Value.RoutingKey);
        }
        public void ExecuteMinimalTest()
        {
            var operation = new AddQueueOperation()
                            .SetName("bar");

            var server            = new RabbitServer();
            var connectionFactory = new FakeConnectionFactory(server);

            using (var connection = connectionFactory.CreateConnection())
            {
                operation.Execute(connection, string.Empty);
            }

            Assert.AreEqual(1, server.Queues.Count);
            var queue = server.Queues.Values.First();

            Assert.AreEqual("bar", queue.Name);
            Assert.IsFalse(queue.IsAutoDelete);
            Assert.IsFalse(queue.IsDurable);
            Assert.IsFalse(queue.IsExclusive);
            Assert.AreEqual(0, queue.Arguments.Count);
            Assert.AreEqual(0, queue.Bindings.Count);
        }
        public void PropertySettersFullTest()
        {
            var operation = new AddQueueOperation()
                            .SetName("bar")
                            .SetAutoDelete()
                            .SetDurable(true)
                            .SetExclusive()
                            .AddArgument("foo", "foo-bar")
                            .AddQueueBind("foo", "#");

            Assert.AreEqual("bar", operation.Name);
            Assert.IsTrue(operation.AutoDelete);
            Assert.IsTrue(operation.Durable);
            Assert.IsTrue(operation.Exclusive);
            Assert.AreEqual(1, operation.Arguments.Count);
            Assert.IsTrue(operation.Arguments.ContainsKey("foo"));
            Assert.AreEqual("foo-bar", operation.Arguments["foo"]);
            Assert.AreEqual(1, operation.BindQueueOperations.Count);
            var subOperation = operation.BindQueueOperations.First();

            Assert.AreEqual("bar", subOperation.QueueName);
            Assert.AreEqual("foo", subOperation.ExchangeName);
            Assert.AreEqual("#", subOperation.RoutingKey);
        }
Exemple #8
0
        /// <summary>
        /// Maximum number of priority levels for the queue to support; if not set, the queue will not support message priorities.
        /// (Sets the "x-max-priority" argument.)
        /// </summary>
        public static AddQueueOperation SetMaxPriority(this AddQueueOperation operation, int value)
        {
            Guard.ArgumentNotNull(nameof(operation), operation);

            return(operation.AddArgument("x-max-priority", value));
        }
Exemple #9
0
        /// <summary>
        /// Optional replacement routing key to use when a message is dead-lettered. If this is not set, the message's original routing key will be used.
        /// (Sets the "x-dead-letter-routing-key" argument.)
        /// </summary>
        public static AddQueueOperation SetDeadLetterRoutingKey(this AddQueueOperation operation, string value)
        {
            Guard.ArgumentNotNull(nameof(operation), operation);

            return(operation.AddArgument("x-dead-letter-routing-key", value));
        }
Exemple #10
0
        /// <summary>
        /// Optional name of an exchange to which messages will be republished if they are rejected or expire.
        /// (Sets the "x-dead-letter-exchange" argument.)
        /// </summary>
        public static AddQueueOperation SetDeadLetterExchange(this AddQueueOperation operation, string value)
        {
            Guard.ArgumentNotNull(nameof(operation), operation);

            return(operation.AddArgument("x-dead-letter-exchange", value));
        }
Exemple #11
0
        /// <summary>
        /// Sets the queue overflow behaviour. This determines what happens to messages when the maximum length of a queue is reached.
        /// Valid values are 'drop-head' or 'reject-publish'.
        /// (Sets the "x-overflow" argument.)
        /// </summary>
        public static AddQueueOperation SetOverflowBehaviour(this AddQueueOperation operation, string value)
        {
            Guard.ArgumentNotNull(nameof(operation), operation);

            return(operation.AddArgument("x-overflow", value));
        }
Exemple #12
0
        /// <summary>
        /// Total body size for ready messages a queue can contain before it starts to drop them from its head.
        /// (Sets the "x-max-length-bytes" argument.)
        /// </summary>
        public static AddQueueOperation SetMaxLengthBytes(this AddQueueOperation operation, int value)
        {
            Guard.ArgumentNotNull(nameof(operation), operation);

            return(operation.AddArgument("x-max-length-bytes", value));
        }
Exemple #13
0
        /// <summary>
        /// How long a queue can be unused for before it is automatically deleted (milliseconds).
        /// (Sets the "x-expires" argument.)
        /// </summary>
        public static AddQueueOperation SetAutoExpire(this AddQueueOperation operation, int value)
        {
            Guard.ArgumentNotNull(nameof(operation), operation);

            return(operation.AddArgument("x-expires", value));
        }
Exemple #14
0
        /// <summary>
        /// Set the queue into master location mode, determining the rule by which the queue master is located when declared on a cluster of nodes.
        /// (Sets the "x-queue-master-locator" argument.)
        /// </summary>
        public static AddQueueOperation SetMasterLocation(this AddQueueOperation operation, string value)
        {
            Guard.ArgumentNotNull(nameof(operation), operation);

            return(operation.AddArgument("x-queue-master-locator", value));
        }
Exemple #15
0
        /// <summary>
        /// Set the queue into lazy mode, keeping as many messages as possible on disk to reduce RAM usage; if not set,
        /// the queue will keep an in-memory cache to deliver messages as fast as possible.
        /// (Sets the "x-queue-mode" argument.)
        /// </summary>
        public static AddQueueOperation SetLazyMode(this AddQueueOperation operation)
        {
            Guard.ArgumentNotNull(nameof(operation), operation);

            return(operation.AddArgument("x-queue-mode", "lazy"));
        }
Exemple #16
0
        /// <summary>
        /// How long a message published to a queue can live before it is discarded (milliseconds).
        /// (Sets the "x-message-ttl" argument.)
        /// </summary>
        public static AddQueueOperation SetMessageTimeToLive(this AddQueueOperation operation, int value)
        {
            Guard.ArgumentNotNull(nameof(operation), operation);

            return(operation.AddArgument("x-message-ttl", value));
        }