示例#1
0
        public void Publishing_message_to_fanout_exchange_publishes_to_all_queues()
        {
            using (IConnection connection = mqFactory.CreateConnection())
                using (IModel channel = connection.CreateModel())
                {
                    channel.RegisterFanoutExchange(ExchangeFanout);

                    RegisterQueue(channel, QueueNames <HelloRabbit> .In, exchange: ExchangeFanout);
                    RegisterQueue(channel, QueueNames <HelloRabbit> .Priority, exchange: ExchangeFanout);

                    byte[] payload = new HelloRabbit {
                        Name = "World!"
                    }.ToJson().ToUtf8Bytes();
                    var props = channel.CreateBasicProperties();
                    props.Persistent = true;

                    channel.BasicPublish(ExchangeFanout, QueueNames <HelloRabbit> .In, props, payload);

                    var basicGetMsg = channel.BasicGet(QueueNames <HelloRabbit> .In, noAck: true);
                    Assert.That(basicGetMsg, Is.Not.Null);

                    basicGetMsg = channel.BasicGet(QueueNames <HelloRabbit> .Priority, noAck: true);
                    Assert.That(basicGetMsg, Is.Not.Null);
                }
        }
示例#2
0
        private static void PublishHelloRabbit(IModel channel, string text = "World!")
        {
            byte[] payload = new HelloRabbit {
                Name = text
            }.ToJson().ToUtf8Bytes();
            var props = channel.CreateBasicProperties();

            props.Persistent = true;
            channel.BasicPublish(Exchange, QueueNames <HelloRabbit> .In, props, payload);
        }
示例#3
0
        public void Can_publish_messages_to_RabbitMQ()
        {
            using (IConnection connection = mqFactory.CreateConnection())
                using (IModel channel = connection.CreateModel())
                {
                    5.Times(i => {
                        byte[] payload = new HelloRabbit {
                            Name = "World! #{0}".Fmt(i)
                        }.ToJson().ToUtf8Bytes();
                        var props = channel.CreateBasicProperties();
                        props.SetPersistent(true);

                        channel.BasicPublish(exchange: Exchange,
                                             routingKey: QueueNames <HelloRabbit> .In, basicProperties: props, body: payload);

                        Console.WriteLine("Sent Message " + i);
                        Thread.Sleep(1000);
                    });
                }
        }
示例#4
0
        public void Can_publish_messages_to_RabbitMQ()
        {
            using (IConnection connection = mqFactory.CreateConnection())
            using (IModel channel = connection.CreateModel())
            {
                5.Times(i => {
                    byte[] payload = new HelloRabbit { Name = "World! #{0}".Fmt(i) }.ToJson().ToUtf8Bytes();
                    var props = channel.CreateBasicProperties();
                    props.Persistent = true;

                    channel.BasicPublish(exchange: Exchange,
                        routingKey: QueueNames<HelloRabbit>.In, basicProperties: props, body: payload);

                    Console.WriteLine("Sent Message " + i);
                    Thread.Sleep(1000);
                });
            }
        }
示例#5
0
        public void Publishing_message_to_fanout_exchange_publishes_to_all_queues()
        {
            using (IConnection connection = mqFactory.CreateConnection())
            using (IModel channel = connection.CreateModel())
            {
                channel.RegisterFanoutExchange(ExchangeFanout);

                RegisterQueue(channel, QueueNames<HelloRabbit>.In, exchange: ExchangeFanout);
                RegisterQueue(channel, QueueNames<HelloRabbit>.Priority, exchange: ExchangeFanout);

                byte[] payload = new HelloRabbit { Name = "World!" }.ToJson().ToUtf8Bytes();
                var props = channel.CreateBasicProperties();
                props.Persistent = true;

                channel.BasicPublish(ExchangeFanout, QueueNames<HelloRabbit>.In, props, payload);

                var basicGetMsg = channel.BasicGet(QueueNames<HelloRabbit>.In, noAck: true);
                Assert.That(basicGetMsg, Is.Not.Null);

                basicGetMsg = channel.BasicGet(QueueNames<HelloRabbit>.Priority, noAck: true);
                Assert.That(basicGetMsg, Is.Not.Null);
            }
        }
示例#6
0
 private static void PublishHelloRabbit(IModel channel, string text = "World!")
 {
     byte[] payload = new HelloRabbit {Name = text}.ToJson().ToUtf8Bytes();
     var props = channel.CreateBasicProperties();
     props.Persistent = true;
     channel.BasicPublish(Exchange, QueueNames<HelloRabbit>.In, props, payload);
 }