Exemplo n.º 1
0
        private static void PublishHelloRabbit(IModel channel, string text = "World!")
        {
            var payload = MqMessageExtensions.ToJsonBytes(new HelloRabbit {
                Name = text
            });
            var props = channel.CreateBasicProperties();

            props.Persistent = true;
            channel.BasicPublish(_exchange, MqQueueNames <HelloRabbit> .Direct, props, payload);
        }
        public void Can_serialize_IMqMessage_into_typed_Message()
        {
            var dto = new Incr {
                Value = 1
            };
            var iMsg      = MqMessageFactory.Create(dto);
            var jsonBytes = MqMessageExtensions.ToJsonBytes((object)iMsg);
            IMqMessage <Incr> typedMessage = MqMessageExtensions.FromJsonBytes <MqMessage <Incr> >(jsonBytes);

            Assert.That(typedMessage.GetBody().Value, Is.EqualTo(dto.Value));
        }
Exemplo n.º 3
0
        public virtual void Publish(string queueName, string exchange, IMqMessage message)
        {
            var props = this.Channel.CreateBasicProperties();

            props.Persistent = true;
            props.PopulateFromMessage(message);

            this.PublishMessageFilter?.Invoke(queueName, props, message);

            var messageBytes = MqMessageExtensions.ToJsonBytes(message.Body);

            this.PublishMessage(exchange ?? MqQueueNames.Exchange, queueName, props, messageBytes);
        }
Exemplo n.º 4
0
        public void Can_publish_messages_to_RabbitMQ()
        {
            RabbitMqConfig.UsingChannel(channel => {
                for (var i1 = 0; i1 < 5; i1++)
                {
                    var payload = MqMessageExtensions.ToJsonBytes(new HelloRabbit {
                        Name = $"World! #{i1}"
                    });
                    var props        = channel.CreateBasicProperties();
                    props.Persistent = true;

                    channel.BasicPublish(_exchange, MqQueueNames <HelloRabbit> .Direct, props, payload);

                    Console.WriteLine("Sent Message " + i1);
                    Thread.Sleep(1000);
                }
            });
        }
Exemplo n.º 5
0
        public void Publishing_message_to_fanout_exchange_publishes_to_all_queues()
        {
            RabbitMqConfig.UsingChannel(channel => {
                channel.RegisterFanoutExchange(_exchangeFanout);

                RegisterQueue(channel, MqQueueNames <HelloRabbit> .Direct, _exchangeFanout);

                var body = MqMessageExtensions.ToJsonBytes(new HelloRabbit {
                    Name = "World!"
                });
                var props        = channel.CreateBasicProperties();
                props.Persistent = true;

                channel.BasicPublish(_exchangeFanout, MqQueueNames <HelloRabbit> .Direct, props, body);

                var basicGetMsg = channel.BasicGet(MqQueueNames <HelloRabbit> .Direct, true);
                Assert.That(basicGetMsg, Is.Not.Null);
            });
        }