Taming the rabbit

Preview:

Citation preview

Taming The RabbitWriting RabbitMQ Plugins

Alvaro Videla - VMware

Wednesday, October 24, 12

About Me• Developer Advocate for Cloud Foundry

• Blog: http://videlalvaro.github.com/

• Twitter: @old_sound

Wednesday, October 24, 12

About Me• Developer Advocate for Cloud Foundry

• Blog: http://videlalvaro.github.com/

• Twitter: @old_sound

• I created gifsockets™

Wednesday, October 24, 12

About Me

Co-authored

RabbitMQ in Action

http://bit.ly/rabbitmq

Wednesday, October 24, 12

RabbitMQ

Wednesday, October 24, 12

RabbitMQ

• Enterprise Messaging System

• Open Source MPL

• Written in Erlang/OTP

• Messaging via AMQP

• Acquired by Spring Source (VMware)

Wednesday, October 24, 12

Features

• Reliable and High Scalable

• Easy To install

• Easy To Cluster

• Runs on: Windows, Solaris, Linux, OSX

• AMQP 0.8 - 0.9.1

Wednesday, October 24, 12

Wednesday, October 24, 12

Extensible

• Plugin System

• Official Plugins

• Community Plugins

Wednesday, October 24, 12

Extensible

• Plugin System

• Official Plugins

• Community Plugins

• Plugins must be written in Erlang

Wednesday, October 24, 12

Wednesday, October 24, 12

What can you do with plugins?

Wednesday, October 24, 12

Add new Protocols

Wednesday, October 24, 12

STOMPWednesday, October 24, 12

STOMP

COMMANDheader1:value1header2:value2

Body^@

Wednesday, October 24, 12

STOMP

CONNECTaccept-version:1.1host:stomp.github.org

^@

Wednesday, October 24, 12

STOMP

CONNECTEDversion:1.1

^@

Wednesday, October 24, 12

Websockets+

STOMP=

WebSTOMP

Wednesday, October 24, 12

Add AuthenticationMechanisms

Wednesday, October 24, 12

LDAPWednesday, October 24, 12

SSLWednesday, October 24, 12

Add your own Message Store

Wednesday, October 24, 12

Wrap Erlang apps together with

RabbitMQ

Wednesday, October 24, 12

cowboy-wrapper

Wednesday, October 24, 12

ldap-wrapper

Wednesday, October 24, 12

webmachine-wrapper

Wednesday, October 24, 12

Add extra functionality to the broker

Wednesday, October 24, 12

RabbitMQ Management Plugin

Wednesday, October 24, 12

http://www.rabbitmq.com/img/management/overview.pngWednesday, October 24, 12

RabbitMQ Shovel Plugin

Wednesday, October 24, 12

Create your Own Exchanges

Wednesday, October 24, 12

Why?

Wednesday, October 24, 12

Exchanges

Wednesday, October 24, 12

Message Flow

http://www.redhat.com/docs/en-US/Red_Hat_Enterprise_MRG/1.0/html/Messaging_Tutorial/chap-Messaging_Tutorial-Initial_Concepts.html

Wednesday, October 24, 12

AMQP Model

• Exchanges

• Message Queues

• Bindings

• Rules for binding them

Wednesday, October 24, 12

Exchange Types

• Fanout

• Direct

• Topic

Wednesday, October 24, 12

random-exchange

Wednesday, October 24, 12

consistent-hash-exchange

Wednesday, October 24, 12

riak-exchange

Wednesday, October 24, 12

rabbitmq-global-fanout-exchange

Wednesday, October 24, 12

recent-history-exchange

Wednesday, October 24, 12

recent-history-exchange

Chat Room Exchange

user_a user_b user_c

user_x

MsgCache

NewMsg

NewMsg

NewMsg

NewMsg

NewMsg

Last N messages

new_user

CachedMsgs

Using the recent history exchange

http://manning.com/videla/Wednesday, October 24, 12

Exchange Behaviours

Wednesday, October 24, 12

recent-history-exchange

Caches up to 20 messages

Delivers cached msgsto new client

route/2

add_binding/3

delete/3

Recent History Exchange

Drops cached

messages

http://manning.com/videla/Wednesday, October 24, 12

Env Setup

hg clone http://hg.rabbitmq.com/rabbitmq-public-umbrella

cd rabbitmq-public-umbrella

make co

Wednesday, October 24, 12

File Structure

|-- rabbitmq-public-umbrella| |-- myplugin-folder| | | -- package.mk| | | -- Makefile

Wednesday, October 24, 12

RabbitMQ Boot Steps

https://github.com/videlalvaro/rabbit-internals/blob/master/rabbit_boot_process.md

Wednesday, October 24, 12

RabbitMQ Boot Steps

Wednesday, October 24, 12

RabbitMQ Boot Steps

-rabbit_boot_step({recovery, [{description,

"exchange, queue and binding recovery"},

{mfa, {rabbit, recover, []}}, {requires, empty_db_check}, {enables, routing_ready}]}).

Wednesday, October 24, 12

RabbitMQ Boot Steps

-rabbit_boot_step({msg_store_bitcask_index, [{description, "Bitcask Index for rabbit_msg_store"}, {mfa, {application, set_env, [rabbit, msg_store_index_module, ?MODULE]}}, {enables, recovery}]}).

Modify Configuration at Startup

Wednesday, October 24, 12

Demo Code

Wednesday, October 24, 12

Managing Plugins

Wednesday, October 24, 12

rabbitmq-plugins

$ rabbitmq-plugins list

$ rabbitmq-plugins enable plugin_name

$ rabbitmq-plugins disable plugin_name

http://www.rabbitmq.com/man/rabbitmq-plugins.1.man.html

Wednesday, October 24, 12

ACHTUNG!

• Plugins Run in the same Erlang process

Wednesday, October 24, 12

ACHTUNG!

• Plugins Run in the same Erlang process

• They may crash your broker

Wednesday, October 24, 12

Have Funand

Experiment!

Wednesday, October 24, 12

Questions?

Wednesday, October 24, 12

Thanks!Álvaro Videla

http://twitter.com/old_sound

http://github.com/videlalvaro

http://www.slideshare.net/old_sound

Wednesday, October 24, 12