一個winform帶你玩轉rabbitMQ(三) 附源碼

來源:互聯網
上載者:User

標籤:des   winform   blog   http   io   os   ar   for   strong   

第一章. 安裝,簡介和初探

第二章. exchange,queue,binding介紹 訂閱發布 工作隊列(消費者叢集)

本章收尾 介紹API CommandLine 以及其他功能

源碼地址 https://github.com/dubing/MaoyaRabbit

RabbitMQ API

  RabbitMQ Server提供了豐富的http api。

  舉個列子

  

  需要HTTP基本驗證。預設的使用者名稱/密碼為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則是由用戶端手動來控制。

  在demo中在所示處區分

  

  如果你選擇了消費訊息,那麼基本上代碼層面是這樣來完成的

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

 

上一章節介紹了 消費者如何做分布式或者說是叢集,很多同學可能對server端的叢集也高度興趣,鑒於單機的應用程式這裡就不多介紹了,給出官網的傳送門

http://www.rabbitmq.com/clustering.html

本篇收尾 有點狗尾續貂的感覺 旨在按照之前的計劃 放出源碼 希望對大家有協助 

 

一個winform帶你玩轉rabbitMQ(三) 附源碼

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.