Exemplo n.º 1
0
        private void RebindQueue(string routingKey)
        {
            var ctx     = ContextRegistry.GetContext();
            var factory =
                ctx.GetObject("ConnectionFactory") as IConnectionFactory;

            try
            {
                IAmqpAdmin amqpAdmin = new RabbitAdmin(factory);

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

                if (!string.IsNullOrEmpty(_currentBinding))
                {
                    amqpAdmin.RemoveBinding(BindingBuilder.Bind(mktDataQueue).To(mktDataExchange).With(_currentBinding));
                }

                _currentBinding = routingKey;
                if (!string.IsNullOrEmpty(_currentBinding))
                {
                    amqpAdmin.DeclareBinding(BindingBuilder.Bind(mktDataQueue).To(mktDataExchange).With(_currentBinding));
                    txtRoutingKey.Text = _currentBinding;
                }
            }
            catch (Exception ex)
            {
                log.ErrorFormat("Uncaught application exception.", ex);
            }
        }
Exemplo n.º 2
0
        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();
        }
Exemplo n.º 3
0
        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);
            });
        }
Exemplo n.º 4
0
        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);
            });
        }