Transcript
Page 1: Distributed messaging with AMQP

Distributed MessagingAMQP, RabbitMQ (Quick demo)

Tuesday, 10 September 13

Page 2: Distributed messaging with AMQP

Event LoggingCurrent architecture & problems

Tuesday, 10 September 13

Page 3: Distributed messaging with AMQP

Event Logging

ServerClient

Client

Client

MongoDB

Tuesday, 10 September 13

Page 4: Distributed messaging with AMQP

Problem

ServerClient

Client

Client

80

110

65MongoDB

Tuesday, 10 September 13

Page 5: Distributed messaging with AMQP

Problem

ServerClient

Client

Client

80

110

65

255

MongoDB

Tuesday, 10 September 13

Page 6: Distributed messaging with AMQP

Problem

ServerClient

Client

Client

0

0

0

0

MongoDB

Tuesday, 10 September 13

Page 7: Distributed messaging with AMQP

Problem

ServerClient

Client

Client

0

0

0

0

MongoDB

Tuesday, 10 September 13

Page 8: Distributed messaging with AMQP

Possible Solutions

• Server tweaks: TCP conns, ulimit, etc

• Multi-master model

• Localised queue

• ... and quite a few more

Tuesday, 10 September 13

Page 9: Distributed messaging with AMQP

Possible Solutions

• Server tweaks: TCP conns, ulimit, etc

• Multi-master model

• Localised queue

• ... and quite a few more

Tuesday, 10 September 13

Page 10: Distributed messaging with AMQP

Localised Queues

• Fast (no TCP latency)

• Network partition tolerant

• Modular & scalable

• Reliable & Durable

Tuesday, 10 September 13

Page 11: Distributed messaging with AMQP

Why Localise?

ServerClient

Client

Client

80

110

65MongoDB

Q

Q

Q

< 10

Tuesday, 10 September 13

Page 12: Distributed messaging with AMQP

Why Localise?

ServerClient

Client

Client

80

110

65MongoDB

Q

Q

Q

0

Tuesday, 10 September 13

Page 13: Distributed messaging with AMQP

Why Localise?

ServerClient

Client

Client

80

110

65MongoDB

Q

Q

Q

0

Tuesday, 10 September 13

Page 14: Distributed messaging with AMQP

Why Localise?

ServerClient

Client

Client

80

110

65MongoDB

Q

Q

Q

< 10

Tuesday, 10 September 13

Page 15: Distributed messaging with AMQP

Why Localise?

ServerClient

Client

Client

80

110

65MongoDB

Q

Q

Q

< 10

Client

Q

Tuesday, 10 September 13

Page 16: Distributed messaging with AMQP

Queue Criteria

• Reliable

• Durable

• Scalable

Tuesday, 10 September 13

Page 17: Distributed messaging with AMQP

AMQPAdvanced Message Queueing Protocol

Tuesday, 10 September 13

Page 18: Distributed messaging with AMQP

Why AMQP?

• Stable and mature

• Designed for SX markets

• Widely supported (good interop)

• Modular, Fast & Flexible

Tuesday, 10 September 13

Page 19: Distributed messaging with AMQP

Service ModelWire

AMQP Overview

AMQP

Advanced Message Queueing Protocol

Tuesday, 10 September 13

Page 20: Distributed messaging with AMQP

Service Model Wire

AMQP Overview

AMQP

Tuesday, 10 September 13

Page 21: Distributed messaging with AMQP

➡ Model/component spec

‣ Exchange

‣ Message Queue

‣ Binding

AMQ Model Wire

AMQP Overview

AMQP

Tuesday, 10 September 13

Page 22: Distributed messaging with AMQP

➡ Model/component spec

‣ Exchange

‣ Message Queue

‣ Binding

AMQ Model Wire

AMQP Overview

AMQP

➡ Function layer

‣ Transactions, Exchange, Queues, etc

➡ Transport layer

‣ Protocol format

‣ Data rep/framing

‣ Multiplexing, heart-beating, etc

Tuesday, 10 September 13

Page 23: Distributed messaging with AMQP

AMQ Model Wire

AMQP Overview

AMQP

➡ Function layer

‣ Transactions, Exchange, Queues, etc

➡ Transport layer

‣ Protocol format

‣ Data rep/framing

‣ Multiplexing, heart-beating, etc

➡ Model/component spec

‣ Exchange

‣ Message Queue

‣ Binding

Tuesday, 10 September 13

Page 24: Distributed messaging with AMQP

ExchangeQueuesBindingAMQ Model

AMQ Model

Tuesday, 10 September 13

Page 25: Distributed messaging with AMQP

QueuesExchange Binding

AMQ Model

AMQ Model

Tuesday, 10 September 13

Page 26: Distributed messaging with AMQP

Virtual Host

QueuesExchange Binding

AMQ Model

AMQ Model

Tuesday, 10 September 13

Page 27: Distributed messaging with AMQP

Virtual Host

QueuesExchange Binding

AMQ Model

AMQ Model

Publisher Consumer

Tuesday, 10 September 13

Page 28: Distributed messaging with AMQP

Virtual Host

QueuesExchange

Binding

AMQ Model

Publisher Consumer

Tuesday, 10 September 13

Page 29: Distributed messaging with AMQP

Virtual Host

QueuesExchange

Binding

AMQ Model

Router

Message

Publisher Consumer

Tuesday, 10 September 13

Page 30: Distributed messaging with AMQP

Virtual Host

QueuesExchange

Binding

AMQ Model

Router

Message

Publisher Consumer

Tuesday, 10 September 13

Page 31: Distributed messaging with AMQP

Virtual Host

QueuesExchange

Binding

AMQ Model

Router

Message

Publisher Consumer

Tuesday, 10 September 13

Page 32: Distributed messaging with AMQP

Virtual Host

QueuesExchange

Binding

AMQ Model

Router

?Message

Publisher Consumer

Tuesday, 10 September 13

Page 33: Distributed messaging with AMQP

Virtual Host

QueuesExchange

Binding

AMQ Model

Message

Router

?

Publisher Consumer

Tuesday, 10 September 13

Page 34: Distributed messaging with AMQP

Virtual Host

QueuesExchange

Binding

AMQ Model

Message

Router

Publisher

➡ Queue: ‣ critical_error_queue

➡ Exchange: ‣ errors_exchange

➡ Filter:‣ *.error.critical

Consumer

Tuesday, 10 September 13

Page 35: Distributed messaging with AMQP

Virtual Host

QueuesExchange

Binding

AMQ Model

➡ Queue: ‣ critical_error_queue

➡ Exchange: ‣ errors_exchange

➡ Filter:‣ *.error.critical

Message

Router

Publisher Consumer

Tuesday, 10 September 13

Page 36: Distributed messaging with AMQP

QueuesExchange Binding

AMQP Service Model

Tuesday, 10 September 13

Page 37: Distributed messaging with AMQP

QueuesExchange Binding

AMQP Service Model

‣ routes messages based on criteria‣ doesn’t store messages‣ can inspect message content‣ can be created at runtime consumers

Tuesday, 10 September 13

Page 38: Distributed messaging with AMQP

QueuesExchange Binding

AMQP Service Model

‣ store messages‣ named‣ bound-able to exchange‣ criteria‣ can be created at runtime by consumers

‣ routes messages based on criteria‣ doesn’t store messages‣ can inspect message content‣ can be created at runtime consumers

Tuesday, 10 September 13

Page 39: Distributed messaging with AMQP

QueuesExchange Binding

AMQP Service Model

‣ creates a relationship between queues and exchanges‣ contains criteria and properties‣ can be created at runtime by consumers

‣ store messages‣ named‣ bound-able to exchange‣ criteria‣ can be created at runtime by consumers

‣ routes messages based on criteria‣ doesn’t store messages‣ can inspect message content‣ can be created at runtime consumers

Tuesday, 10 September 13

Page 40: Distributed messaging with AMQP

QueuesExchange Binding

AMQP Service Model

‣ creates a relationship between queues and exchanges‣ contains criteria and properties‣ can be created at runtime by consumers

‣ store messages‣ named‣ bound-able to exchange‣ criteria‣ can be created at runtime by consumers

‣ routes messages based on criteria‣ doesn’t store messages‣ can inspect message content‣ can be created at runtime consumers

Tuesday, 10 September 13

Page 41: Distributed messaging with AMQP

QueuesExchange Binding

AMQP Service Model

Publisher Consumer

‣ creates a relationship between queues and exchanges‣ contains criteria and properties‣ can be created at runtime by consumers

‣ store messages‣ named‣ bound-able to exchange‣ criteria‣ can be created at runtime by consumers

‣ routes messages based on criteria‣ doesn’t store messages‣ can inspect message content‣ can be created at runtime consumers

Tuesday, 10 September 13

Page 42: Distributed messaging with AMQP

QueuesExchange Binding

AMQP Service Model

Publisher Consumer

‣ creates a relationship between queues and exchanges‣ contains criteria and properties‣ can be created at runtime by consumers

‣ store messages‣ named‣ bound-able to exchange‣ criteria‣ can be created at runtime by consumers

‣ routes messages based on criteria‣ doesn’t store messages‣ can inspect message content‣ can be created at runtime consumers

‣ can create exchanges and queues

‣ can create exchanges and queues

Tuesday, 10 September 13

Page 43: Distributed messaging with AMQP

Exchange

AMQP Service Model

Tuesday, 10 September 13

Page 44: Distributed messaging with AMQP

FanoutTopicHeadersSystem

Exchange

AMQP Service Model

Types(routing algo)

Tuesday, 10 September 13

Page 45: Distributed messaging with AMQP

Fanout Topic Headers System

Exchange

AMQP Service Model

Types(routing algo)

Direct

Tuesday, 10 September 13

Page 46: Distributed messaging with AMQP

Fanout Topic Headers System

Exchange

AMQP Service Model

Types(routing algo)

Direct

Tuesday, 10 September 13

Page 47: Distributed messaging with AMQP

Exchange

AMQP Service ModelDirect Type

Tuesday, 10 September 13

Page 48: Distributed messaging with AMQP

Exchange‘events’

AMQP Service ModelDirect Type

Tuesday, 10 September 13

Page 49: Distributed messaging with AMQP

Exchange‘events’

AMQP Service ModelDirect Type

Message

Message

Message

event.user.click

event.user.view

event.user.share

Tuesday, 10 September 13

Page 50: Distributed messaging with AMQP

Exchange‘events’

AMQP Service ModelDirect Type

Message

Message

Message

event.user.click

event.user.view

event.user.share

user_click_queue

Tuesday, 10 September 13

Page 51: Distributed messaging with AMQP

Exchange‘events’

Binding

AMQP Service Model

➡Queue: ‣ user_click_queue

Direct Type

Message

Message

Message

event.user.click

event.user.view

event.user.share

user_click_queue

Tuesday, 10 September 13

Page 52: Distributed messaging with AMQP

Exchange‘events’

Binding

AMQP Service Model

➡Queue: ‣ user_click_queue

➡Exchange: ‣ events

Direct Type

Message

Message

Message

event.user.click

event.user.view

event.user.share

user_click_queue

Tuesday, 10 September 13

Page 53: Distributed messaging with AMQP

Exchange‘events’

Binding

AMQP Service Model

➡Queue: ‣ user_click_queue

➡Exchange: ‣ events

➡Routing Key:‣ event.user.click

Direct Type

Message

Message

Message

event.user.click

event.user.view

event.user.share

user_click_queue

Tuesday, 10 September 13

Page 54: Distributed messaging with AMQP

Exchange‘events’

Binding

AMQP Service Model

➡Queue: ‣ user_click_queue

➡Exchange: ‣ events

➡Routing Key:‣ event.user.click

Direct Type

Message

Message

Message

event.user.click

event.user.view

event.user.share

PHP Script

PHP Script

PHP Script

user_click_queue

Tuesday, 10 September 13

Page 55: Distributed messaging with AMQP

Exchange‘events’

AMQP Service ModelDirect Type

Message

Message

Message

event.user.click

event.user.view

event.user.share

PHP Script

PHP Script

PHP Script

user_click_queue

ConsumerPublisher/Producer

Tuesday, 10 September 13

Page 56: Distributed messaging with AMQP

Exchange‘events’

AMQP Service ModelDirect Type

Message

Message

Message

event.user.click

event.user.view

event.user.share

user_click_queue

user_view_queue

user_share_queue

Tuesday, 10 September 13

Page 57: Distributed messaging with AMQP

Exchange‘events’

AMQP Service ModelDirect Type

Message

Message

Message

event.user.click

event.user.view

event.user.share

user_click_queue

user_view_queue

user_share_queue

Message

Message

Message

Tuesday, 10 September 13

Page 58: Distributed messaging with AMQP

Exchange‘events’

AMQP Service ModelWhat if...

Message

Message

Message

event.user.click

event.user.view

event.user.share

user_interaction_queue

user_shares_queue

Tuesday, 10 September 13

Page 59: Distributed messaging with AMQP

Exchange‘events’

AMQP Service ModelWhat if...

user_interaction_queue

user_shares_queue

Message

Message

Message

event.user.click

event.user.view

event.user.share

Tuesday, 10 September 13

Page 60: Distributed messaging with AMQP

Exchange‘events’

AMQP Service ModelWhat if...

Message

Message

Message

event.user.click

event.user.view

event.user.share

user_interaction_queue

user_shares_queue

Tuesday, 10 September 13

Page 61: Distributed messaging with AMQP

Exchange‘events’

AMQP Service ModelTopic Exchange

user_interaction_queue

Binding

Message

Message

Message

event.user.click

event.user.view

event.user.share

Tuesday, 10 September 13

Page 62: Distributed messaging with AMQP

Exchange‘events’

AMQP Service ModelTopic Exchange

user_interaction_queue

Binding

➡Queue: ‣ user_interaction_queue

➡Exchange: ‣ events

➡Routing Key:‣ event.user.*

Message

Message

Message

event.user.click

event.user.view

event.user.share

Tuesday, 10 September 13

Page 63: Distributed messaging with AMQP

Exchange‘events’

AMQP Service ModelTopic Exchange

user_interaction_queue

Binding

➡Queue: ‣ user_interaction_queue

➡Exchange: ‣ events

➡Routing Key:‣ event.user.*

Message

Message

Message

event.user.click

event.user.view

event.user.share

PHP Script

PHP Script

PHP Script

Tuesday, 10 September 13

Page 64: Distributed messaging with AMQP

Exchange‘events’

AMQP Service ModelTopic Exchange

user_shares_queue

Binding

Message

Message

Message

event.user.click

event.user.view

event.user.share

Tuesday, 10 September 13

Page 65: Distributed messaging with AMQP

Exchange‘events’

AMQP Service ModelTopic Exchange

user_shares_queue

Binding

➡Queue: ‣ user_interaction_queue

➡Exchange: ‣ events

➡Routing Key:‣ event.user.share

Message

Message

Message

event.user.click

event.user.view

event.user.share

Tuesday, 10 September 13

Page 66: Distributed messaging with AMQP

Exchange‘events’

AMQP Service ModelTopic Exchange

user_shares_queue

Binding

➡Queue: ‣ user_interaction_queue

➡Exchange: ‣ events

➡Routing Key:‣ event.user.share

Message

Message

Message

event.user.click

event.user.view

event.user.share

PHP Script

PHP Script

PHP Script

Tuesday, 10 September 13

Page 67: Distributed messaging with AMQP

Message

Exchange‘events’

AMQP Service ModelTopic Exchange

Message

Message

Message

event.user.click

event.user.view

event.user.share

user_interaction_queue

user_shares_queue

Message

Message

event.user.*

event.user.share

Tuesday, 10 September 13

Page 68: Distributed messaging with AMQP

Message

Exchange‘events’

AMQP Service ModelTopic Exchange

Message

Message

Message

event.user.click

event.user.view

event.user.share

user_interaction_queue

user_shares_queue

Message

Message

Can be done at runtime

event.user.*

event.user.share

Tuesday, 10 September 13

Page 69: Distributed messaging with AMQP

Message

Exchange‘events’

AMQP Service ModelTopic Exchange

Message

Message

Message

event.user.click

event.user.view

event.user.share

user_interaction_queue

user_shares_queue

Message

Message

Click vs Share Conversion?

event.user.*

event.user.share

Tuesday, 10 September 13

Page 70: Distributed messaging with AMQP

Message

Exchange‘events’

AMQP Service ModelTopic Exchange

Message

Message

Message

event.user.click

event.user.view

event.user.share

user_interaction_queue

user_shares_queue

Message

Message

Click vs Share Conversion?

event.user.*

event.user.share

Messageclick_share_queue

Message

event.user.shareevent.user.click

Tuesday, 10 September 13

Page 71: Distributed messaging with AMQP

Message

Exchange‘events’

AMQP Service ModelTopic Exchange

Message

Message

Message

event.user.click

event.user.view

event.user.share

user_interaction_queue

user_shares_queueMessage

live_view_queue

event.user.*

event.user.share

*.*.view

Message

Messageevent.staff.view

MessageMessage

Staff vs user views?

Tuesday, 10 September 13

Page 72: Distributed messaging with AMQP

AMQ Model Wire

AMQP Overview

AMQP

➡ Function layer

‣ Transactions, Exchange, Queues, etc

➡ Transport layer

‣ Protocol format

‣ Data rep/framing

‣ Multiplexing, heart-beating, etc

➡ Model/component spec

‣ Exchange

‣ Message Queue

‣ Binding

Tuesday, 10 September 13

Page 73: Distributed messaging with AMQP

➡ Model/component spec

‣ Exchange

‣ Message Queue

‣ Binding

AMQ Model Wire

AMQP Overview

AMQP

➡ Function layer

‣ Transactions, Exchange, Queues, etc

➡ Transport layer

‣ Protocol format

‣ Data rep/framing

‣ Multiplexing, heart-beating, etc

Tuesday, 10 September 13

Page 74: Distributed messaging with AMQP

Wire

Wire Protocol

Tuesday, 10 September 13

Page 75: Distributed messaging with AMQP

Wire

Wire Protocol

‣ Datagram specification‣ Protocol header‣ Payload format‣ Data fields specification‣ Content framing‣ Heartbeat frames

‣ Channel multiplexing‣ Visibility guarantee‣ Channel closure‣ Content synchronisation‣ Content ordering

Tuesday, 10 September 13

Page 76: Distributed messaging with AMQP

Wire ProtocolMethod Payloads

Tuesday, 10 September 13

Page 77: Distributed messaging with AMQP

Wire ProtocolMethod Payloads

Tuesday, 10 September 13

Page 78: Distributed messaging with AMQP

Virtual Host

QueuesExchange

Binding

Summary

➡ Queue: ‣ critical_error_queue

➡ Exchange: ‣ errors_exchange

➡ Filter:‣ *.error.critical

Message

Router

Publisher Consumer

Tuesday, 10 September 13

Page 79: Distributed messaging with AMQP

Revisiting event loggingA proposed solution

Tuesday, 10 September 13

Page 80: Distributed messaging with AMQP

Event Logging Revisited

Client

Client

Client

MongoDB

Tuesday, 10 September 13

Page 81: Distributed messaging with AMQP

Event Logging Revisited

Client

Client

ClientMQ

MQ

MQ

MongoDB

Tuesday, 10 September 13

Page 82: Distributed messaging with AMQP

MongoDB

Event Logging Revisited

MQClient

Client

Client

80

110

65

MQ

MQ

MQ

Tuesday, 10 September 13

Page 83: Distributed messaging with AMQP

MongoDB

Event Logging Revisited

MQClient

Client

Client

80

110

65

MQ

MQ

MQ

Tuesday, 10 September 13

Page 84: Distributed messaging with AMQP

MongoDB

Event Logging Revisited

MQClient

Client

Client

80

110

65

MQ

MQ

MQ

MQ

Tuesday, 10 September 13

Page 85: Distributed messaging with AMQP

MongoDB

Event Logging Revisited

MQ

Client

Client

Client

80

110

65

MQ

MQ

MQ

MQ

Tuesday, 10 September 13

Page 86: Distributed messaging with AMQP

Message

Exchange‘events’

AMQP Service ModelTopic Exchange

Message

Message

Message

event.user.click

event.user.view

event.user.share

user_interaction_queue

user_shares_queueMessage

live_view_queue

event.user.*

event.user.share

*.*.view

Message

Messageevent.staff.view

MessageMessage

Remember this?

Tuesday, 10 September 13

Page 87: Distributed messaging with AMQP

MongoDB

Event Logging Revisited

MQClient

Client

Client

80

110

65

MQ

MQ

MQ

ReportingSQL

Notification

Tuesday, 10 September 13

Page 88: Distributed messaging with AMQP

RabbitMQAn AMQP Implementation

Tuesday, 10 September 13

Page 89: Distributed messaging with AMQP

Why RabbitMQ?

• Mature (born 2006)

• Acquired by SpringSource (now part of VMWare) in 2010

• Used by companies like Nokia, Google, Mozilla, vFabric, SecondLife, OpenStack

Tuesday, 10 September 13

Page 90: Distributed messaging with AMQP

Overview

• Written in Erlang/OTP

• Supports other protocols too - STOMP, MQTT

• Many library supports - Python, PHP, Ruby, .NET

• RESTful API is available

Tuesday, 10 September 13

Page 91: Distributed messaging with AMQP

Hands on Demo

Tuesday, 10 September 13

Page 92: Distributed messaging with AMQP

Q&A

Tuesday, 10 September 13

Page 93: Distributed messaging with AMQP

Coming soon...RabbitMQ in Depth (sort of)

Tuesday, 10 September 13


Recommended