乐趣与你rabbitMQ 源代码

RabbitMQ API

  RabbitMQ Server它提供了丰富的http api。

  对于列子

  

  须要HTTP基本身份验证。默认的username/password为guest/guest。

  这些返回值得意义我从官网搬来解释,为了避免翻译的问题导致大家理解的误差这里直接给出原文

cluster_name The name of the entire cluster, as set with rabbitmqctl set_cluster_name.
erlang_full_version A string with extended detail about the Erlang VM and how it was compiled, for the node connected to.
erlang_version A string with the Erlang version of the node connected to. As clusters should all run the same version this can be taken as representing the cluster.
exchange_types A list of all exchange types available.
listeners All (non-HTTP) network listeners for all nodes in the cluster. (See contexts in /api/nodes for HTTP).
management_version Version of the management plugin in use.
message_stats A message_stats object for everything the user can see - for all vhosts regardless of permissions in the case of monitoring and administrator users, and for all vhosts the user has access to for other users.
node The name of the cluster node this management plugin instance is running on.
object_totals An object containing global counts of all connections, channels, exchanges, queues and consumers, subject to the same visibility rules as for message_stats.
queue_totals An object containing sums of the messagesmessages_ready and messages_unacknowledged fields for all queues, again subject to the same visibility rules as for message_stats.
rabbitmq_version Version of RabbitMQ on the node which processed this request.
statistics_db_node Name of the cluster node hosting the management statistics database.
statistics_level Whether the node is running fine or coarse statistics.

  又或者通过api查询虚拟主机
  
  很多api的URI须要一个虚拟主机路径的一部分的名字,由于名字仅仅有唯一在一个虚拟主机识别物体。作为默认的虚拟主机称为“/”,这​​将须要被编码为“%2F”。

  在我的demo程序中相应的api功能能够通过这里的功能来实现

  

  其更丰富的功能能够參考官网说明文档 http://hg.rabbitmq.com/rabbitmq-management/raw-file/3646dee55e02/priv/www-api/help.html

  以及 http://hg.rabbitmq.com/rabbitmq-management/raw-file/rabbitmq_v3_3_5/priv/www/api/index.html

  一般来说我们经常使用的我在应用程序中已经给出 比如查看全部队列等

  


 RabbitMQ CommandLine

  除了丰富的http api,rabbitmq server自然也有其非常全面命令行。

  比如查询全部exchange。

  

  查询全部队列以及他们包括的消息数目

   

  rabbitmqctl很多其它的命令说明參考 http://www.rabbitmq.com/man/rabbitmqctl.1.man.html


Message的BasicGet于consume的差别

   consume的功能上一张介绍过,basicget更偏向于我们平时用过的其它类型的MessageQueue,它就是最主要的接受消息,consume的消费针对basicget来说属于一个长连接于短连接的差别。

消费者关系一旦确定。基本上默认它就是在侦听通道的消息是否在生产。而basicget则是由client手动来控制。

  在demo中在下图所看到的处区分

  

  假设你选择了消费消息,那么基本上代码层面是这样来完毕的

1
2
3
4
5
6
7
8
9
var consumer = new QueueingBasicConsumer(channel);
channel.BasicQos(0, 1, false);
channel.BasicConsume(queue.name, rbAckTrue.Checked, consumer);
while (true)
{
    var e = consumer.Queue.Dequeue();
    MessageBox.Show(string.Format("队列{0}获取消息{1},线程id为{2}", queue.name, Encoding.ASCII.GetString(e.Body), Process.GetCurrentProcess().Id));
    Thread.Sleep(1000);
}

版权声明:本文博客原创文章。博客,未经同意,不得转载。

原文地址:https://www.cnblogs.com/zfyouxi/p/4654072.html