SlideShare a Scribd company logo
1 of 46
Rabbit MQ



Cloud System Software Institute
Institute for Information Industry

                1
Outline
•   Introduction
•   Technical survey
•   AMQP
•   Rabbit MQ
•   Implement
•   Q&A




                          2
Introduction




     3
What is server push

1.Notifications

                                         Unread
                                        messages
2. Message and Chat




  3. Message wall ,history messages
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 doesn't have
    to send request first.
Ajax V.S Comet
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
Technical survey




       8
Push server compare
                                                       Payment &
             Support OS    Scalability   Complexity                    NOTE
                                                      Open Source

             WIN 、 MA
                                                       Limit For     Ajax Push
Stream Hub   C 、 Linux         No           Low
                                                         Free         Server
             、 Solaris

             、 Unix
             Windows
                                                                    websocket
Node.js      Mac OS           Yes         Medium         Free
                                                                    Web service
              Linux

Ajax Push    Linux, BSD                                              Ajax push
                               No           Low          Free
(APE)        & Mac OS                                                 Server

              Windows                                               websocket
Rabbit MQ    Linux , Mac      Yes           Low          Free         Web
                 OS                                                  Service
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
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.
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
Node.js VS. Rabbit MQ
• Node .js
  – 優點 :
     • 在 server 和 client 間建立 socket 容易
     • 高效率
  – 缺點 :
     • 需要自己管理 connection 及自己做 routing
• RabbitMQ
  – 優點 :
     •   subscribe/publish/broadcasting ,三個願望一次滿足
     •   有實做一套 memory monitor 的機制
     •   提供資料保存 提高了訊息的傳送可靠性
     •   安全性較高
  – 缺點 :
     • 消耗資源較大
     • 使用 Erlang 撰寫,維護原碼 effort 較高
AMQP
Advanced Message Queuing Protocol




               14
The AMQP




  The Advanced Message Queuing Protocol (AMQP) is an open standard
application 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
AMQP protocol
• AMQP ( 高級消息隊列協議 )
 – 異步消息傳遞所使用的應用層協議規範
 – 生產者在產生消息之後,把消息發送到消息服務器
   ,再由消息服務器發給消費者
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
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” 的消息要到綁定的名稱隊列中
AMQP Architecture
Service exchange   Personal messages
Rabbit MQ




   21
RabbitMQ
Native support
•   C
•   C#
•   Erlang
•   Java
•   Php
•   Python
•   Python-puka
•   Ruby

                  23
24
Fanout Exchange
Direct Exchange
Topic Exchange
Implement




   28
Push work flow
1. 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
Three step for create connection
1.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
Send Message example




1 String message “This is a message”;
2 channel.basicPublish("", QUEUE_NAME, null, message.getBytes());




                                                           Java example
                                     31
For among consumers




1 String message “This is a message”;
2 channel.basic_publish(exchange=‘ ', routing_key='hello', body=message)




                                     32
Message publish




1 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
Routing message




       34
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
Pattern message




       36
Routing Rule

Routing rule= Domain. ID
• # one section matched
• * any section

Example :
                        Name   Cosa.user.id156486   Cosa.group
     Routing
               Cosa.*                  O                O

               Cosa.#                  X                O



                                                                 37
                                           37
1 String message “This is a message”;
2 channel.queue_bind(exchange=exchange_name,
 queue=queue_name, routing_key=‘*.black.#’)




                            38
PRC




 39
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
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
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
‹#›
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
Q&A

Thank you.




    46

More Related Content

What's hot

The RabbitMQ Message Broker
The RabbitMQ Message BrokerThe RabbitMQ Message Broker
The RabbitMQ Message BrokerMartin Toshev
 
Messaging Standards and Systems - AMQP & RabbitMQ
Messaging Standards and Systems - AMQP & RabbitMQMessaging Standards and Systems - AMQP & RabbitMQ
Messaging Standards and Systems - AMQP & RabbitMQPOSSCON
 
[@NaukriEngineering] Messaging Queues
[@NaukriEngineering] Messaging Queues[@NaukriEngineering] Messaging Queues
[@NaukriEngineering] Messaging QueuesNaukri.com
 
Messaging Standards and Systems - AMQP & RabbitMQ
Messaging Standards and Systems - AMQP & RabbitMQMessaging Standards and Systems - AMQP & RabbitMQ
Messaging Standards and Systems - AMQP & RabbitMQAll Things Open
 
Messaging with RabbitMQ and AMQP
Messaging with RabbitMQ and AMQPMessaging with RabbitMQ and AMQP
Messaging with RabbitMQ and AMQPEberhard Wolff
 
An update from the RabbitMQ team - Michael Klishin
An update from the RabbitMQ team - Michael KlishinAn update from the RabbitMQ team - Michael Klishin
An update from the RabbitMQ team - Michael KlishinRabbitMQ Summit
 
Distributed messaging with AMQP
Distributed messaging with AMQPDistributed messaging with AMQP
Distributed messaging with AMQPWee Keat Chin
 
A walk-through of the design and architecture of RabbitMQ - Ayanda Dube
A walk-through of the design and architecture of RabbitMQ - Ayanda DubeA walk-through of the design and architecture of RabbitMQ - Ayanda Dube
A walk-through of the design and architecture of RabbitMQ - Ayanda DubeRabbitMQ Summit
 
Introduction To RabbitMQ
Introduction To RabbitMQIntroduction To RabbitMQ
Introduction To RabbitMQKnoldus Inc.
 
XMPP & AMQP
XMPP & AMQPXMPP & AMQP
XMPP & AMQPvoluntas
 
Messaging with amqp and rabbitmq
Messaging with amqp and rabbitmqMessaging with amqp and rabbitmq
Messaging with amqp and rabbitmqSelasie Hanson
 
RabbitMQ fairly-indepth
RabbitMQ fairly-indepthRabbitMQ fairly-indepth
RabbitMQ fairly-indepthWee Keat Chin
 
The Future of Messaging: RabbitMQ and AMQP
The Future of Messaging: RabbitMQ and AMQP The Future of Messaging: RabbitMQ and AMQP
The Future of Messaging: RabbitMQ and AMQP Eberhard Wolff
 

What's hot (20)

AMQP with RabbitMQ
AMQP with RabbitMQAMQP with RabbitMQ
AMQP with RabbitMQ
 
The RabbitMQ Message Broker
The RabbitMQ Message BrokerThe RabbitMQ Message Broker
The RabbitMQ Message Broker
 
RabbitMQ & Hutch
RabbitMQ & HutchRabbitMQ & Hutch
RabbitMQ & Hutch
 
Messaging Standards and Systems - AMQP & RabbitMQ
Messaging Standards and Systems - AMQP & RabbitMQMessaging Standards and Systems - AMQP & RabbitMQ
Messaging Standards and Systems - AMQP & RabbitMQ
 
AMQP for phpMelb
AMQP for phpMelbAMQP for phpMelb
AMQP for phpMelb
 
[@NaukriEngineering] Messaging Queues
[@NaukriEngineering] Messaging Queues[@NaukriEngineering] Messaging Queues
[@NaukriEngineering] Messaging Queues
 
Messaging Standards and Systems - AMQP & RabbitMQ
Messaging Standards and Systems - AMQP & RabbitMQMessaging Standards and Systems - AMQP & RabbitMQ
Messaging Standards and Systems - AMQP & RabbitMQ
 
Messaging with RabbitMQ and AMQP
Messaging with RabbitMQ and AMQPMessaging with RabbitMQ and AMQP
Messaging with RabbitMQ and AMQP
 
An update from the RabbitMQ team - Michael Klishin
An update from the RabbitMQ team - Michael KlishinAn update from the RabbitMQ team - Michael Klishin
An update from the RabbitMQ team - Michael Klishin
 
Distributed messaging with AMQP
Distributed messaging with AMQPDistributed messaging with AMQP
Distributed messaging with AMQP
 
Amqp Basic
Amqp BasicAmqp Basic
Amqp Basic
 
A walk-through of the design and architecture of RabbitMQ - Ayanda Dube
A walk-through of the design and architecture of RabbitMQ - Ayanda DubeA walk-through of the design and architecture of RabbitMQ - Ayanda Dube
A walk-through of the design and architecture of RabbitMQ - Ayanda Dube
 
Spring RabbitMQ
Spring RabbitMQSpring RabbitMQ
Spring RabbitMQ
 
Introduction To RabbitMQ
Introduction To RabbitMQIntroduction To RabbitMQ
Introduction To RabbitMQ
 
XMPP & AMQP
XMPP & AMQPXMPP & AMQP
XMPP & AMQP
 
Messaging with amqp and rabbitmq
Messaging with amqp and rabbitmqMessaging with amqp and rabbitmq
Messaging with amqp and rabbitmq
 
A Closer Look at RabbitMQ
A Closer Look at RabbitMQA Closer Look at RabbitMQ
A Closer Look at RabbitMQ
 
What is RabbitMQ ?
What is RabbitMQ ?What is RabbitMQ ?
What is RabbitMQ ?
 
RabbitMQ fairly-indepth
RabbitMQ fairly-indepthRabbitMQ fairly-indepth
RabbitMQ fairly-indepth
 
The Future of Messaging: RabbitMQ and AMQP
The Future of Messaging: RabbitMQ and AMQP The Future of Messaging: RabbitMQ and AMQP
The Future of Messaging: RabbitMQ and AMQP
 

Viewers also liked

MSMQ - Microsoft Message Queueing
MSMQ - Microsoft Message QueueingMSMQ - Microsoft Message Queueing
MSMQ - Microsoft Message QueueingPeter R. Egli
 
Things i wished i knew as a junior developer
Things i wished i knew as a junior developerThings i wished i knew as a junior developer
Things i wished i knew as a junior developerGeshan Manandhar
 
Message Queues a basic overview
Message Queues a basic overviewMessage Queues a basic overview
Message Queues a basic overviewGeshan Manandhar
 

Viewers also liked (6)

MSMQ - Microsoft Message Queueing
MSMQ - Microsoft Message QueueingMSMQ - Microsoft Message Queueing
MSMQ - Microsoft Message Queueing
 
Jms
JmsJms
Jms
 
Things i wished i knew as a junior developer
Things i wished i knew as a junior developerThings i wished i knew as a junior developer
Things i wished i knew as a junior developer
 
Message Queues a basic overview
Message Queues a basic overviewMessage Queues a basic overview
Message Queues a basic overview
 
Coding Culture
Coding CultureCoding Culture
Coding Culture
 
How Google Works
How Google WorksHow Google Works
How Google Works
 

Similar to Rabbit MQ introduction

Architectures with Windows Azure
Architectures with Windows AzureArchitectures with Windows Azure
Architectures with Windows AzureDamir Dobric
 
quickguide-einnovator-3-rabbitmq
quickguide-einnovator-3-rabbitmqquickguide-einnovator-3-rabbitmq
quickguide-einnovator-3-rabbitmqjorgesimao71
 
OpenStack Quantum: Cloud Carrier Summit 2012
OpenStack Quantum: Cloud Carrier Summit 2012OpenStack Quantum: Cloud Carrier Summit 2012
OpenStack Quantum: Cloud Carrier Summit 2012Dan Wendlandt
 
Quantum for Cloud Operators - Folsom Conference
Quantum for Cloud Operators  - Folsom Conference Quantum for Cloud Operators  - Folsom Conference
Quantum for Cloud Operators - Folsom Conference Dan Wendlandt
 
Architecture | The Future of Messaging: RabbitMQ and AMQP | Eberhard Wolff
Architecture | The Future of Messaging: RabbitMQ and AMQP | Eberhard WolffArchitecture | The Future of Messaging: RabbitMQ and AMQP | Eberhard Wolff
Architecture | The Future of Messaging: RabbitMQ and AMQP | Eberhard WolffJAX London
 
Quantum grizzly summit
Quantum   grizzly summitQuantum   grizzly summit
Quantum grizzly summitDan Wendlandt
 
Quantum PTL Update - Grizzly Summit.pptx
Quantum PTL Update - Grizzly Summit.pptxQuantum PTL Update - Grizzly Summit.pptx
Quantum PTL Update - Grizzly Summit.pptxOpenStack Foundation
 
Openstack Quantum yahoo meetup 1 23-13
Openstack Quantum yahoo meetup 1 23-13Openstack Quantum yahoo meetup 1 23-13
Openstack Quantum yahoo meetup 1 23-13Dan Wendlandt
 
Quantum Folsom Summit Developer Overview
Quantum Folsom Summit Developer OverviewQuantum Folsom Summit Developer Overview
Quantum Folsom Summit Developer OverviewDan Wendlandt
 
OpenStack Quantum Intro (OS Meetup 3-26-12)
OpenStack Quantum Intro (OS Meetup 3-26-12)OpenStack Quantum Intro (OS Meetup 3-26-12)
OpenStack Quantum Intro (OS Meetup 3-26-12)Dan Wendlandt
 
RabbitMQ and AMQP with .net client library
RabbitMQ and AMQP with .net client libraryRabbitMQ and AMQP with .net client library
RabbitMQ and AMQP with .net client libraryMohammed Shaban
 
Testing the limits of cloud networks
Testing the limits of cloud networksTesting the limits of cloud networks
Testing the limits of cloud networksPLUMgrid
 
Real time websites and mobile apps with SignalR
Real time websites and mobile apps with SignalRReal time websites and mobile apps with SignalR
Real time websites and mobile apps with SignalRRoy Cornelissen
 
Messaging for Modern Applications
Messaging for Modern ApplicationsMessaging for Modern Applications
Messaging for Modern ApplicationsTom McCuch
 
CloudStack Overview
CloudStack OverviewCloudStack Overview
CloudStack Overviewsedukull
 
Agile OpenStack Networking with Cisco Solutions
Agile OpenStack Networking with Cisco SolutionsAgile OpenStack Networking with Cisco Solutions
Agile OpenStack Networking with Cisco SolutionsCisco DevNet
 
Commication Framework in OpenStack
Commication Framework in OpenStackCommication Framework in OpenStack
Commication Framework in OpenStackSean Chang
 

Similar to Rabbit MQ introduction (20)

Architectures with Windows Azure
Architectures with Windows AzureArchitectures with Windows Azure
Architectures with Windows Azure
 
quickguide-einnovator-3-rabbitmq
quickguide-einnovator-3-rabbitmqquickguide-einnovator-3-rabbitmq
quickguide-einnovator-3-rabbitmq
 
OpenStack Quantum: Cloud Carrier Summit 2012
OpenStack Quantum: Cloud Carrier Summit 2012OpenStack Quantum: Cloud Carrier Summit 2012
OpenStack Quantum: Cloud Carrier Summit 2012
 
Quantum for Cloud Operators - Folsom Conference
Quantum for Cloud Operators  - Folsom Conference Quantum for Cloud Operators  - Folsom Conference
Quantum for Cloud Operators - Folsom Conference
 
Architecture | The Future of Messaging: RabbitMQ and AMQP | Eberhard Wolff
Architecture | The Future of Messaging: RabbitMQ and AMQP | Eberhard WolffArchitecture | The Future of Messaging: RabbitMQ and AMQP | Eberhard Wolff
Architecture | The Future of Messaging: RabbitMQ and AMQP | Eberhard Wolff
 
Quantum grizzly summit
Quantum   grizzly summitQuantum   grizzly summit
Quantum grizzly summit
 
Quantum PTL Update - Grizzly Summit.pptx
Quantum PTL Update - Grizzly Summit.pptxQuantum PTL Update - Grizzly Summit.pptx
Quantum PTL Update - Grizzly Summit.pptx
 
Spring integration
Spring integrationSpring integration
Spring integration
 
Openstack Quantum yahoo meetup 1 23-13
Openstack Quantum yahoo meetup 1 23-13Openstack Quantum yahoo meetup 1 23-13
Openstack Quantum yahoo meetup 1 23-13
 
Quantum Folsom Summit Developer Overview
Quantum Folsom Summit Developer OverviewQuantum Folsom Summit Developer Overview
Quantum Folsom Summit Developer Overview
 
OpenStack Quantum Intro (OS Meetup 3-26-12)
OpenStack Quantum Intro (OS Meetup 3-26-12)OpenStack Quantum Intro (OS Meetup 3-26-12)
OpenStack Quantum Intro (OS Meetup 3-26-12)
 
RabbitMQ and AMQP with .net client library
RabbitMQ and AMQP with .net client libraryRabbitMQ and AMQP with .net client library
RabbitMQ and AMQP with .net client library
 
Testing the limits of cloud networks
Testing the limits of cloud networksTesting the limits of cloud networks
Testing the limits of cloud networks
 
Messaging in Java
Messaging in JavaMessaging in Java
Messaging in Java
 
WMQ, WMB and EIP
WMQ, WMB and EIPWMQ, WMB and EIP
WMQ, WMB and EIP
 
Real time websites and mobile apps with SignalR
Real time websites and mobile apps with SignalRReal time websites and mobile apps with SignalR
Real time websites and mobile apps with SignalR
 
Messaging for Modern Applications
Messaging for Modern ApplicationsMessaging for Modern Applications
Messaging for Modern Applications
 
CloudStack Overview
CloudStack OverviewCloudStack Overview
CloudStack Overview
 
Agile OpenStack Networking with Cisco Solutions
Agile OpenStack Networking with Cisco SolutionsAgile OpenStack Networking with Cisco Solutions
Agile OpenStack Networking with Cisco Solutions
 
Commication Framework in OpenStack
Commication Framework in OpenStackCommication Framework in OpenStack
Commication Framework in OpenStack
 

More from Sitg Yao

2011 0616 老闆要我來報告
2011 0616 老闆要我來報告2011 0616 老闆要我來報告
2011 0616 老闆要我來報告Sitg Yao
 
Azure overview for it pros
Azure overview for it prosAzure overview for it pros
Azure overview for it prosSitg Yao
 
2012 0521 雲端產業介紹 簡報
2012 0521 雲端產業介紹  簡報2012 0521 雲端產業介紹  簡報
2012 0521 雲端產業介紹 簡報Sitg Yao
 
2012 雲端產業介紹
2012 雲端產業介紹2012 雲端產業介紹
2012 雲端產業介紹Sitg Yao
 
111102 dicom viewer_softwareintro
111102 dicom viewer_softwareintro111102 dicom viewer_softwareintro
111102 dicom viewer_softwareintroSitg Yao
 
120720 cosa software intro
120720 cosa software intro120720 cosa software intro
120720 cosa software introSitg Yao
 

More from Sitg Yao (7)

2011 0616 老闆要我來報告
2011 0616 老闆要我來報告2011 0616 老闆要我來報告
2011 0616 老闆要我來報告
 
Azure overview for it pros
Azure overview for it prosAzure overview for it pros
Azure overview for it pros
 
2012 0521 雲端產業介紹 簡報
2012 0521 雲端產業介紹  簡報2012 0521 雲端產業介紹  簡報
2012 0521 雲端產業介紹 簡報
 
Git教學
Git教學Git教學
Git教學
 
2012 雲端產業介紹
2012 雲端產業介紹2012 雲端產業介紹
2012 雲端產業介紹
 
111102 dicom viewer_softwareintro
111102 dicom viewer_softwareintro111102 dicom viewer_softwareintro
111102 dicom viewer_softwareintro
 
120720 cosa software intro
120720 cosa software intro120720 cosa software intro
120720 cosa software intro
 

Rabbit MQ introduction

  • 1. Rabbit MQ Cloud System Software Institute Institute for Information Industry 1
  • 2. Outline • Introduction • Technical survey • AMQP • Rabbit MQ • Implement • Q&A 2
  • 4. What is server push 1.Notifications Unread messages 2. 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 doesn't have to send request first.
  • 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
  • 9. Push server compare Payment & Support OS Scalability Complexity NOTE Open Source WIN 、 MA Limit For Ajax Push Stream Hub C 、 Linux No Low Free Server 、 Solaris 、 Unix Windows websocket Node.js Mac OS Yes Medium Free Web service Linux Ajax Push Linux, BSD Ajax push No Low Free (APE) & Mac OS Server Windows websocket Rabbit 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 較高
  • 15. The AMQP The Advanced Message Queuing Protocol (AMQP) is an open standard application 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” 的消息要到綁定的名稱隊列中
  • 20. Service exchange Personal messages
  • 21. Rabbit MQ 21
  • 23. Native support • C • C# • Erlang • Java • Php • Python • Python-puka • Ruby 23
  • 24. 24
  • 28. Implement 28
  • 29. Push work flow 1. 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 connection 1.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 example 1 String message “This is a message”; 2 channel.basicPublish("", QUEUE_NAME, null, message.getBytes()); Java example 31
  • 32. For among consumers 1 String message “This is a message”; 2 channel.basic_publish(exchange=‘ ', routing_key='hello', body=message) 32
  • 33. Message publish 1 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
  • 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
  • 37. Routing Rule Routing rule= Domain. ID • # one section matched • * any section Example : 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
  • 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.
  • 42. 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
  • 43. 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
  • 45. 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

Editor's Notes

  1. 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 也要開始節省使用
  2. 面向消息的中間件 ( MOM )系統,例如發布 / 訂閱隊列,沒有作為基本元素實現。反而通過發送簡化的 AMQ 實體,用戶被賦予了構建例如這些實體的能力
  3. 如果需要 禁止 A 組訪問 B 組的交換機 / 隊列 / 綁定 , 必須為 A 和 B 分別創建一個虛擬主機 。每一個 RabbitMQ 服務器都有一個默認的虛擬主機“ /” 。如果這就夠了,那現在就可以開始了。 你的 消費者程序要負責創建你的交換機們 (複數) 。啥?你是說你可以有多個交換機?是的,這個可以有,不過為啥?很簡單,每個交換機在自己獨立的進程當中執行,因此增加多個交換機就是增加多個進程,可以充分利用服務器上的 CPU 核以便達到更高的效率。例如,在一個 8 核的服務器上,可以創建 5 個交換機來用 5 個核,另外 3 個核留下來做消息處理。類似的,在 RabbitMQ 的集群當中,你可以用類似的思路來擴展交換機一邊獲取更高的吞吐量。 一個綁定就是一個基於路由鍵將交換機和隊列連接起來的路由規則。
  4. https://github.com/alanxz/rabbitmq-c
  5. http://140.92.25.159:55672/#/ guest guest
  6. 交換機不過就是一個由綁定構成的路由表。 現在復雜的東西來了:交換機有多種類型。他們都是做路由的,不過接受不同類型的綁定。為什麼不創建一種交換機來處理所有類型的路由規則呢?因為每種規則用來做匹配分子的 CPU 開銷是不同的。例如,一個“ topic” 類型的交換機試圖將消息的路由鍵與類似“ dogs.* ” 的模式進行匹配。匹配這種末端的通配符比直接將路由鍵與“ dogs ” 比較(“ direct” 類型的交換機)要消耗更多的 CPU 。如果你不需要“ topic” 類型的交換機帶來的靈活性,你可以通過使用“ direct” 類型的交換機獲取更高的處理效率。 不處理路由鍵。你只需要簡單的將隊列綁定到交換機上。一個發送到交換機的消息都會被轉發到與該交換機綁定的所有隊列上。很像子網廣播,每台子網內的主機都獲得了一份複製的消息。 Fanout 交換機轉發消息是最快的。
  7. 處理路由鍵。需要將一個隊列綁定到交換機上,要求該消息與一個特定的路由鍵完全匹配。這是一個完整的匹配。如果一個隊列綁定到該交換機上要求路由鍵“ dog” ,則只有被標記為“ dog ” 的消息才被轉發,不會轉發 dog.puppy ,也不會轉發 dog.guard ,只會轉發 dog 。手機申
  8. 將路由鍵和某模式進行匹配。此時隊列需要綁定要一個模式上。符號“ #” 匹配一個或多個詞,符號“ *” 匹配不多不少一個詞。因此“ audit.#” 能夠匹配到“ audit.irs.corporate ” ,但是“ audit.* ” 只會匹配到“ audit.irs ” 。
  9. http://www.vmware.com/products/application-platform/vfabric-rabbitmq/overview.html