+ All Categories
Home > Documents > Rabbit MQ introduction

Rabbit MQ introduction

Date post: 10-May-2015
Category:
Upload: sitg-yao
View: 1,392 times
Download: 9 times
Share this document with a friend
Description:
10/26 於南台資工系
Popular Tags:
46
Rabbit MQ Cloud System Software Institute Institute for Information Industry 1
Transcript
Page 1: Rabbit MQ introduction

Rabbit MQ

Cloud System Software Institute

Institute for Information Industry

1

Page 2: Rabbit MQ introduction

Outline

• Introduction

• Technical survey

• AMQP

• Rabbit MQ

• Implement

• Q&A

2

Page 3: Rabbit MQ introduction

Introduction

3

Page 4: Rabbit MQ introduction

What is server push

3. Message wall ,history messages

1.Notifications

2. Message and Chat

Unread messages

Page 5: Rabbit MQ introduction

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.

Page 6: Rabbit MQ introduction

Ajax V.S Comet

Page 7: Rabbit MQ introduction

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

Page 8: Rabbit MQ introduction

Technical survey

8

Page 9: Rabbit MQ introduction

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

Page 10: Rabbit MQ introduction

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

Page 11: Rabbit MQ introduction

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.

Page 12: Rabbit MQ introduction

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

Page 13: Rabbit MQ introduction

Node.js VS. Rabbit MQ

• Node .js– 優點 :

• 在 server 和 client 間建立 socket 容易• 高效率

– 缺點 :• 需要自己管理 connection 及自己做 routing

• RabbitMQ– 優點 :

• subscribe/publish/broadcasting ,三個願望一次滿足• 有實做一套 memory monitor 的機制• 提供資料保存 提高了訊息的傳送可靠性• 安全性較高

– 缺點 :• 消耗資源較大• 使用 Erlang 撰寫,維護原碼 effort 較高

Page 14: Rabbit MQ introduction

AMQPAdvanced Message Queuing Protocol

14

Page 15: Rabbit MQ introduction

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

Page 16: Rabbit MQ introduction

AMQP protocol

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

Page 17: Rabbit MQ introduction

• 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

Page 18: Rabbit MQ introduction

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” 的消息要到綁定的名稱隊列中

Page 19: Rabbit MQ introduction

AMQP Architecture

Page 20: Rabbit MQ introduction

Personal messagesService exchange

Page 21: Rabbit MQ introduction

Rabbit MQ

21

Page 22: Rabbit MQ introduction

RabbitMQ

Page 23: Rabbit MQ introduction

Native support

• C

• C#

• Erlang

• Java

• Php

• Python

• Python-puka

• Ruby

23

Page 24: Rabbit MQ introduction

24

Page 25: Rabbit MQ introduction

Fanout Exchange

Page 26: Rabbit MQ introduction

Direct Exchange

Page 27: Rabbit MQ introduction

Topic Exchange

Page 28: Rabbit MQ introduction

Implement

28

Page 29: Rabbit MQ introduction

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

Page 30: Rabbit MQ introduction

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

Page 31: Rabbit MQ introduction

Send Message example

1 String message “This is a message”;

2 channel.basicPublish("", QUEUE_NAME, null, message.getBytes());

Java example

31

Page 32: Rabbit MQ introduction

For among consumers

32

1 String message “This is a message”;

2 channel.basic_publish(exchange=‘ ', routing_key='hello', body=message)

Page 33: Rabbit MQ introduction

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)

Page 34: Rabbit MQ introduction

Routing message

34

Page 35: Rabbit MQ introduction

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)

Page 36: Rabbit MQ introduction

Pattern message

36

Page 37: Rabbit MQ introduction

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

Page 38: Rabbit MQ introduction

38

1 String message “This is a message”;

2 channel.queue_bind(exchange=exchange_name,

queue=queue_name, routing_key=‘*.black.#’)

Page 39: Rabbit MQ introduction

PRC

39

Page 40: Rabbit MQ introduction

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)

Page 41: Rabbit MQ introduction
Page 42: Rabbit MQ introduction

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

Page 43: Rabbit MQ introduction

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

Page 44: Rabbit MQ introduction

‹#›

Page 45: Rabbit MQ introduction

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

Page 46: Rabbit MQ introduction

Q & A

Thank you.

46


Recommended