Rabbit MQ introduction

jpstjeffyao 2,088 views 46 slides Oct 31, 2012
Slide 1
Slide 1 of 46
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28
Slide 29
29
Slide 30
30
Slide 31
31
Slide 32
32
Slide 33
33
Slide 34
34
Slide 35
35
Slide 36
36
Slide 37
37
Slide 38
38
Slide 39
39
Slide 40
40
Slide 41
41
Slide 42
42
Slide 43
43
Slide 44
44
Slide 45
45
Slide 46
46

About This Presentation

10/26 於南台資工系


Slide Content

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
3. Message wall ,history messages
1.Notifications
2. Message and Chat
Unread
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
Support OS Scalability Complexity
Payment &
Open Source
NOTE
Stream Hub
WIN、MA
C、Linux
、Solaris
、Unix
No Low
Limit For
Free
Ajax Push
Server
Node.js
Windows
Mac OS
Linux
Yes Medium Free
websocket
Web service
Ajax Push
(APE)
Linux, BSD
& Mac OS
No Low Free
Ajax push
Server
Rabbit MQ
Windows
Linux , Mac
OS
Yes Low Free
websocket
Web
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 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.
The AMQP
15
15

AMQP protocol
• AMQP (高級消息隊列協議 )
–異步消息傳遞所使用的應用層協議規範
–生產者在產生消息之後,把消息發送到消息服務器
,再由消息服務器發給消費者

•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
broker
Consumer
Channel
AMQP Server
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

Personal messagesService exchange

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
32
1 String message “This is a message”;
2 channel.basic_publish(exchange=‘ ', routing_key='hello', body=message)

Message publish
33
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)

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)

Pattern message
36

Routing Rule
Routing rule= Domain. ID
•# one section matched
•* any section
Example :
Name
Routing
Cosa.user.id156486 Cosa.group
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.#’)

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)

Web Service Post
•Provide web push function thought web service.
Var Description Type
Domain *Domain Name String
ExName *Exchange Name String
ID
(null for broadcast)
ID String
Msg *Message String
Durable
(Default False)
Durable Bool
Ack
(Default True)
No Ack require Bool
Auth *Authentication
(Get form SSO)
String
* Required
42
42

Web Service 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
•Response code
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
Tags