• Like
Rabbit MQ introduction
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

Rabbit MQ introduction

  • 1,252 views
Published

10/26 於南台資工系

10/26 於南台資工系

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
1,252
On SlideShare
0
From Embeds
0
Number of Embeds
1

Actions

Shares
Downloads
29
Comments
0
Likes
3

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide
  • IP 路由 (routing) 。那什麼是路由呢﹖簡單而言﹐就是當一個封包從發送端被傳送到接收端所經過的路徑。 關於 server push ,以我自身的經驗, cometd 是早期開發者的唯一選擇。要選擇 server push 的原因很簡單, client polling 這個方法太笨了,每一秒或是每十秒去跟 server 要資料某種程度就像是在 DDOS 自己的 server 一樣。 後來 node.js 出現了,我們可以在 server 和 client 間建立 socket , server 收到了變動通知就可以 send message 給 client ,但是對實際的 application 來說還是太麻煩了,我們還是得自己管理 connection ,自己做 routing 。 接著, MessageQueue server 滿足了大家的需求, subscribe/publish/broadcasting ,三個願望一次滿足。 ActiveMQ 是比較有名的 solution ,他是基於 STOMP protocol 的 MessageQueue Server ,我們可以從 client 去 subscribe 某個 queue(channel?) ,所有的 subscriber 就會收到任何送到這個 queue 的訊息。 如果真的有興趣開發這樣的功能, Server 端使用 RabbitMQ 會是一個很好的選擇, client 就選擇有支援 STOMP protocol 的 library(STOMP 的 specification 有 support list) 即可。 ,當到達高水位的時候 , 便會 block 新進來的 connection, 並且通知 cluster 其他 node 也要開始節省使用
  • 面向消息的中間件 ( MOM )系統,例如發布 / 訂閱隊列,沒有作為基本元素實現。反而通過發送簡化的 AMQ 實體,用戶被賦予了構建例如這些實體的能力
  • 如果需要 禁止 A 組訪問 B 組的交換機 / 隊列 / 綁定 , 必須為 A 和 B 分別創建一個虛擬主機 。每一個 RabbitMQ 服務器都有一個默認的虛擬主機“ /” 。如果這就夠了,那現在就可以開始了。 你的 消費者程序要負責創建你的交換機們 (複數) 。啥?你是說你可以有多個交換機?是的,這個可以有,不過為啥?很簡單,每個交換機在自己獨立的進程當中執行,因此增加多個交換機就是增加多個進程,可以充分利用服務器上的 CPU 核以便達到更高的效率。例如,在一個 8 核的服務器上,可以創建 5 個交換機來用 5 個核,另外 3 個核留下來做消息處理。類似的,在 RabbitMQ 的集群當中,你可以用類似的思路來擴展交換機一邊獲取更高的吞吐量。 一個綁定就是一個基於路由鍵將交換機和隊列連接起來的路由規則。
  • https://github.com/alanxz/rabbitmq-c
  • http://140.92.25.159:55672/#/ guest guest
  • 交換機不過就是一個由綁定構成的路由表。 現在復雜的東西來了:交換機有多種類型。他們都是做路由的,不過接受不同類型的綁定。為什麼不創建一種交換機來處理所有類型的路由規則呢?因為每種規則用來做匹配分子的 CPU 開銷是不同的。例如,一個“ topic” 類型的交換機試圖將消息的路由鍵與類似“ dogs.* ” 的模式進行匹配。匹配這種末端的通配符比直接將路由鍵與“ dogs ” 比較(“ direct” 類型的交換機)要消耗更多的 CPU 。如果你不需要“ topic” 類型的交換機帶來的靈活性,你可以通過使用“ direct” 類型的交換機獲取更高的處理效率。 不處理路由鍵。你只需要簡單的將隊列綁定到交換機上。一個發送到交換機的消息都會被轉發到與該交換機綁定的所有隊列上。很像子網廣播,每台子網內的主機都獲得了一份複製的消息。 Fanout 交換機轉發消息是最快的。
  • 處理路由鍵。需要將一個隊列綁定到交換機上,要求該消息與一個特定的路由鍵完全匹配。這是一個完整的匹配。如果一個隊列綁定到該交換機上要求路由鍵“ dog” ,則只有被標記為“ dog ” 的消息才被轉發,不會轉發 dog.puppy ,也不會轉發 dog.guard ,只會轉發 dog 。手機申
  • 將路由鍵和某模式進行匹配。此時隊列需要綁定要一個模式上。符號“ #” 匹配一個或多個詞,符號“ *” 匹配不多不少一個詞。因此“ audit.#” 能夠匹配到“ audit.irs.corporate ” ,但是“ audit.* ” 只會匹配到“ audit.irs ” 。
  • http://www.vmware.com/products/application-platform/vfabric-rabbitmq/overview.html

Transcript

  • 1. Rabbit MQCloud System Software InstituteInstitute for Information Industry 1
  • 2. Outline• Introduction• Technical survey• AMQP• Rabbit MQ• Implement• Q&A 2
  • 3. Introduction 3
  • 4. What is server push1.Notifications Unread messages2. Message and Chat 3. Message wall ,history messages
  • 5. Ajax V.S Comet• Ajax – When user trigged (mouseover or click…) or using “Periodic Refresh” to check data update.• Comet – Let browser and server connect on a long-request. – Server can send data to client, client doesnt have to send request first.
  • 6. Ajax V.S Comet
  • 7. Websocket• WebSocket is a web technology providing full- duplex communications channels over a single TCP connection.• The WebSocket protocol makes possible more interaction between a browser and a web site. 7
  • 8. Technical survey 8
  • 9. Push server compare Payment & Support OS Scalability Complexity NOTE Open Source WIN 、 MA Limit For Ajax PushStream Hub C 、 Linux No Low Free Server 、 Solaris 、 Unix Windows websocketNode.js Mac OS Yes Medium Free Web service LinuxAjax Push Linux, BSD Ajax push No Low Free(APE) & Mac OS Server Windows websocketRabbit MQ Linux , Mac Yes Low Free Web OS Service
  • 10. Push server• Stream Hub – Light and quick Comet Server• Node.js – Base on Google Chrome V8 JavaScript engine. – The fastest JavaScript engine – Design for “Comet(long pulling) Request Server” and capable to handle massive message exchange. • Ajax Push (Ajax Push Engine) – Apply for Comet(long pulling) Request Server and easy to setup. – Base on Node.js
  • 11. Node.js• Pro – Build for Web Push . – Java Script Engine (Event Driven) quick and light. – Hottest technology now. – Could provide multi-service in future. – Modules support.• Cons – NodeJS is just a base engine, Still need to develop a whole service. – Stable need to test for porting on the machine.
  • 12. Rabbit MQ• Robust messaging for applications.• Easy to use Runs on all major operating systems.• Supports a huge number of developer platforms.• Open source and commercially supported.• Base on Advanced Message Queuing Protocol (AMQP) 12
  • 13. Node.js VS. Rabbit MQ• Node .js – 優點 : • 在 server 和 client 間建立 socket 容易 • 高效率 – 缺點 : • 需要自己管理 connection 及自己做 routing• RabbitMQ – 優點 : • subscribe/publish/broadcasting ,三個願望一次滿足 • 有實做一套 memory monitor 的機制 • 提供資料保存 提高了訊息的傳送可靠性 • 安全性較高 – 缺點 : • 消耗資源較大 • 使用 Erlang 撰寫,維護原碼 effort 較高
  • 14. AMQPAdvanced Message Queuing Protocol 14
  • 15. The AMQP The Advanced Message Queuing Protocol (AMQP) is an open standardapplication layer protocol for message-oriented middleware. The defining features of AMQP are message orientation, queuing, routing(including point-to-point and publish-and-subscribe), reliability and security. 15 15
  • 16. AMQP protocol• AMQP ( 高級消息隊列協議 ) – 異步消息傳遞所使用的應用層協議規範 – 生產者在產生消息之後,把消息發送到消息服務器 ,再由消息服務器發給消費者
  • 17. AMQP Server broker Channel Consumer• Message broker: a server to which AMQ clients connect using the AMQ protocol. Message brokers can run in a cluster but these details are implementation specific and are not covered by the specification.• Consumer: a user is an entity that, by providing credentials in form of a password, may or may not be authorized to connect to a broker.• Connection: a physical connection (e.g., using TCP/IP or SCTP). A connection is bound to a user.• Channel: a logical connection that is tied to a connection 17 17
  • 18. AMQP protocol• Advanced Message Queuing Protocol (AMQP) – virtual host • A host containes Exchange 、 Queue 、 Binding – Exchange • A message with with routing key – Message Queue • Keep message, and send it to message consumer – Binding • Message binding with routes rule ,例如,指明具有路由 鍵“ X” 的消息要到綁定的名稱隊列中
  • 19. AMQP Architecture
  • 20. Service exchange Personal messages
  • 21. Rabbit MQ 21
  • 22. RabbitMQ
  • 23. Native support• C• C#• Erlang• Java• Php• Python• Python-puka• Ruby 23
  • 24. 24
  • 25. Fanout Exchange
  • 26. Direct Exchange
  • 27. Topic Exchange
  • 28. Implement 28
  • 29. Push work flow1. Server create a message queue. (without binding user)2. Client connect to server and bind the queue. (connection established)3. Server send messages to queue.4. Client received messages from server. 29
  • 30. Three step for create connection1.Create connection factory.2.Create connection.3.Create channel.1. ConnectionFactory factory = new ConnectionFactory();2. factory.setHost("140.92.25.159");3. Connection connection = factory.newConnection();4. Channel channel = connection.createChannel(); Java example 30
  • 31. Send Message example1 String message “This is a message”;2 channel.basicPublish("", QUEUE_NAME, null, message.getBytes()); Java example 31
  • 32. For among consumers1 String message “This is a message”;2 channel.basic_publish(exchange=‘ , routing_key=hello, body=message) 32
  • 33. Message publish1 String message “This is a message”;2 channel.exchange_declare(exchange=logs, type=fanout)2 channel.basic_publish(exchange=‘ , routing_key=hello, body=message) 33
  • 34. Routing message 34
  • 35. 1 String message “This is a message”;2 channel.queue_bind(exchange=exchange_name, queue=queue_name, routing_key=black)3 channel.exchange_declare(exchange=direct_logs, type=direct)4 channel.basic_publish(exchange=‘direct_logs’, routing_key=severity, body=message) 35
  • 36. Pattern message 36
  • 37. Routing RuleRouting rule= Domain. ID• # one section matched• * any sectionExample : Name Cosa.user.id156486 Cosa.group Routing Cosa.* O O Cosa.# X O 37 37
  • 38. 1 String message “This is a message”;2 channel.queue_bind(exchange=exchange_name, queue=queue_name, routing_key=‘*.black.#’) 38
  • 39. PRC 39
  • 40. 1 String message “This is a message”;2 ch.basic_publish(exchange=, routing_key=props.reply_to,properties=pika.BasicProperties(correlation_id = props.correlation_id), body=str(response))3 ch.basic_ack(delivery_tag) 40
  • 41. Web Service Post• Provide web push function thought web service. Var Description Type Domain *Domain Name String ExName *Exchange Name String ID ID String (null for broadcast) Msg *Message String Durable Durable Bool (Default False) Ack No Ack require Bool (Default True) Auth *Authentication String (Get form SSO) * Required 42 42
  • 42. Web Service Response Code• Response code Var Description 200 Message sant 401 Not authorize. 404 Domain or exchange not exist 406 Not Acceptable 500 Service is busy or maintain. * Required 43 43
  • 43. ‹#›
  • 44. Summary• Push server is … – A style of Internet-based communication where the request for a given transaction is initiated by the publisher or central server.• Rabbit MQ is – Aopen source message broker software (i.e., message-oriented middleware) that implements the Advanced Message Queuing Protocol (AMQP) standard. 45
  • 45. Q&AThank you. 46