Upload
alvaro-videla
View
151
Download
1
Tags:
Embed Size (px)
DESCRIPTION
Talk given at PHPUK 13. The Pub/Sub Pattern image form slide 51 is taken from here: http://www.eaipatterns.com/PublishSubscribeChannel.html
Citation preview
RabbitMQ Hands On
Álvaro Videla - VMware
Monday, February 25, 13
About Me• Developer Advocate for Cloud Foundry
• Blog: http://videlalvaro.github.com/
• Twitter: @old_sound
Monday, February 25, 13
About Me• Developer Advocate for Cloud Foundry
• Blog: http://videlalvaro.github.com/
• Twitter: @old_sound
• I created gifsockets™
Monday, February 25, 13
About Me
Co-authored
RabbitMQ in Action
http://bit.ly/rabbitmq
Monday, February 25, 13
Why do you need messaging?
Monday, February 25, 13
Classic Web Apps
Monday, February 25, 13
Implement a Photo Gallery
Monday, February 25, 13
Two Parts:
Monday, February 25, 13
Pretty Simple
Monday, February 25, 13
‘Till new requirements arrive
Monday, February 25, 13
The Product Owner
Monday, February 25, 13
Can we also notify the user friends when she uploads a new image?
Monday, February 25, 13
Can we also notify the user friends when she uploads a new image?
I forgot to mention we need it for tomorrow…
Monday, February 25, 13
Monday, February 25, 13
The Social Media Guru
Monday, February 25, 13
We need to give badges to users for each picture upload
Monday, February 25, 13
We need to give badges to users for each picture upload
and post uploads to Twitter
Monday, February 25, 13
Monday, February 25, 13
The Sysadmin
Monday, February 25, 13
Dumb! You’re delivering full size images!
The bandwidth bill has tripled!
Monday, February 25, 13
Dumb! You’re delivering full size images!
The bandwidth bill has tripled!
We need this fixed for yesterday!
Monday, February 25, 13
Monday, February 25, 13
The Developer in the other team
Monday, February 25, 13
I need to call your PHP stuff but from Python
Monday, February 25, 13
I need to call your PHP stuff but from Python
And also Java starting next week
Monday, February 25, 13
Monday, February 25, 13
The User
Monday, February 25, 13
I don’t want to waittill your app resizes
my image!
Monday, February 25, 13
You
Monday, February 25, 13
Monday, February 25, 13
Let’s see the code evolution
Monday, February 25, 13
%% image_controllerhandle('PUT', "/user/image", ReqData) -> image_handler:do_upload(ReqData:get_file()), ok.
Pseudo Code
Comments
Monday, February 25, 13
%% image_controllerhandle('PUT', "/user/image", ReqData) -> image_handler:do_upload(ReqData:get_file()), ok.
Pseudo Code
Function Name
Monday, February 25, 13
%% image_controllerhandle('PUT', "/user/image", ReqData) -> image_handler:do_upload(ReqData:get_file()), ok.
Pseudo Code
Arguments
Monday, February 25, 13
%% image_controllerhandle('PUT', "/user/image", ReqData) -> image_handler:do_upload(ReqData:get_file()), ok.
Pseudo Code
Function Body
Monday, February 25, 13
%% image_controllerhandle('PUT', "/user/image", ReqData) -> image_handler:do_upload(ReqData:get_file()), ok.
Pseudo Code
Return Value
Monday, February 25, 13
%% image_controllerhandle('PUT', "/user/image", ReqData) -> image_handler:do_upload(ReqData:get_file()), ok.
First Implementation:
Monday, February 25, 13
%% image_controllerhandle('PUT', "/user/image", ReqData) -> {ok, Image} = image_handler:do_upload(ReqData:get_file()), resize_image(Image),ok.
Second Implementation:
Monday, February 25, 13
%% 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:
Monday, February 25, 13
%% 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:
Monday, February 25, 13
%% 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:
Monday, February 25, 13
Can our code scale to new requirements?
Monday, February 25, 13
What if
Monday, February 25, 13
• We need to speed up image conversion
What if
Monday, February 25, 13
• We need to speed up image conversion• User notifications sent by email
What if
Monday, February 25, 13
• We need to speed up image conversion• User notifications sent by email• Stop tweeting about new images
What if
Monday, February 25, 13
• We need to speed up image conversion• User notifications sent by email• Stop tweeting about new images• Resize in different formats
What if
Monday, February 25, 13
• 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
Monday, February 25, 13
Can we do better?
Monday, February 25, 13
Sure.Using messaging
Monday, February 25, 13
DesignPublish / Subscribe Pattern
Monday, February 25, 13
%% 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:
Monday, February 25, 13
%% 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).
Monday, February 25, 13
%% 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').
Monday, February 25, 13
%% 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).
Monday, February 25, 13
Second Implementation:
Monday, February 25, 13
Second Implementation:
THIS PAGE INTENTIONALLY LEFT BLANK
Monday, February 25, 13
Monday, February 25, 13
Messaging and RabbitMQ
Monday, February 25, 13
RabbitMQ
Monday, February 25, 13
RabbitMQ
• Multi Protocol Messaging Server
Monday, February 25, 13
RabbitMQ
• Multi Protocol Messaging Server• Open Source (MPL)
Monday, February 25, 13
RabbitMQ
• Multi Protocol Messaging Server• Open Source (MPL)• Part of Spring Source
Monday, February 25, 13
RabbitMQ
• Polyglot• Multi Protocol• Open Source (MPL)• Written in Erlang/OTP
Monday, February 25, 13
Multi Protocol
http://bit.ly/rmq-protocols
Monday, February 25, 13
Polyglot
• PHP• node.js• Erlang• Java• Ruby• .Net• Haskell
Monday, February 25, 13
CODE OR IT DIDN’T HAPPEN
http://github.com/videlalvaro/php-amqplib
Monday, February 25, 13
Messaging
Monday, February 25, 13
Messaging
Scale
Monday, February 25, 13
Messaging
DecouplingScale
Monday, February 25, 13
Messaging
DecouplingScale
Polyglot Apps
Monday, February 25, 13
Questions?
Monday, February 25, 13
Thanks!@old_sound
Monday, February 25, 13