rabbitmq is the new king

85
© 2013 SpringOne 2GX. All rights reserved. Do not distribute without permission. RabbitMQ is the new king Jan Machacek | Alvaro Videla

Upload: spring-io

Post on 01-Dec-2014

2.105 views

Category:

Technology


2 download

DESCRIPTION

Speakers: Jan Machacek and Alvaro Videla Jan will show how to use RabbitMQ to connect components on different platforms. After a few introductory slides explaining the main concepts, the rest of the talk will be live code. The coding will begin by showing Spring Integration code to connect to RabbitMQ to send and receive messages--think byte[] values back and forth to start with. Jan will then show the real power of RabbitMQ by replacing the RPC server component by native code in C++: we will write image processing component. To make matters even better--faster--we will then use CUDA to perform the image processing. Come to Jan's talk and demo if you want to find out how to use RabbitMQ in the core of your application, especially if your application needs to tie together code on completely different platforms and if it performs heavy number crunching or image processing. You do not need to have deep knowledge of Spring Integration, AMQP or OpenCV, …; all that you will need is your inner geek.

TRANSCRIPT

Page 1: RabbitMQ is the new King

© 2013 SpringOne 2GX. All rights reserved. Do not distribute without permission.

RabbitMQ is the new kingJan Machacek | Alvaro Videla

Page 2: RabbitMQ is the new King

Jan Machacek

• Works at Cake Solutions

• Author of Pro Spring, Pro Spring 2.5 and other books & articles

• Author of Akka Patterns, Specs2 Spring, Scalad;Spring Extensions, Spock Spring Integration

• Editor of the Open Source Journal

• @honzam399 | [email protected]/janm399

Page 3: RabbitMQ is the new King

Alvaro Videla

• Developer Advocate at Pivotal / RabbitMQ

• Co-Author of RabbitMQ in Action

• Creator of the RabbitMQ Simulator

• Blogs about RabbitMQ Internals: http://videlalvaro.github.io/internals.html

• @old_sound | [email protected]/videlalvaro

Page 4: RabbitMQ is the new King

Why do we need messaging?

Page 5: RabbitMQ is the new King

Classic Web Apps

Page 6: RabbitMQ is the new King

Implement a Photo Gallery

Page 7: RabbitMQ is the new King

Two Parts:

Page 8: RabbitMQ is the new King

Pretty Simple

Page 9: RabbitMQ is the new King

‘Till new requirements arrive

Page 10: RabbitMQ is the new King

The Product Owner

Page 11: RabbitMQ is the new King

Can we also notify the user friends when she uploads a new

image?

Page 12: RabbitMQ is the new King

Can we also notify the user friends when she uploads a new

image?

I forgot to mention we need it for tomorrow…

Page 13: RabbitMQ is the new King

The Social Media Guru

Page 14: RabbitMQ is the new King

We need to give badges to users for each picture upload

Page 15: RabbitMQ is the new King

We need to give badges to users for each picture upload

and post uploads to Twitter

Page 16: RabbitMQ is the new King

The Sysadmin

Page 17: RabbitMQ is the new King

Dumb! You’re delivering full size images!

The bandwidth bill has tripled!

Page 18: RabbitMQ is the new King

Dumb! You’re delivering full size images!

The bandwidth bill has tripled!

We need this fixed for yesterday!

Page 19: RabbitMQ is the new King

The Developer in the other team

Page 20: RabbitMQ is the new King

I need to call your Java stuff but from Python

Page 21: RabbitMQ is the new King

I need to call your PHP stuff but from Python

And also PHP starting next week

Page 22: RabbitMQ is the new King

The User

Page 23: RabbitMQ is the new King

I don’t want to waittill your app resizes

my image!

Page 24: RabbitMQ is the new King

You

Page 25: RabbitMQ is the new King

(╯°□°)╯( ┻━┻

Page 26: RabbitMQ is the new King

Let’s see the code evolution

Page 27: RabbitMQ is the new King

%% image_controllerhandle('PUT', "/user/image", ReqData) -> image_handler:do_upload(ReqData:get_file()), ok.

Pseudo Code

Comments

Page 28: RabbitMQ is the new King

%% image_controllerhandle('PUT', "/user/image", ReqData) -> image_handler:do_upload(ReqData:get_file()), ok.

Pseudo Code

Function Name

Page 29: RabbitMQ is the new King

%% image_controllerhandle('PUT', "/user/image", ReqData) -> image_handler:do_upload(ReqData:get_file()), ok.

Pseudo Code

Arguments

Page 30: RabbitMQ is the new King

%% image_controllerhandle('PUT', "/user/image", ReqData) -> image_handler:do_upload(ReqData:get_file()), ok.

Pseudo Code

Function Body

Page 31: RabbitMQ is the new King

%% image_controllerhandle('PUT', "/user/image", ReqData) -> image_handler:do_upload(ReqData:get_file()), ok.

Pseudo Code

Return Value

Page 32: RabbitMQ is the new King

%% image_controllerhandle('PUT', "/user/image", ReqData) -> image_handler:do_upload(ReqData:get_file()), ok.

First Implementation:

Page 33: RabbitMQ is the new King

%% image_controllerhandle('PUT', "/user/image", ReqData) -> {ok, Image} = image_handler:do_upload(ReqData:get_file()), resize_image(Image),

ok.

Second Implementation:

Page 34: RabbitMQ is the new King

%% image_controllerhandle('PUT', "/user/image", ReqData) -> {ok, Image} = image_handler:do_upload(ReqData:get_file()), resize_image(Image),

notify_friends(ReqData:get_user()),ok.

Third Implementation:

Page 35: RabbitMQ is the new King

%% image_controllerhandle('PUT', "/user/image", ReqData) -> {ok, Image} = image_handler:do_upload(ReqData:get_file()), resize_image(Image),

notify_friends(ReqData:get_user()),add_points_to_user(ReqData:get_user()),ok.

Fourth Implementation:

Page 36: RabbitMQ is the new King

%% image_controllerhandle('PUT', "/user/image", ReqData) -> {ok, Image} = image_handler:do_upload(ReqData:get_file()), resize_image(Image),

notify_friends(ReqData:get_user()),add_points_to_user(ReqData:get_user()),tweet_new_image(User, Image),ok.

Final Implementation:

Page 37: RabbitMQ is the new King

Can our code scale to new requirements?

Page 38: RabbitMQ is the new King

What if

Page 39: RabbitMQ is the new King

• We need to speed up image conversion

What if

Page 40: RabbitMQ is the new King

• We need to speed up image conversion• User notifications sent by email

What if

Page 41: RabbitMQ is the new King

• We need to speed up image conversion• User notifications sent by email• Stop tweeting about new images

What if

Page 42: RabbitMQ is the new King

• We need to speed up image conversion• User notifications sent by email• Stop tweeting about new images• Resize in different formats

What if

Page 43: RabbitMQ is the new King

• We need to speed up image conversion• User notifications sent by email• Stop tweeting about new images• Resize in different formats• Swap Language / Technology (No Down Time)

What if

Page 44: RabbitMQ is the new King

Can we do better?

Page 45: RabbitMQ is the new King

Sure.Using messaging

Page 46: RabbitMQ is the new King

DesignPublish / Subscribe Pattern

Page 47: RabbitMQ is the new King

%% image_controllerhandle('PUT', "/user/image", ReqData) -> {ok, Image} = image_handler:do_upload(ReqData:get_file()),

Msg = #msg{user = ReqData:get_user(), image = Image},publish_message('new_image', Msg).

First Implementation:

Page 48: RabbitMQ is the new King

%% image_controllerhandle('PUT', "/user/image", ReqData) -> {ok, Image} = image_handler:do_upload(ReqData:get_file()),

Msg = #msg{user = ReqData:get_user(), image = Image},publish_message('new_image', Msg).

First Implementation:

%% friends notifieron('new_image', Msg) ->

notify_friends(Msg.user, Msg.image).

Page 49: RabbitMQ is the new King

%% image_controllerhandle('PUT', "/user/image", ReqData) -> {ok, Image} = image_handler:do_upload(ReqData:get_file()),

Msg = #msg{user = ReqData:get_user(), image = Image},publish_message('new_image', Msg).

First Implementation:

%% friends notifieron('new_image', Msg) ->

notify_friends(Msg.user, Msg.image).

%% points manageron('new_image', Msg) ->

add_points(Msg.user, 'new_image').

Page 50: RabbitMQ is the new King

%% image_controllerhandle('PUT', "/user/image", ReqData) -> {ok, Image} = image_handler:do_upload(ReqData:get_file()),

Msg = #msg{user = ReqData:get_user(), image = Image},publish_message('new_image', Msg).

First Implementation:

%% friends notifieron('new_image', Msg) ->

notify_friends(Msg.user, Msg.image).

%% points manageron('new_image', Msg) ->

add_points(Msg.user, 'new_image').

%% resizeron('new_image', Msg) ->

resize_image(Msg.image).

Page 51: RabbitMQ is the new King

Second Implementation:

Page 52: RabbitMQ is the new King

Second Implementation:

THIS PAGE INTENTIONALLY LEFT BLANK

Page 53: RabbitMQ is the new King

What is RabbitMQ

Page 54: RabbitMQ is the new King

RabbitMQ

Page 55: RabbitMQ is the new King

RabbitMQ

• Multi Protocol Messaging Server

Page 56: RabbitMQ is the new King

RabbitMQ

• Multi Protocol Messaging Server• Open Source (MPL)

Page 57: RabbitMQ is the new King

RabbitMQ

• Multi Protocol Messaging Server• Open Source (MPL)• Polyglot

Page 58: RabbitMQ is the new King

RabbitMQ

• Multi Protocol Messaging Server• Open Source (MPL)• Polyglot• Written in Erlang/OTP

Page 59: RabbitMQ is the new King

Multi Protocol

http://bit.ly/rmq-protocols

Page 60: RabbitMQ is the new King

Polyglot

Page 61: RabbitMQ is the new King

Polyglot

• Java

Page 62: RabbitMQ is the new King

Polyglot

• Java• node.js

Page 63: RabbitMQ is the new King

Polyglot

• Java• node.js• Erlang

Page 64: RabbitMQ is the new King

Polyglot

• Java• node.js• Erlang• PHP

Page 65: RabbitMQ is the new King

Polyglot

• Java• node.js• Erlang• PHP• Ruby

Page 66: RabbitMQ is the new King

Polyglot

• Java• node.js• Erlang• PHP• Ruby• .Net

Page 67: RabbitMQ is the new King

Polyglot

• Java• node.js• Erlang• PHP• Ruby• .Net• Haskell

Page 68: RabbitMQ is the new King

Polyglot

Even COBOL!!!11

Page 69: RabbitMQ is the new King

Some users of RabbitMQ

Page 70: RabbitMQ is the new King

Some users of RabbitMQ

• Instagram

Page 71: RabbitMQ is the new King

Some users of RabbitMQ

• Instagram

• Indeed.com

Page 72: RabbitMQ is the new King

Some users of RabbitMQ

• Instagram

• Indeed.com

• MailboxApp

Page 73: RabbitMQ is the new King

Some users of RabbitMQ

• Instagram

• Indeed.com

• MailboxApp

• Mercado Libre

Page 74: RabbitMQ is the new King
Page 75: RabbitMQ is the new King

Messaging with RabbitMQ

A demo with the RabbitMQ Simulator

https://github.com/RabbitMQSimulator/RabbitMQSimulator

Page 76: RabbitMQ is the new King

What are we building?

Page 77: RabbitMQ is the new King

What are we building?

AMQP

Server

CV

Page 78: RabbitMQ is the new King

What are we building?

AMQP

Server

CV

Page 79: RabbitMQ is the new King

onCoinResponse(CorrelationId, CoinResponse): Unit

RecogServiceActivatormjpegChunk(CorrelationId) (ChunkData): UnitimageChunk(CorrelationId) (ChunkData): Unit

RecogService

Page 80: RabbitMQ is the new King

Demo

Page 81: RabbitMQ is the new King

int:chain

ChunkData Collection[FrameData]FrameData

Array[Byte] StringFrameData

FrameDataFrameData

int:chain

decodeFrame(ChunkData): Collection[FrameData]

ChunkDecoder

DefaultMessageSplitter

AmqpOutboundEndpoint

ObjectToStringTransformer

ServiceActivatingHandler

ServiceActivatingHandler

onCoinResponse(CorrelationId, CoinResponse): Unit

RecogServiceActivator

mjpegChunk(ChunkData): UnitimageChunk(ChunkData): Unit

recogChannel: MessageChannelRecogService

DirectChannel

Page 82: RabbitMQ is the new King

mjpegChunk(CorrelationId) (ChunkData): UnitimageChunk(CorrelationId) (ChunkData): Unit

RecogService

mjpegChunk(SessionId, ChunkData): UnitimageChunk(SessionId, ChunkData): Unit

recogService: RecogServiceRecogController

sessionEnded(SessionId): UnitonCoinResponse(CorrelationId, CoinResponse): Unit

sessions: Map[SessionId, CoinResponse]messageSender: MessageSendingOperations[...]

RecogSessions

onCoinResponse(CorrelationId, CoinResponse): Unit

recogSessions: RecogSessionsRecogServiceActivator

Page 83: RabbitMQ is the new King

SubscribableChannel dispatchChannel

SubscribableChannel webSocketHandlerChannel

MessagingWebSocketHandler

AnnotationMessageHandler

SimpleBrokerMessageHandler

RecogSessions

RecogController

send

send

send

send

subscribe

subscribe

send

send

subscribeMessageSendingOperations[] DispatcherServlet

HTTP

WebSocket

SubProtocolWebSocketHandler

RecogService

Page 84: RabbitMQ is the new King

Questions

https://github.com/eigengo/springone2gx2013

Page 85: RabbitMQ is the new King