Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/263.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在c中从RabbitMQ中的队列获取所有消息#_C#_Rabbitmq - Fatal编程技术网

C# 在c中从RabbitMQ中的队列获取所有消息#

C# 在c中从RabbitMQ中的队列获取所有消息#,c#,rabbitmq,C#,Rabbitmq,给定队列名称,我需要RabbitMQ中该队列中的所有消息 我在msgCount变量中获得了队列中的消息数,在strBody变量中获得了第一条消息。 但是我需要给定队列中的所有消息。RabbitMQ管理UI在我单击“获取消息”按钮时在浏览器中提供的内容 using (var conn = _connectionFactory.CreateConnection()) { using (var channel = conn.CreateModel())

给定队列名称,我需要RabbitMQ中该队列中的所有消息

我在msgCount变量中获得了队列中的消息数,在strBody变量中获得了第一条消息。 但是我需要给定队列中的所有消息。RabbitMQ管理UI在我单击“获取消息”按钮时在浏览器中提供的内容

using (var conn = _connectionFactory.CreateConnection())
        {
            using (var channel = conn.CreateModel())
            {
                var queueName = "myqueuename";

                var response = channel.QueueDeclarePassive(queueName);
                var msgCount = response.MessageCount;
                var consCount = response.ConsumerCount;

                BasicGetResult result = channel.BasicGet(queueName, noAck);


                if (result == null)
                {
                    //No msgs available 
                }
                else
                {
                    IBasicProperties properties = result.BasicProperties;
                    byte[] body = result.Body;

                    string strBody = System.Text.Encoding.UTF8.GetString(body);
                    Console.WriteLine(strBody);
                    //channel.BasicAck(result.DeliveryTag, false);
                }
            }
        }

向rabbitMQ服务器发出简单的http请求即可完成此任务。 向以下url发出POST请求:

string queuesUrl = Url + ":" + Port + "/api/queues/" + VirtualHost + "/" + queueName + "/get";
其中Url是承载rabbitMQ的位置

发送以下有效负载

{"count":5,"ackmode":"ack_requeue_true","encoding":"auto","truncate":50000}
在计数中输入-1以获取所有消息。截断是可选的

RabbitMQ管理HTTP API: