public Topology Parse(IManagementClient client, Vhost virtualHost)
        {
            var topology = new Topology();

            foreach (var exchange in client.GetExchanges())
            {
                if (!IsSystemExchange(exchange.Name))
                {
                    var modelExchange = new Model.Exchange
                    {
                        Name = exchange.Name,
                        ExchangeType = ExchangeTypeMap[exchange.Type],
                        Durable = exchange.Durable,
                    };

                    MapArguments(exchange.Arguments, modelExchange.Arguments);
                    topology.Exchanges.Add(modelExchange);
                }
            }

            foreach (var queue in client.GetQueues())
            {
                if (!IsSystemQueue(queue))
                {
                    var modelQueue = new Model.Queue
                    {
                        Name = queue.Name,
                        Durable = queue.Durable
                    };

                    MapArguments(queue.Arguments, modelQueue.Arguments);

                    foreach (var binding in client.GetBindingsForQueue(queue))
                    {
                        if (!IsSystemBinding(binding))
                        {
                            var modelBinding = new Model.Binding
                            {
                                Exchange = binding.Source,
                                RoutingKey = binding.RoutingKey
                            };

                            MapArguments(binding.Arguments, modelBinding.Arguments);
                            modelQueue.Bindings.Add(modelBinding);
                        }
                    }

                    topology.Queues.Add(modelQueue);
                }
            }

            return topology;
        }
Ejemplo n.º 2
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 defaultExchange = new Exchange { Name = "amq.default", Vhost = "/" };

            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);
                }
            }
        }