public void Should_be_able_to_get_messages_from_a_queue()
        {
            var queue = managementClient.GetQueues().SingleOrDefault(x => x.Name == testQueue);

            if (queue == null)
            {
                throw new ApplicationException("Test queue has not been created");
            }

            var defaultExchange = new Exchange {
                Name = "amq.default", Vhost = vhostName
            };

            var properties = new Dictionary <string, string>
            {
                { "app_id", "management-test" }
            };

            var publishInfo = new PublishInfo(properties, testQueue, "Hello World", "string");

            managementClient.Publish(defaultExchange, publishInfo);

            var criteria = new GetMessagesCriteria(1, false);
            var messages = managementClient.GetMessagesFromQueue(queue, criteria);

            foreach (var message in messages)
            {
                Console.Out.WriteLine("message.Payload = {0}", message.Payload);
                foreach (var property in message.Properties)
                {
                    Console.Out.WriteLine("key: '{0}', value: '{1}'", property.Key, property.Value);
                }
            }
        }
        protected internal override void Apply(IManagementClient managementClient)
        {
            _log.Info($"Moving messages from queue '{SourceQueue}' to exchange '{DestinationExchange}'");
            if (MessageTypeDeclared)
            {
                _log.Info($"    MessageType = {MessageType}");
            }

            var virtualHost         = managementClient.GetVhost(VirtualHost);
            var sourceQueue         = managementClient.GetQueue(SourceQueue, virtualHost);
            var destinationExchange = managementClient.GetExchange(DestinationExchange, virtualHost);

            var messages = managementClient.GetMessagesFromQueue(sourceQueue, new GetMessagesCriteria(long.MaxValue, false));

            foreach (var message in messages)
            {
                if (MessageTypeDeclared)
                {
                    message.Properties["type"] = MessageType;
                }

                var properties = message.Properties
                                 .ToDictionary(property => property.Key, property => property.Value);

                managementClient.Publish(destinationExchange, new PublishInfo(properties, "#", message.Payload, message.PayloadEncoding));
            }
        }
示例#3
0
        public void Should_be_able_to_get_messages_from_a_queue()
        {
            var queue = managementClient.GetQueues().SingleOrDefault(x => x.name == testQueue);

            if (queue == null)
            {
                throw new ApplicationException("Test queue has not been created");
            }

            var criteria = new GetMessagesCriteria(1, true);
            var messages = managementClient.GetMessagesFromQueue(queue, criteria);

            foreach (var message in messages)
            {
                Console.Out.WriteLine("message.payload = {0}", message.payload);
            }
        }