62
Taming The Rabbit Writing RabbitMQ Plugins Alvaro Videla - VMware Wednesday, October 24, 12

Taming the rabbit

Embed Size (px)

Citation preview

Page 1: Taming the rabbit

Taming The RabbitWriting RabbitMQ Plugins

Alvaro Videla - VMware

Wednesday, October 24, 12

Page 2: Taming the rabbit

About Me• Developer Advocate for Cloud Foundry

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

• Twitter: @old_sound

Wednesday, October 24, 12

Page 3: Taming the rabbit

About Me• Developer Advocate for Cloud Foundry

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

• Twitter: @old_sound

• I created gifsockets™

Wednesday, October 24, 12

Page 4: Taming the rabbit

About Me

Co-authored

RabbitMQ in Action

http://bit.ly/rabbitmq

Wednesday, October 24, 12

Page 5: Taming the rabbit

RabbitMQ

Wednesday, October 24, 12

Page 6: Taming the rabbit

RabbitMQ

• Enterprise Messaging System

• Open Source MPL

• Written in Erlang/OTP

• Messaging via AMQP

• Acquired by Spring Source (VMware)

Wednesday, October 24, 12

Page 7: Taming the rabbit

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

Page 8: Taming the rabbit

Wednesday, October 24, 12

Page 9: Taming the rabbit

Extensible

• Plugin System

• Official Plugins

• Community Plugins

Wednesday, October 24, 12

Page 10: Taming the rabbit

Extensible

• Plugin System

• Official Plugins

• Community Plugins

• Plugins must be written in Erlang

Wednesday, October 24, 12

Page 11: Taming the rabbit

Wednesday, October 24, 12

Page 12: Taming the rabbit

What can you do with plugins?

Wednesday, October 24, 12

Page 13: Taming the rabbit

Add new Protocols

Wednesday, October 24, 12

Page 14: Taming the rabbit

STOMPWednesday, October 24, 12

Page 15: Taming the rabbit

STOMP

COMMANDheader1:value1header2:value2

Body^@

Wednesday, October 24, 12

Page 16: Taming the rabbit

STOMP

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

^@

Wednesday, October 24, 12

Page 17: Taming the rabbit

STOMP

CONNECTEDversion:1.1

^@

Wednesday, October 24, 12

Page 18: Taming the rabbit

Websockets+

STOMP=

WebSTOMP

Wednesday, October 24, 12

Page 19: Taming the rabbit

Add AuthenticationMechanisms

Wednesday, October 24, 12

Page 20: Taming the rabbit

LDAPWednesday, October 24, 12

Page 21: Taming the rabbit

SSLWednesday, October 24, 12

Page 22: Taming the rabbit

Add your own Message Store

Wednesday, October 24, 12

Page 24: Taming the rabbit

Wrap Erlang apps together with

RabbitMQ

Wednesday, October 24, 12

Page 25: Taming the rabbit

cowboy-wrapper

Wednesday, October 24, 12

Page 26: Taming the rabbit

ldap-wrapper

Wednesday, October 24, 12

Page 27: Taming the rabbit

webmachine-wrapper

Wednesday, October 24, 12

Page 28: Taming the rabbit

Add extra functionality to the broker

Wednesday, October 24, 12

Page 29: Taming the rabbit

RabbitMQ Management Plugin

Wednesday, October 24, 12

Page 30: Taming the rabbit

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

Page 31: Taming the rabbit

RabbitMQ Shovel Plugin

Wednesday, October 24, 12

Page 32: Taming the rabbit

Create your Own Exchanges

Wednesday, October 24, 12

Page 33: Taming the rabbit

Why?

Wednesday, October 24, 12

Page 34: Taming the rabbit

Exchanges

Wednesday, October 24, 12

Page 35: Taming the rabbit

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

Page 36: Taming the rabbit

AMQP Model

• Exchanges

• Message Queues

• Bindings

• Rules for binding them

Wednesday, October 24, 12

Page 37: Taming the rabbit

Exchange Types

• Fanout

• Direct

• Topic

Wednesday, October 24, 12

Page 41: Taming the rabbit

random-exchange

Wednesday, October 24, 12

Page 42: Taming the rabbit

consistent-hash-exchange

Wednesday, October 24, 12

Page 43: Taming the rabbit

riak-exchange

Wednesday, October 24, 12

Page 44: Taming the rabbit

rabbitmq-global-fanout-exchange

Wednesday, October 24, 12

Page 45: Taming the rabbit

recent-history-exchange

Wednesday, October 24, 12

Page 46: Taming the rabbit

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

Page 47: Taming the rabbit

Exchange Behaviours

Wednesday, October 24, 12

Page 48: Taming the rabbit

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

Page 49: Taming the rabbit

Env Setup

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

cd rabbitmq-public-umbrella

make co

Wednesday, October 24, 12

Page 50: Taming the rabbit

File Structure

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

Wednesday, October 24, 12

Page 51: Taming the rabbit

RabbitMQ Boot Steps

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

Wednesday, October 24, 12

Page 52: Taming the rabbit

RabbitMQ Boot Steps

Wednesday, October 24, 12

Page 53: Taming the rabbit

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

Page 54: Taming the rabbit

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

Page 55: Taming the rabbit

Demo Code

Wednesday, October 24, 12

Page 56: Taming the rabbit

Managing Plugins

Wednesday, October 24, 12

Page 57: Taming the rabbit

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

Page 58: Taming the rabbit

ACHTUNG!

• Plugins Run in the same Erlang process

Wednesday, October 24, 12

Page 59: Taming the rabbit

ACHTUNG!

• Plugins Run in the same Erlang process

• They may crash your broker

Wednesday, October 24, 12

Page 60: Taming the rabbit

Have Funand

Experiment!

Wednesday, October 24, 12

Page 61: Taming the rabbit

Questions?

Wednesday, October 24, 12

Page 62: Taming the rabbit

Thanks!Álvaro Videla

http://twitter.com/old_sound

http://github.com/videlalvaro

http://www.slideshare.net/old_sound

Wednesday, October 24, 12