Exemple #1
0
        /// <summary>
        /// Creates a single exchange
        /// </summary>
        /// <param name="address"></param>
        /// <exception cref="ArgumentNullException"></exception>
        /// <exception cref="ServiceException"></exception>
        /// <exception cref="ValidationException"></exception>
        /// <returns></returns>
        public void Declare(ExchangeAddressModel exchange)
        {
            Console.WriteLine($"{exchange.Name} {exchange.ExchangeType}");
            try
            {
                Validate(exchange, "Exchange to declare cannot be null");
                Channel.ExchangeDeclare(
                    exchange.Name,
                    exchange.ExchangeType,
                    exchange.Durable,
                    exchange.AutoDelete,
                    exchange.Arguments
                    );

                if (QueueService != null && exchange.HasQueues())
                {
                    QueueService.DeclareMany(exchange.Queues);
                }
            }
            catch (Exception ex) when(ex is ArgumentNullException || ex is ServiceException || ex is ValidationException)
            {
                throw;
            }
            catch (Exception ex)
            {
                Logger.Error(ex.Message);
                throw new ServiceException("Exchange Service Exception: please see log for more details.");
            }
        }
        public void TestExchangeService_DeclareExchange_AddressObject()
        {
            var addr = new ExchangeAddressModel()
            {
                Name = "Test.Exchange"
            };

            Assert.DoesNotThrow(() => { BaseExchangeService.Declare(addr); });
        }
 public void TestExchangeService_DeclareExchange_ServiceChannelClosed()
 {
     Assert.That(() =>
     {
         var exchange = new ExchangeService(ClosedChannel);
         var addr     = new ExchangeAddressModel()
         {
             Name = "Test.Exchange"
         };
         exchange.Declare(addr);
     }, Throws.TypeOf <ServiceException>());
 }
Exemple #4
0
        public void TestExchangeAddress_ArgsDictionary()
        {
            ExchangeAddressModel ex = new ExchangeAddressModel()
            {
                Name         = "sdfsf",
                ExchangeType = "direct",
                Arguments    = new Dictionary <string, object>()
                {
                    { "test", 32 }, { "test2", new string('o', 30) }
                }
            };

            Assert.Pass();
        }
Exemple #5
0
        public void TestExchangeAddress_ValidAddreses()
        {
            ExchangeAddressModel ex = new ExchangeAddressModel()
            {
                Name         = "sdfsf",
                ExchangeType = "direct"
            };

            var errorMessage = "";

            if (ex.TryValidate(out errorMessage))
            {
                Assert.Pass(errorMessage);
            }
            Assert.Fail("Should have failed");
        }
        public void TestExchangeService_DeclareMany()
        {
            var addr = new ExchangeAddressModel()
            {
                Name = "Test.Exchange.ToDelete"
            };
            var addr2 = new ExchangeAddressModel()
            {
                Name = "Test.Exchange.ToDelete2"
            };
            List <ExchangeAddressModel> exchanges = new List <ExchangeAddressModel>()
            {
                addr, addr2
            };

            // Assert
            Assert.DoesNotThrow(() => { BaseExchangeService.DeclareMany(exchanges); });
        }
        /// <summary>
        /// Creates and binds the exchange and queues using the 'ExchangeService' Component,
        /// then sends the message using the 'PublishService' Component
        /// </summary>
        private static void FanoutSetup_Example2()
        {
            /* Pattern: Publish/Subscribe Message Pattern
             * Related Consumer(s): FanOutRecevier
             * What this will do ...
             * (A) Create an exchange with 2 queues.
             * (B) The type for this exchange will be 'fanout'.
             * (C) Send a single message.
             * (D) The result of this is: Both queues containing 2 a single message .
             */

            // Create the exchange using the exchange service component
            ExchangeAddressModel exchange = new ExchangeAddressModel()
            {
                Name         = "b.fanout.exchange",
                ExchangeType = RabbitMQ.Client.ExchangeType.Fanout,
                Queues       = new List <QueueAddressModel>()
                {
                    new QueueAddressModel()
                    {
                        Name = "b.fanout.queue_1"
                    },
                    new QueueAddressModel()
                    {
                        Name = "b.fanout.queue_2"
                    }
                }
            };

            srvcmngr.ExchangeService.Declare(exchange);

            // Sends the message using the publish service component
            var str     = "Just testing a fanout exchange";
            var message = new MessageModel()
            {
                Body         = str,
                ExchangeName = "b.fanout.exchange",
                SendType     = RabbitMQ.Client.ExchangeType.Fanout
            };

            srvcmngr.PublisherService.Publish(message);
            System.Console.WriteLine("Messages sent");
        }
        public void TestExchangeService_DeclareExchange_WithQueues()
        {
            var exchange = new ExchangeAddressModel()
            {
                Name   = "Test.Exchange.WithQueues",
                Queues = new List <QueueAddressModel>()
                {
                    new QueueAddressModel()
                    {
                        Name = "Test.ExchangeWithQueues.Queue1"
                    },
                    new QueueAddressModel()
                    {
                        Name = "Test.ExchangeWithQueues.Queue2"
                    }
                }
            };

            var exc = new ExchangeService(Channel, new QueueService(Channel));

            Assert.DoesNotThrow(() => { exc.Declare(exchange); });
            Assert.DoesNotThrow(() => { exc.Delete("Test.Exchange.WithQueues", false); });
        }