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;
                                         });
        }
示例#2
0
 public Binding To(FanoutExchange fanoutExchange)
 {
     return new Binding(this.queue, fanoutExchange);
 }
示例#3
0
 /// <summary>The to.</summary>
 /// <param name="exchange">The exchange.</param>
 /// <returns>The binding.</returns>
 public Binding To(FanoutExchange exchange)
 {
     return(new Binding(this.name, this.type, exchange.Name, string.Empty, null));
 }
示例#4
0
 public Binding(Queue queue, FanoutExchange exchange)
 {
     this.queue = queue.Name;
     this.exchange = exchange.Name;
     this.routingKey = "";
 }
        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;
                });
        }