Rabbit mq messaginginthecloud_v_mworld_2010_ms

79
ADD-01 RabbitMQ: Messaging in the Cloud Matthew Sackman [email protected]

Transcript of Rabbit mq messaginginthecloud_v_mworld_2010_ms

Page 1: Rabbit mq messaginginthecloud_v_mworld_2010_ms

ADD-01

RabbitMQ: Messaging in the Cloud

Matthew [email protected]

Page 2: Rabbit mq messaginginthecloud_v_mworld_2010_ms

I P

C . . .

I Messaging, messaging, messaging: What does it all mean?I What is this angular mutant orange Rabbit thing, and why is it

dropping AMQP all over the carpet?I How many balloons does it take to keep a Rabbit in a cloud?I Prizes! Prizes! Prizes!

Page 3: Rabbit mq messaginginthecloud_v_mworld_2010_ms

I P

C . . .I Messaging, messaging, messaging: What does it all mean?

I What is this angular mutant orange Rabbit thing, and why is itdropping AMQP all over the carpet?

I How many balloons does it take to keep a Rabbit in a cloud?I Prizes! Prizes! Prizes!

Page 4: Rabbit mq messaginginthecloud_v_mworld_2010_ms

I P

C . . .I Messaging, messaging, messaging: What does it all mean?I What is this angular mutant orange Rabbit thing, and why is it

dropping AMQP all over the carpet?

I How many balloons does it take to keep a Rabbit in a cloud?I Prizes! Prizes! Prizes!

Page 5: Rabbit mq messaginginthecloud_v_mworld_2010_ms

I P

C . . .I Messaging, messaging, messaging: What does it all mean?I What is this angular mutant orange Rabbit thing, and why is it

dropping AMQP all over the carpet?I How many balloons does it take to keep a Rabbit in a cloud?

I Prizes! Prizes! Prizes!

Page 6: Rabbit mq messaginginthecloud_v_mworld_2010_ms

I P

C . . .I Messaging, messaging, messaging: What does it all mean?I What is this angular mutant orange Rabbit thing, and why is it

dropping AMQP all over the carpet?I How many balloons does it take to keep a Rabbit in a cloud?I Prizes! Prizes! Prizes!

Page 7: Rabbit mq messaginginthecloud_v_mworld_2010_ms

W ?

M :I Scalability issues demand greater flexibility from application

developersI Traditional synchronous programming models fair poorly at

large scaleI Cloud computing permits greater dynamic scaling than ever

seen before, but applications need to be written well to takeadvantage of this

I Messaging enables scaling by decoupling components andadding flexibility

Page 8: Rabbit mq messaginginthecloud_v_mworld_2010_ms

RMQ CT R H

I Several cloud infrastructures have been built using RabbitMQas the nervous system of the cloud

I RabbitMQ is easily installed and used by clients on existingclouds such as Amazon EC2

I RabbitMQ is available as an additional component on HerokuI RabbitMQ is going to become available in more clouds in the

future, e.g. Social, Nebula, VMforceI RabbitMQ is just as easy to use to solve problems in clouds as it

is to solve problems on the ground

Page 9: Rabbit mq messaginginthecloud_v_mworld_2010_ms

W ?

What is Messaging?

What is a Banana?

Page 10: Rabbit mq messaginginthecloud_v_mworld_2010_ms

W ?

What is Messaging?What is a Banana?

Page 11: Rabbit mq messaginginthecloud_v_mworld_2010_ms

W ?

What can I use Messaging for?

What can I use a Banana for?

Page 12: Rabbit mq messaginginthecloud_v_mworld_2010_ms

W ?

What can I use Messaging for?What can I use a Banana for?

Page 13: Rabbit mq messaginginthecloud_v_mworld_2010_ms

W ?

What can I use a Messaging protocol for?

What can I use a Banana for?

Page 14: Rabbit mq messaginginthecloud_v_mworld_2010_ms

U M PI’ , ?

Decoupling

Producer Consumer

E.g. website passing orders to a credit-card charging engine

Page 15: Rabbit mq messaginginthecloud_v_mworld_2010_ms

U M PI’ , ?

Decoupling

Producer Consumer

E.g. website passing orders to a credit-card charging engine

Page 16: Rabbit mq messaginginthecloud_v_mworld_2010_ms

U M PI’ , ?

Bidirectional Decoupling

Caller Callee

E.g. remote procedure call

Page 17: Rabbit mq messaginginthecloud_v_mworld_2010_ms

U M PI’ , ?

Bidirectional Decoupling

Caller Callee

E.g. remote procedure call

Page 18: Rabbit mq messaginginthecloud_v_mworld_2010_ms

U M PI’ , ?

Pipelining and Decoupling

Producer Consumer

Producer

Consumer

E.g. combining messages with records in a database

Page 19: Rabbit mq messaginginthecloud_v_mworld_2010_ms

U M PI’ , ?

Pipelining and Decoupling

Producer Consumer

Producer

Consumer

E.g. combining messages with records in a database

Page 20: Rabbit mq messaginginthecloud_v_mworld_2010_ms

U M PI’ , ?

Pipelining and Decoupling

Producer ConsumerProducer

Consumer

E.g. combining messages with records in a database

Page 21: Rabbit mq messaginginthecloud_v_mworld_2010_ms

U M PI’ , ?

Pipelining and Decoupling

Producer ConsumerProducer

Consumer

E.g. combining messages with records in a database

Page 22: Rabbit mq messaginginthecloud_v_mworld_2010_ms

U M PI’ , ?

Work-distribution and Decoupling

Producer

Consumer

Consumer

Both duplication and round-robin.Duplication can be used for logging messages at certain points in

the system.Round-robin can be used for horizontal scaling.

Page 23: Rabbit mq messaginginthecloud_v_mworld_2010_ms

U M PI’ , ?

Work-distribution and Decoupling

Producer

Consumer

Consumer

Both duplication and round-robin.

Duplication can be used for logging messages at certain points inthe system.

Round-robin can be used for horizontal scaling.

Page 24: Rabbit mq messaginginthecloud_v_mworld_2010_ms

U M PI’ , ?

Work-distribution and Decoupling

Producer

Consumer

Consumer

Both duplication and round-robin.Duplication can be used for logging messages at certain points in

the system.Round-robin can be used for horizontal scaling.

Page 25: Rabbit mq messaginginthecloud_v_mworld_2010_ms

U M PI’ , ?

Work aggregation, distribution andDecoupling

Producer Consumer

ConsumerProducer

Page 26: Rabbit mq messaginginthecloud_v_mworld_2010_ms

U M PT I ’

O I Store-and-forward of messagesI Absorbing spikes of activity (again, decoupling)I Routing to different consumers based on message properties

G I Messaging protocols as a means of decoupling events is an

extremely common and pervasive taskI There is an enormous range of applications and problems to

which using a messaging protocol is an effective solution

Page 27: Rabbit mq messaginginthecloud_v_mworld_2010_ms

U M PT I ’

O I Store-and-forward of messagesI Absorbing spikes of activity (again, decoupling)I Routing to different consumers based on message properties

G I Messaging protocols as a means of decoupling events is an

extremely common and pervasive taskI There is an enormous range of applications and problems to

which using a messaging protocol is an effective solution

Page 28: Rabbit mq messaginginthecloud_v_mworld_2010_ms

AMQP

AMQP:Advanced Message Queueing Protocol

Page 29: Rabbit mq messaginginthecloud_v_mworld_2010_ms

W AMQP?I’ Advanced, !

AMQP . . .I All resources are dynamically created and destroyed by clients

as they need them – no static preconfigurationI A clean and simple model: just three key nouns to learnI Open standard, developed by the AMQP Working Group (we’re

members)I Lots of client libraries available in many languages, for free

I An excellent, freely available, open source brokerimplementation, called RabbitMQ. . .

Page 30: Rabbit mq messaginginthecloud_v_mworld_2010_ms

W AMQP?I’ Advanced, !

AMQP . . .I All resources are dynamically created and destroyed by clients

as they need them – no static preconfigurationI A clean and simple model: just three key nouns to learnI Open standard, developed by the AMQP Working Group (we’re

members)I Lots of client libraries available in many languages, for freeI An excellent, freely available, open source broker

implementation, called RabbitMQ. . .

Page 31: Rabbit mq messaginginthecloud_v_mworld_2010_ms

AMQP A != C

Create an exchange,. . .

X"my_exchange"

type = fanout

Page 32: Rabbit mq messaginginthecloud_v_mworld_2010_ms

AMQP A != C

. . . create a queue,. . .

X"my_exchange"

type = fanout"my_queue"

Page 33: Rabbit mq messaginginthecloud_v_mworld_2010_ms

AMQP A != C

. . . add a binding,. . .

X"my_exchange"

type = fanout"my_queue"

Page 34: Rabbit mq messaginginthecloud_v_mworld_2010_ms

AMQP A != C

. . . all inside a broker.

X"my_exchange"

type = fanout

"my_queue"

Page 35: Rabbit mq messaginginthecloud_v_mworld_2010_ms

AMQP A != C

Publish a message, . . .

it sits in a queue.

X"my_exchange"

type = fanout"my_queue"

msg

Page 36: Rabbit mq messaginginthecloud_v_mworld_2010_ms

AMQP A != C

Publish a message,

. . . it sits in a queue.

msgX"my_exchange"

type = fanout

"my_queue"

Page 37: Rabbit mq messaginginthecloud_v_mworld_2010_ms

AMQP A != C

Publish another message, . . .

it also goes to the queue.

msgX"my_exchange"

type = fanout"my_queue"

msg 2

Page 38: Rabbit mq messaginginthecloud_v_mworld_2010_ms

AMQP A != C

Publish another message,

. . . it also goes to the queue.

msg 2 msgX"my_exchange"

type = fanout

"my_queue"

Page 39: Rabbit mq messaginginthecloud_v_mworld_2010_ms

AMQP A != C

Consuming from the queue retrieves the messages in order.

msg 2 msgX"my_exchange"

type = fanout"my_queue"

Page 40: Rabbit mq messaginginthecloud_v_mworld_2010_ms

AMQP A != C

Consuming from the queue retrieves the messages in order.

msg 2X"my_exchange"

type = fanout"my_queue" msg

Page 41: Rabbit mq messaginginthecloud_v_mworld_2010_ms

AMQP A != C

Consuming from the queue retrieves the messages in order.

X"my_exchange"

type = fanout"my_queue" msg 2

Page 42: Rabbit mq messaginginthecloud_v_mworld_2010_ms

AMQP A != C

Publish many messages,. . .

and they are distributed amongst severalconsumers on the same queue.

X"my_exchange"

type = fanout

"my_queue"

ABCDEF

Page 43: Rabbit mq messaginginthecloud_v_mworld_2010_ms

AMQP A != C

Publish many messages,

. . . and they are distributed amongst severalconsumers on the same queue.

X"my_exchange"

type = fanout

"my_queue" F

E

D

C

B

A

Page 44: Rabbit mq messaginginthecloud_v_mworld_2010_ms

AMQP A != C

We can create a second queue and bind it to the same exchange.

"my_queue"

"my_queue_2"X"my_exchange"

type = fanout

Page 45: Rabbit mq messaginginthecloud_v_mworld_2010_ms

AMQP A != C

Messages go to every queue bound to a fanout exchange . . .

and thequeues can be consumed from at different rates.

"my_queue"

"my_queue_2"X"my_exchange"

type = fanout

ABC

Page 46: Rabbit mq messaginginthecloud_v_mworld_2010_ms

AMQP A != C

Messages go to every queue bound to a fanout exchange . . .

and thequeues can be consumed from at different rates.

ABC

ABC

"my_queue"

"my_queue_2"X"my_exchange"

type = fanout

Page 47: Rabbit mq messaginginthecloud_v_mworld_2010_ms

AMQP A != C

Messages go to every queue bound to a fanout exchange

. . . and thequeues can be consumed from at different rates.

C

ABC

"my_queue"

"my_queue_2"X"my_exchange"

type = fanout

AB

Page 48: Rabbit mq messaginginthecloud_v_mworld_2010_ms

AMQP A != C

Messages go to every queue bound to a fanout exchange

. . . and thequeues can be consumed from at different rates.

C

"my_queue"

"my_queue_2"X"my_exchange"

type = fanout

A

B

C

Page 49: Rabbit mq messaginginthecloud_v_mworld_2010_ms

AMQP A != C

Messages go to every queue bound to a fanout exchange

. . . and thequeues can be consumed from at different rates.

"my_queue"

"my_queue_2"X"my_exchange"

type = fanout

C

Page 50: Rabbit mq messaginginthecloud_v_mworld_2010_ms

AMQP A != C

We replace “my_exchange” with a direct exchange.

"my_queue"

"my_queue_2"X"my_exchange"

type = direct

bk = "vodka"

bk = "beer"

bk: Binding Keyrk: Routing Key

Page 51: Rabbit mq messaginginthecloud_v_mworld_2010_ms

AMQP A != C

The routing key of a published message selects which queues themessage goes to.

"my_queue"

"my_queue_2"X"my_exchange"

type = direct

bk = "vodka"

bk = "beer"

bk: Binding Keyrk: Routing Key

A rk = "vodka"

Page 52: Rabbit mq messaginginthecloud_v_mworld_2010_ms

AMQP A != C

The routing key of a published message selects which queues themessage goes to.

A

"my_queue"

"my_queue_2"X"my_exchange"

type = direct

bk = "vodka"

bk = "beer"

bk: Binding Keyrk: Routing Key

B rk = "beer"

Page 53: Rabbit mq messaginginthecloud_v_mworld_2010_ms

AMQP A != C

The routing key of a published message selects which queues themessage goes to.

A

B

"my_queue"

"my_queue_2"X"my_exchange"

type = direct

bk = "vodka"

bk = "beer"

bk: Binding Keyrk: Routing Key

Page 54: Rabbit mq messaginginthecloud_v_mworld_2010_ms

AMQP A != C

Messages with no matching bindings are discarded.

A

B

"my_queue"

"my_queue_2"X"my_exchange"

type = direct

bk = "vodka"

bk = "beer"

bk: Binding Keyrk: Routing Key

C rk = "tequila"

Page 55: Rabbit mq messaginginthecloud_v_mworld_2010_ms

AMQP A != C

Messages with no matching bindings are discarded.

A

B

"my_queue"

"my_queue_2"X"my_exchange"

type = direct

bk = "vodka"

bk = "beer"

bk: Binding Keyrk: Routing Key

Page 56: Rabbit mq messaginginthecloud_v_mworld_2010_ms

AMQP A != C

Topic exchanges permit wildcards in the binding key.

Keys are .-separated lists, e.g. “stocks.nyse.vmw”* matches any 1 element.# matches zero or more elements.

"my_queue"

"my_queue_2"X"my_exchange"

type = topic

bk = "a.*.c"

bk = "#.e"

bk: Binding Keyrk: Routing Key

Page 57: Rabbit mq messaginginthecloud_v_mworld_2010_ms

AMQP A != C

Topic exchanges permit wildcards in the binding key.Keys are .-separated lists, e.g. “stocks.nyse.vmw”* matches any 1 element.# matches zero or more elements.

"my_queue"

"my_queue_2"X"my_exchange"

type = topic

bk = "a.*.c"

bk = "#.e"

bk: Binding Keyrk: Routing Key

Page 58: Rabbit mq messaginginthecloud_v_mworld_2010_ms

AMQP A != C

Topic exchanges permit wildcards in the binding key.Keys are .-separated lists, e.g. “stocks.nyse.vmw”* matches any 1 element.# matches zero or more elements.

"my_queue"

"my_queue_2"X"my_exchange"

type = topic

bk = "a.*.c"

bk = "#.e"

bk: Binding Keyrk: Routing Key

A rk = "a"

B rk = "a.c"

C rk = "a.b.c"

D rk = "a.e"

E rk = "b.e"

F rk = "e"

Page 59: Rabbit mq messaginginthecloud_v_mworld_2010_ms

AMQP A != C

Topic exchanges permit wildcards in the binding key.Keys are .-separated lists, e.g. “stocks.nyse.vmw”* matches any 1 element.# matches zero or more elements.

"my_queue"

"my_queue_2"X"my_exchange"

type = topic

bk = "a.*.c"

bk = "#.e"

bk: Binding Keyrk: Routing Key

A rk = "a"

B rk = "a.c"

C rk = "a.b.c"

D rk = "a.e"

E rk = "b.e"

F rk = "e"

Page 60: Rabbit mq messaginginthecloud_v_mworld_2010_ms

AMQP A != C

Topic exchanges permit wildcards in the binding key.Keys are .-separated lists, e.g. “stocks.nyse.vmw”* matches any 1 element.# matches zero or more elements.

"my_queue"

"my_queue_2"X"my_exchange"

type = topic

bk = "a.*.c"

bk = "#.e"

bk: Binding Keyrk: Routing Key

B rk = "a.c"

C rk = "a.b.c"

D rk = "a.e"

E rk = "b.e"

F rk = "e"

Page 61: Rabbit mq messaginginthecloud_v_mworld_2010_ms

AMQP A != C

Topic exchanges permit wildcards in the binding key.Keys are .-separated lists, e.g. “stocks.nyse.vmw”* matches any 1 element.# matches zero or more elements.

"my_queue"

"my_queue_2"X"my_exchange"

type = topic

bk = "a.*.c"

bk = "#.e"

bk: Binding Keyrk: Routing Key

B rk = "a.c"

C rk = "a.b.c"

D rk = "a.e"

E rk = "b.e"

F rk = "e"

Page 62: Rabbit mq messaginginthecloud_v_mworld_2010_ms

AMQP A != C

Topic exchanges permit wildcards in the binding key.Keys are .-separated lists, e.g. “stocks.nyse.vmw”* matches any 1 element.# matches zero or more elements.

"my_queue"

"my_queue_2"X"my_exchange"

type = topic

bk = "a.*.c"

bk = "#.e"

bk: Binding Keyrk: Routing Key

C rk = "a.b.c"

D rk = "a.e"

E rk = "b.e"

F rk = "e"

Page 63: Rabbit mq messaginginthecloud_v_mworld_2010_ms

AMQP A != C

Topic exchanges permit wildcards in the binding key.Keys are .-separated lists, e.g. “stocks.nyse.vmw”* matches any 1 element.# matches zero or more elements.

C

"my_queue"

"my_queue_2"X"my_exchange"

type = topic

bk = "a.*.c"

bk = "#.e"

bk: Binding Keyrk: Routing Key

D rk = "a.e"

E rk = "b.e"

F rk = "e"

Page 64: Rabbit mq messaginginthecloud_v_mworld_2010_ms

AMQP A != C

Topic exchanges permit wildcards in the binding key.Keys are .-separated lists, e.g. “stocks.nyse.vmw”* matches any 1 element.# matches zero or more elements.

D

C

"my_queue"

"my_queue_2"X"my_exchange"

type = topic

bk = "a.*.c"

bk = "#.e"

bk: Binding Keyrk: Routing Key

E rk = "b.e"

F rk = "e"

Page 65: Rabbit mq messaginginthecloud_v_mworld_2010_ms

AMQP A != C

Topic exchanges permit wildcards in the binding key.Keys are .-separated lists, e.g. “stocks.nyse.vmw”* matches any 1 element.# matches zero or more elements.

E D

C

"my_queue"

"my_queue_2"X"my_exchange"

type = topic

bk = "a.*.c"

bk = "#.e"

bk: Binding Keyrk: Routing Key

F rk = "e"

Page 66: Rabbit mq messaginginthecloud_v_mworld_2010_ms

AMQP A != C

Topic exchanges permit wildcards in the binding key.Keys are .-separated lists, e.g. “stocks.nyse.vmw”* matches any 1 element.# matches zero or more elements.

EF D

C

"my_queue"

"my_queue_2"X"my_exchange"

type = topic

bk = "a.*.c"

bk = "#.e"

bk: Binding Keyrk: Routing Key

Page 67: Rabbit mq messaginginthecloud_v_mworld_2010_ms

O AMQPY,

I Errors can be raised for messages that do not get routed to anyqueues

I Messages can be consumed so that the broker does not forgetabout the message until the client explicitly acknowledges themessage

I Messages can be published with a property indicatingwhether the message should be written to disk

I Transactions: making publication and acknowledgement ofseveral messages atomic

I Flow control: e.g. used to stop publishers from overwhelmingthe broker in extreme situations

Page 68: Rabbit mq messaginginthecloud_v_mworld_2010_ms

C: W AMQP?I’ Advanced, !

A O Protocol . . .I Makes it easier to have multiple implementations that

interoperate at the wire-levelI Avoids vendor lock-in: easy to rip out and replace individual

components with alternative implementationsI Allows third-parties to write client libraries for other languagesI Decouples flag-day upgrades for both client libraries and

brokerI Allows third-party traffic analysis tools to inspect and decode

interactions between the clients and brokersI Promotes similarities in APIs presented by different client

libraries

Page 69: Rabbit mq messaginginthecloud_v_mworld_2010_ms

RMQ

Page 70: Rabbit mq messaginginthecloud_v_mworld_2010_ms

I RMQN

RMQ, AMQP & MI RabbitMQ consists of the broker (server) and several clients

(Java, .Net, plus others)I They speak the AMQP protocol to each otherI Anyone can write (and many have) other clients which also

speak AMQP and work with RabbitMQ

I RabbitMQ is freely available and open source, licensed underthe Mozilla Public License v1.1

I It’s already in many popular Linux distributions (Ubuntu,Debian, Fedora, Gentoo) and can be easily installed on OS Xboth through MacPorts and Homebrew

Page 71: Rabbit mq messaginginthecloud_v_mworld_2010_ms

I RMQN

RMQ, AMQP & MI RabbitMQ consists of the broker (server) and several clients

(Java, .Net, plus others)I They speak the AMQP protocol to each otherI Anyone can write (and many have) other clients which also

speak AMQP and work with RabbitMQI RabbitMQ is freely available and open source, licensed under

the Mozilla Public License v1.1I It’s already in many popular Linux distributions (Ubuntu,

Debian, Fedora, Gentoo) and can be easily installed on OS Xboth through MacPorts and Homebrew

Page 72: Rabbit mq messaginginthecloud_v_mworld_2010_ms

I RMQN

I The broker is written in Erlang: an excellent programminglanguage and platform for the task

I A mere 17k lines of code in the brokerI Supports clustering for increased scalabilityI Supports several extension points via plugins which are

frequently used to extend RabbitMQ, e.g. STOMP, XMPPadaptors; The Shovel; additional exchange types. . .

I Can work with Pacemaker and associated tools to providevarious forms of High Availability

Page 73: Rabbit mq messaginginthecloud_v_mworld_2010_ms

RMQ F

I A single queue can run up around 30,000 messages persecond, depending on payload, clients, and properties of themessages

I But several queues together can achieve much higherthroughput, and still keep the queues empty

I RabbitMQ 2.0 gains the ability to send messages to disk to freeup memory, thus allowing queue depths to grow, boundedonly by disk space, not RAM. Queues of 10s of millions of itemsare easily accommodated

I Adding extension to RabbitMQ based on feedback from ourusers, e.g. queue expiry, queue-message TTL, publisheracknowledgements

Page 74: Rabbit mq messaginginthecloud_v_mworld_2010_ms

C

I RabbitMQ is a leading implementation of AMQP, and has wideadoption from a large community across a large number oflanguages and problem domains

I Website and downloads available athttp://www.rabbitmq.com/

I On Ubuntu and Debian, just anapt-get install rabbitmq-server away. Similarly easy forFedora and many other Linux distributions

I For OS X, it’s in MacPortsI Full easy-to-install Windows bundles available from the

website

Page 75: Rabbit mq messaginginthecloud_v_mworld_2010_ms

A . . .C I P ?

“All our messages are incredibly important andmust never ever be lostunder any circumstances”.

Fact: There are always moments at which the message is at a singlepoint of failure.

Page 76: Rabbit mq messaginginthecloud_v_mworld_2010_ms

A . . .C I P ?

“All our messages are incredibly important andmust never ever be lostunder any circumstances”.

Fact: There are always moments at which the message is at a singlepoint of failure.

Page 77: Rabbit mq messaginginthecloud_v_mworld_2010_ms

A . . .C I P ?

“We need guaranteed exactly-once delivery – I want to send 1message, and know it gets delivered to exactly one consumer, once”.

Fact: Provably impossible.Depends on definition of guarantee: you can achieve a high

probability of no duplicates and no message loss.

Page 78: Rabbit mq messaginginthecloud_v_mworld_2010_ms

A . . .C I P ?

“We need guaranteed exactly-once delivery – I want to send 1message, and know it gets delivered to exactly one consumer, once”.

Fact: Provably impossible.Depends on definition of guarantee: you can achieve a high

probability of no duplicates and no message loss.

Page 79: Rabbit mq messaginginthecloud_v_mworld_2010_ms

T EW !

Thank you

Questions?