static void Main(string[] args)
        {
            using (IConnectionFactory connectionFactory = new CachingConnectionFactory())
            {
                IAmqpAdmin amqpAdmin = new RabbitAdmin(connectionFactory);

                //Each queue is automatically bound to the default direct exchange.
                amqpAdmin.DeclareQueue(new Queue(ConfigurationManager.AppSettings["STOCK_REQUEST_QUEUE_NAME"]));
                amqpAdmin.DeclareQueue(new Queue(ConfigurationManager.AppSettings["STOCK_RESPONSE_QUEUE_NAME"]));

                TopicExchange mktDataExchange = new TopicExchange(ConfigurationManager.AppSettings["MARKET_DATA_EXCHANGE_NAME"], false, false);
                amqpAdmin.DeclareExchange(mktDataExchange);
                Queue mktDataQueue = new Queue(ConfigurationManager.AppSettings["MARKET_DATA_QUEUE_NAME"]);
                amqpAdmin.DeclareQueue(mktDataQueue);

                Console.WriteLine("Queues and exchanges have been declared.");
                Console.WriteLine("Press 'enter' to exit");
                Console.ReadLine();
            }
        }
        public void TestSendAndReceiveWithFanout()
        {
            var admin = new RabbitAdmin(this.connectionFactory);
            var exchange = new FanoutExchange("fanout");
            admin.DeclareExchange(exchange);
            this.template.Exchange = exchange.Name;

            admin.DeclareBinding(BindingBuilder.Bind(queue).To(exchange));

            this.template.Execute<object>(delegate(IModel channel)
                                         {
                                             var consumer = this.CreateConsumer(this.template);
                                             var tag = consumer.ConsumerTag;
                                             Assert.IsNotNull(tag);

                                             try
                                             {
                                                 this.template.ConvertAndSend("message");
                                                 var result = this.GetResult(consumer);
                                                 Assert.AreEqual("message", result);
                                             }
                                             finally
                                             {
                                                 try
                                                 {
                                                     channel.BasicCancel(tag);
                                                 }
                                                 catch (Exception e)
                                                 {
                                                     // TODO: this doesn't make sense. Looks like there is a bug in the rabbitmq.client code here: http://hg.rabbitmq.com/rabbitmq-dotnet-client/file/2f12b3b4d6bd/projects/client/RabbitMQ.Client/src/client/impl/ModelBase.cs#l1018
                                                     Console.WriteLine(e.Message);
                                                 }
                                             }

                                             return null;
                                         });
        }
Пример #3
0
        /// <summary>The apply.</summary>
        /// <returns>The System.Boolean.</returns>
        public bool Apply()
        {
            // Check at the beginning, so this can be used as a static field
            if (this.assumeOnline)
            {
                Assume.That(BrokerOnline.Get(this.port));
            }
            else
            {
                Assume.That(BrokerOffline.Get(this.port));
            }

            var connectionFactory = new CachingConnectionFactory();

            try
            {
                connectionFactory.Port = this.port;
                if (!string.IsNullOrWhiteSpace(this.hostName))
                {
                    connectionFactory.Host = this.hostName;
                }

                var admin = new RabbitAdmin(connectionFactory);
                var exchange = new FederatedExchange("fedDirectRuleTest");
                exchange.BackingType = "direct";
                exchange.UpstreamSet = "upstream-set";
                admin.DeclareExchange(exchange);
                admin.DeleteExchange("fedDirectRuleTest");

                BrokerOffline.AddOrUpdate(this.port, false);

                if (!this.assumeOnline)
                {
                    Assume.That(BrokerOffline.Get(this.port));
                }
            }
            catch (Exception e)
            {
                Logger.Warn(m => m("Not executing tests because federated connectivity test failed"), e);
                BrokerOnline.AddOrUpdate(this.port, false);
                if (this.assumeOnline)
                {
                    Assume.That(e == null, "An exception occurred.");
                    return false;
                }
            }
            finally
            {
                connectionFactory.Dispose();
            }

            return true;

            // return super.apply(base, method, target);
        }
        public void TestSendAndReceiveWithTopicConsumeInBackground()
        {
            var admin = new RabbitAdmin(this.connectionFactory);
            var exchange = new TopicExchange("topic");
            admin.DeclareExchange(exchange);
            this.template.Exchange = exchange.Name;

            admin.DeclareBinding(BindingBuilder.Bind(queue).To(exchange).With("*.end"));

            var template = new RabbitTemplate(new CachingConnectionFactory());
            template.Exchange = exchange.Name;

            var consumer = this.template.Execute<BlockingQueueConsumer>(delegate(IModel channel)
            {
                var consumerinside = this.CreateConsumer(template);
                var tag = consumerinside.ConsumerTag;
                Assert.IsNotNull(tag);

                return consumerinside;
            });

            template.ConvertAndSend("foo", "message");
            var result = this.GetResult(consumer);
            Assert.AreEqual(null, result);

            this.template.ConvertAndSend("foo.end", "message");
            result = this.GetResult(consumer);
            Assert.AreEqual("message", result);

            try
            {
                consumer.Model.BasicCancel(consumer.ConsumerTag);
            }
            catch (Exception e)
            {
                // TODO: this doesn't make sense. Looks like there is a bug in the rabbitmq.client code here: http://hg.rabbitmq.com/rabbitmq-dotnet-client/file/2f12b3b4d6bd/projects/client/RabbitMQ.Client/src/client/impl/ModelBase.cs#l1018
                Console.WriteLine(e.Message);
            }
        }
        private void StockForm_Load(object sender, EventArgs e)
        {
            try
            {
                using (IConnectionFactory connectionFactory = new CachingConnectionFactory())
                {
                    IAmqpAdmin amqpAdmin = new RabbitAdmin(connectionFactory);

                    TopicExchange mktDataExchange = new TopicExchange("APP.STOCK.MARKETDATA", false, false);
                    amqpAdmin.DeclareExchange(mktDataExchange);
                    Spring.Messaging.Amqp.Core.Queue mktDataQueue = new Spring.Messaging.Amqp.Core.Queue("APP.STOCK.MARKETDATA");
                    amqpAdmin.DeclareQueue(mktDataQueue);

                    //Create the Exchange for MarketData Requests if it does not already exist.
                    //amqpAdmin.DeclareBinding(BindingBuilder.Bind(mktDataQueue).To(mktDataExchange).With(_currentBinding));
                    //Set up initial binding
                    RebindQueue("APP.STOCK.QUOTES.nasdaq.*");
                }
            }
            catch (Exception ex)
            {
                log.ErrorFormat("Uncaught application exception.", ex);
            }
        }
        public void TestSendAndReceiveWithFanout()
        {
            var admin = new RabbitAdmin(this.connectionFactory);
            var exchange = new FanoutExchange("fanout");
            admin.DeclareExchange(exchange);
            this.template.Exchange = exchange.Name;

            admin.DeclareBinding(BindingBuilder.Bind(queue).To(exchange));

            this.template.Execute<object>(
                delegate
                {
                    var consumer = this.CreateConsumer(this.template);
                    var tag = consumer.ConsumerTag;
                    Assert.IsNotNull(tag);

                    try
                    {
                        this.template.ConvertAndSend("message");
                        var result = this.GetResult(consumer);
                        Assert.AreEqual("message", result);
                    }
                    finally
                    {
                        consumer.Stop();
                    }

                    return null;
                });
        }
        public void TestSendAndReceiveWithTopicConsumeInBackground()
        {
            var admin = new RabbitAdmin(this.connectionFactory);
            var exchange = new TopicExchange("topic");
            admin.DeclareExchange(exchange);
            this.template.Exchange = exchange.Name;

            admin.DeclareBinding(BindingBuilder.Bind(queue).To(exchange).With("*.end"));

            var template = new RabbitTemplate(new CachingConnectionFactory());
            template.Exchange = exchange.Name;

            var consumer = this.template.Execute(
                delegate
                {
                    var consumerinside = this.CreateConsumer(template);
                    var tag = consumerinside.ConsumerTag;
                    Assert.IsNotNull(tag);

                    return consumerinside;
                });

            template.ConvertAndSend("foo", "message");
            var result = this.GetResult(consumer);
            Assert.AreEqual(null, result);

            this.template.ConvertAndSend("foo.end", "message");
            result = this.GetResult(consumer);
            Assert.AreEqual("message", result);

            consumer.Stop();
        }
        public void TestSendAndReceiveWithNonDefaultExchange()
        {
            var admin = new RabbitAdmin(this.connectionFactory);
            var exchange = new TopicExchange("topic");
            admin.DeclareExchange(exchange);

            admin.DeclareBinding(BindingBuilder.Bind(queue).To(exchange).With("*.end"));

            this.template.Execute<object>(
                delegate
                {
                    var consumer = this.CreateConsumer(this.template);
                    var tag = consumer.ConsumerTag;
                    Assert.IsNotNull(tag);

                    this.template.ConvertAndSend("topic", "foo", "message");

                    try
                    {
                        var result = this.GetResult(consumer);
                        Assert.AreEqual(null, result);

                        this.template.ConvertAndSend("topic", "foo.end", "message");
                        result = this.GetResult(consumer);
                        Assert.AreEqual("message", result);
                    }
                    finally
                    {
                        consumer.Channel.BasicCancel(tag);
                    }

                    return null;
                });
        }
Пример #9
0
        private void StockForm_Load(object sender, EventArgs e)
        {
            accountNameTextBox.Text = DefaultAccountName;
            tradeQuantityNumericUpDown.Value = DefaultTradeRequestQuantity;
            txtRoutingKey.Text = DefaultRoutingKey;

            tradeOperationsGroupBox.Enabled = false;

            try
            {
                using (IConnectionFactory connectionFactory = new CachingConnectionFactory())
                {
                    IAmqpAdmin amqpAdmin = new RabbitAdmin(connectionFactory);

                    TopicExchange mktDataExchange = new TopicExchange("app.stock.marketdata", false, false);
                    amqpAdmin.DeclareExchange(mktDataExchange);
                    Spring.Messaging.Amqp.Core.Queue mktDataQueue = new Spring.Messaging.Amqp.Core.Queue("app.stock.marketdata");
                    amqpAdmin.DeclareQueue(mktDataQueue);

                    //Create the Exchange for MarketData Requests if it does not already exist.
                    //amqpAdmin.DeclareBinding(BindingBuilder.Bind(mktDataQueue).To(mktDataExchange).With(_currentBinding));
                    //Set up initial binding
                    RebindQueue(DefaultRoutingKey);
                }
            }
            catch (Exception ex)
            {
                log.ErrorFormat("Uncaught application exception.", ex);
            }
        }