rabbit mq introduction

Post on 10-May-2015

1.395 Views

Category:

Documents

9 Downloads

Preview:

Click to see full reader

DESCRIPTION

10/26 於南台資工系

TRANSCRIPT

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 ComplexityPayment &

Open SourceNOTE

Stream Hub

WIN 、 MAC 、 Linux 、Solaris 、 U

nix

No LowLimit For

FreeAjax Push

Server

Node.js Windows Mac OS

LinuxYes Medium Free

websocketWeb service

Ajax Push (APE)

Linux, BSD & Mac OS

No Low FreeAjax push

Server

Rabbit MQWindows

Linux , Mac OS

Yes Low Freewebsocket

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 較高

AMQPAdvanced 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 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

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

top related