SlideShare ist ein Scribd-Unternehmen logo
1 von 115
Downloaden Sie, um offline zu lesen
Messaging Patterns


                          Álvaro Videla - Liip AG




Monday, June 6, 2011
About Me


                       •   Developer at Liip AG

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

                       •   Twitter: @old_sound




Monday, June 6, 2011
About Me
                       Co-authoring

               RabbitMQ in Action
              http://bit.ly/rabbitmq




Monday, June 6, 2011
Why Do I need
                        Messaging?


Monday, June 6, 2011
An Example



Monday, June 6, 2011
Implement a
                       Photo Gallery


Monday, June 6, 2011
Two Parts:




Monday, June 6, 2011
Pretty Simple



Monday, June 6, 2011
‘Till new
                       requirements arrive


Monday, June 6, 2011
The Product Owner



Monday, June 6, 2011
Can we also notify the
                       user friends when she
                       uploads a new image?


Monday, June 6, 2011
Can we also notify the
                       user friends when she
                       uploads a new image?
      I forgot to mention we need it for tomorrow…

Monday, June 6, 2011
The Social Media Guru



Monday, June 6, 2011
We need to give badges
                  to users for each
                   picture upload


Monday, June 6, 2011
We need to give badges
                  to users for each
                   picture upload
                       and post uploads to Twitter

Monday, June 6, 2011
The Sysadmin



Monday, June 6, 2011
Dumb! You’re delivering
                    full size images!
                 The bandwidth bill has
                         tripled!

Monday, June 6, 2011
Dumb! You’re delivering
                    full size images!
                 The bandwidth bill has
                         tripled!
                       We need this fixed for yesterday!
Monday, June 6, 2011
The Developer in the
                           other team


Monday, June 6, 2011
I need to call your PHP
                   stuff but from Python


Monday, June 6, 2011
I need to call your PHP
                   stuff but from Python

                       And also Java starting next week
Monday, June 6, 2011
The User



Monday, June 6, 2011
I don’t want to wait
                       till your app resizes
                             my image!


Monday, June 6, 2011
You



Monday, June 6, 2011
FML!

Monday, June 6, 2011
Let’s see the
                       code evolution


Monday, June 6, 2011
First Implementation:

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




Monday, June 6, 2011
Second Implementation:

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




Monday, June 6, 2011
Third Implementation:

           %% image_controller
           handle('PUT', "/user/image", ReqData) ->
             {ok, Image} = image_handler:do_upload(ReqData:get_file()),
             resize_image(Image),
             notify_friends(ReqData:get_user()),
             ok.




Monday, June 6, 2011
Fourth Implementation:

           %% image_controller
           handle('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.




Monday, June 6, 2011
Final Implementation:

           %% image_controller
           handle('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.




Monday, June 6, 2011
Can our code scale to
                        new requirements?


Monday, June 6, 2011
What if




Monday, June 6, 2011
What if
                       • We need to speed up image conversion




Monday, June 6, 2011
What if
                       • We need to speed up image conversion
                       • User notification has to be sent by email




Monday, June 6, 2011
What if
                       • We need to speed up image conversion
                       • User notification has to be sent by email
                       • Stop tweeting about new images



Monday, June 6, 2011
What if
                       • We need to speed up image conversion
                       • User notification has to be sent by email
                       • Stop tweeting about new images
                       • Resize in different formats


Monday, June 6, 2011
Can we do better?



Monday, June 6, 2011
Sure.
                       Using messaging


Monday, June 6, 2011
Design
                       Publish / Subscribe Pattern




Monday, June 6, 2011
First Implementation:
           %% image_controller
           handle('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).




Monday, June 6, 2011
First Implementation:
           %% image_controller
           handle('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).

           %% friends notifier
           on('new_image', Msg) ->
             notify_friends(Msg.user, Msg.image).




Monday, June 6, 2011
First Implementation:
           %% image_controller
           handle('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).

           %% friends notifier
           on('new_image', Msg) ->
             notify_friends(Msg.user, Msg.image).

           %% points manager
           on('new_image', Msg) ->
             add_points(Msg.user, 'new_image').




Monday, June 6, 2011
First Implementation:
           %% image_controller
           handle('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).

           %% friends notifier
           on('new_image', Msg) ->
             notify_friends(Msg.user, Msg.image).

           %% points manager
           on('new_image', Msg) ->
             add_points(Msg.user, 'new_image').

           %% resizer
           on('new_image', Msg) ->
             resize_image(Msg.image).


Monday, June 6, 2011
Second Implementation:




Monday, June 6, 2011
Second Implementation:




           %% there’s none.




Monday, June 6, 2011
Messaging




Monday, June 6, 2011
Messaging
                       • Share data across processes




Monday, June 6, 2011
Messaging
                       • Share data across processes
                       • Processes can be part of different apps




Monday, June 6, 2011
Messaging
                       • Share data across processes
                       • Processes can be part of different apps
                       • Apps can live in different machines



Monday, June 6, 2011
Messaging
                       • Share data across processes
                       • Processes can be part of different apps
                       • Apps can live in different machines
                       • Communication is Asynchronous


Monday, June 6, 2011
Main Concepts




Monday, June 6, 2011
Main Concepts

                       • Messages are sent by Producers




Monday, June 6, 2011
Main Concepts

                       • Messages are sent by Producers
                       • Messages are delivered to Consumers




Monday, June 6, 2011
Main Concepts

                       • Messages are sent by Producers
                       • Messages are delivered to Consumers
                       • Messages goes through a Channel



Monday, June 6, 2011
Messaging
                          and
                       RabbitMQ


Monday, June 6, 2011
What is RabbitMQ?



Monday, June 6, 2011
RabbitMQ

                       • Enterprise Messaging System
                       • Open Source MPL
                       • Written in Erlang/OTP
                       • Commercial Support
                       • Messaging via AMQP

Monday, June 6, 2011
Features

                       • Reliable and High Scalable
                       • Easy To install
                       • Easy To Cluster
                       • Runs on: Windows, Solaris, Linux, OSX
                       • AMQP 0.8 - 0.9.1

Monday, June 6, 2011
Client Libraries

                       • Java
                       • .NET/C#
                       • Erlang
                       • Ruby, Python, PHP, Perl, AS3, Lisp, Scala,
                         Clojure, Haskell



Monday, June 6, 2011
AMQP

                       • Advanced Message Queuing Protocol
                       • Suits Interoperability
                       • Completely Open Protocol
                       • Binary Protocol

Monday, June 6, 2011
Message Flow




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



Monday, June 6, 2011
AMQP Model

                       • Exchanges
                       • Message Queues
                       • Bindings
                       • Rules for binding them

Monday, June 6, 2011
Exchange Types

                       • Fanout
                       • Direct
                       • Topic


Monday, June 6, 2011
http://www.redhat.com/docs/en-US/Red_Hat_Enterprise_MRG/1.0/html/Messaging_Tutorial/sect-Messaging_Tutorial-Initial_Concepts-
                                                                         Fanout_Exchange.html




Monday, June 6, 2011
http://www.redhat.com/docs/en-US/Red_Hat_Enterprise_MRG/1.0/html/Messaging_Tutorial/sect-Messaging_Tutorial-Initial_Concepts-
                                                                          Direct_Exchange.html




Monday, June 6, 2011
http://www.redhat.com/docs/en-US/Red_Hat_Enterprise_MRG/1.0/html/Messaging_Tutorial/sect-Messaging_Tutorial-Initial_Concepts-
                                                                          Topic_Exchange.html




Monday, June 6, 2011
Messaging Patterns



Monday, June 6, 2011
There are many
                       messaging patterns




                          http://www.eaipatterns.com/
Monday, June 6, 2011
Basic Patterns



Monday, June 6, 2011
Competing Consumers

                        How can a messaging
                        client process multiple
                       messages concurrently?




Monday, June 6, 2011
Competing Consumers
                         Create multiple Competing
                       Consumers on a single channel
                         so that the consumers can
                        process multiple messages
                                concurrently.




Monday, June 6, 2011
Competing Consumers




Monday, June 6, 2011
Publisher Code
  init(Exchange, Queue) ->
      #'exchange.declare'{exchange = Exchange,
                          type = <<"direct">>,
                          durable = true},
      #'queue.declare'{queue = Queue, durable = false},
      #'queue.bind'{queue = Queue, exchange = Exchange}.




  publish_msg(Exchange, Payload) ->
      Props = #'P_basic'{content_type = <<"application/json">>,
                         delivery_mode = 2}, %% persistent
      publish(Exchange, #amqp_msg{props = Props, payload = Payload}).




Monday, June 6, 2011
Consumer Code
   init_consumer(Exchange, Queue) ->
       init(Exchange, Queue),
       #'basic.consume'{ticket = 0, queue = Queue}.



   on(#'basic.deliver'{delivery_tag = DeliveryTag},
      #amqp_msg{} = Msg) ->
         do_something_with_msg(Msg),
         #'basic.ack'{delivery_tag = DeliveryTag}.




Monday, June 6, 2011
Publish/Subscribe


                            How can the sender
                         broadcast an event to all
                           interested receivers?




Monday, June 6, 2011
Publish/Subscribe


                       Send the event on a Publish-Subscribe
                        Channel, which delivers a copy of a
                         particular event to each receiver.




Monday, June 6, 2011
Publish/Subscribe




Monday, June 6, 2011
Publisher Code
  init(Exchange, Queue) ->
      #'exchange.declare'{exchange = Exchange,
                          type = <<"fanout">>, %% different type
                          durable = true}
      %% same as before ...




  publish_msg(Exchange, Payload) ->
      Props = #'P_basic'{content_type = <<"application/json">>,
                         delivery_mode = 2}, %% persistent
      publish(Exchange, #amqp_msg{props = Props, payload = Payload}).




Monday, June 6, 2011
Consumer Code A
   init_consumer(Exchange, ResizeImageQueue) ->
       init(Exchange, ResizeImageQueue),
       #'basic.consume'{queue = ResizeImageQueue}.



   on(#'basic.deliver'{delivery_tag = DeliveryTag},
      #amqp_msg{} = Msg) ->
         resize_message(Msg),
         #'basic.ack'{delivery_tag = DeliveryTag}.




Monday, June 6, 2011
Consumer Code B
   init_consumer(Exchange, NotifyFriendsQueue) ->
       init(Exchange, NotifyFriendsQueue),
       #'basic.consume'{queue = NotifyFriendsQueue}.



   on(#'basic.deliver'{delivery_tag = DeliveryTag},
      #amqp_msg{} = Msg) ->
         notify_friends(Msg),
         #'basic.ack'{delivery_tag = DeliveryTag}.




Monday, June 6, 2011
Consumer Code C
   init_consumer(Exchange, LogImageUpload) ->
       init(Exchange, LogImageUpload),
       #'basic.consume'{queue = LogImageUpload}.



   on(#'basic.deliver'{delivery_tag = DeliveryTag},
      #amqp_msg{} = Msg) ->
         log_image_upload(Msg),
         #'basic.ack'{delivery_tag = DeliveryTag}.




Monday, June 6, 2011
Request/Reply


                       When an application sends a message,
                        how can it get a response from the
                                     receiver?




Monday, June 6, 2011
Request/Reply


                         Send a pair of Request-Reply
                       messages, each on its own channel.




Monday, June 6, 2011
Request/Reply




Monday, June 6, 2011
Return Address


                       How does a replier know where to
                              send the reply?




Monday, June 6, 2011
Return Address


                         The request message should contain a
                       Return Address that indicates where to send
                                   the reply message.




Monday, June 6, 2011
Return Address




Monday, June 6, 2011
Correlation Identifier


                         How does a requestor that has
                          received a reply know which
                          request this is the reply for?




Monday, June 6, 2011
Correlation Identifier


             Each reply message should contain a Correlation
             Identifier, a unique identifier that indicates which
                     request message this reply is for.




Monday, June 6, 2011
Correlation Identifier




Monday, June 6, 2011
Putting it all together



Monday, June 6, 2011
RPC Client
  init() ->
      #'queue.declare_ok'{queue = SelfQueue} =
          #'queue.declare'{exclusive = true, auto_delete = true},
      #'basic.consume'{queue = SelfQueue, no_ack = true},
      SelfQueue.




Monday, June 6, 2011
RPC Client
  init() ->
      #'queue.declare_ok'{queue = SelfQueue} =
          #'queue.declare'{exclusive = true, auto_delete = true},
      #'basic.consume'{queue = SelfQueue, no_ack = true},
      SelfQueue.


  request(Payload, RequestId) ->
      Props = #'P_basic'{correlation_id = RequestId,
                         reply_to = SelfQueue},
      publish(ServerExchange, #amqp_msg{props = Props,
                                        payload = Payload}).




Monday, June 6, 2011
RPC Client
  init() ->
      #'queue.declare_ok'{queue = SelfQueue} =
          #'queue.declare'{exclusive = true, auto_delete = true},
      #'basic.consume'{queue = SelfQueue, no_ack = true},
      SelfQueue.


  request(Payload, RequestId) ->
      Props = #'P_basic'{correlation_id = RequestId,
                         reply_to = SelfQueue},
      publish(ServerExchange, #amqp_msg{props = Props,
                                        payload = Payload}).

  on(#'basic.deliver'{},
     #amqp_msg{props = Props, payload = Payload}) ->
      CorrelationId = Props.correlation_id,
      do_something_with_reply(Payload).


Monday, June 6, 2011
RPC Server
  on(#'basic.deliver'{},
     #amqp_msg{props = Props, payload = Payload}) ->

           CorrelationId = Props.correlation_id,

           ReplyTo = Props.reply_to,

           Reply = process_request(Payload),

           NewProps = #'P_basic'{correlation_id = CorrelationId},

           publish("", %% anonymous exchange
                  #amqp_msg{props = NewProps,
                            payload = Reply},
                   ReplyTo). %% routing key


Monday, June 6, 2011
Advanced Patterns



Monday, June 6, 2011
Control Bus


                How can we effectively administer a messaging
                  system that is distributed across multiple
                   platforms and a wide geographic area?




Monday, June 6, 2011
Control Bus

                       Use a Control Bus to
                       manage an enterprise
                        integration system.




Monday, June 6, 2011
Control Bus

                       • Send Configuration Messages
                       • Start/Stop Services
                       • Inject Test Messages
                       • Collect Statistics

Monday, June 6, 2011
Control Bus




Monday, June 6, 2011
Control Bus

                          Make Services
                       “Control Bus” Enabled




Monday, June 6, 2011
Detour

                        How can you route a message through
                       intermediate steps to perform validation,
                            testing or debugging functions?




Monday, June 6, 2011
Detour
                Construct a Detour with a context-based router
                       controlled via the Control Bus.
           In one state the router routes incoming messages
          through additional steps while in the other it routes
             messages directly to the destination channel.




Monday, June 6, 2011
Detour




Monday, June 6, 2011
Wire Tap

                       How do you inspect messages that
                       travel on a point-to-point channel?




Monday, June 6, 2011
Wire Tap

            Insert a simple Recipient List into the channel that
              publishes each incoming message to the main
                     channel and a secondary channel.




Monday, June 6, 2011
Wire Tap

                       How do you inspect messages that
                       travel on a point-to-point channel?




Monday, June 6, 2011
Wire Tap

            Insert a simple Recipient List into the channel that
              publishes each incoming message to the main
                     channel and a secondary channel.




Monday, June 6, 2011
Wire Tap




Monday, June 6, 2011
Smart Proxy

               How can you track messages on a service that
              publishes reply messages to the Return Address
                        specified by the requestor?




Monday, June 6, 2011
Smart Proxy
                       Use a Smart Proxy to store the Return
                         Address supplied by the original
                         requestor and replace it with the
                           address of the Smart Proxy.


                         When the service sends the reply
                       message route it to the original Return
                                    Address.



Monday, June 6, 2011
Smart Proxy




Monday, June 6, 2011
Credits
                       Pattern graphics and description taken from:
                               http://www.eaipatterns.com/




Monday, June 6, 2011
Thanks!
                                    @old_sound
                          http://vimeo.com/user1169087
                       http://www.slideshare.net/old_sound


Monday, June 6, 2011

Weitere ähnliche Inhalte

Ähnlich wie Messaging patterns

Javascript Views, Client-side or Server-side with NodeJS
Javascript Views, Client-side or Server-side with NodeJSJavascript Views, Client-side or Server-side with NodeJS
Javascript Views, Client-side or Server-side with NodeJSSylvain Zimmer
 
Uxcampla deck jamyli
Uxcampla deck jamyliUxcampla deck jamyli
Uxcampla deck jamyliJamy Li
 
iPhone Python love affair
iPhone Python love affairiPhone Python love affair
iPhone Python love affairAnna Callahan
 
Koss, How to make desktop caliber browser apps
Koss, How to make desktop caliber browser appsKoss, How to make desktop caliber browser apps
Koss, How to make desktop caliber browser appsEvil Martians
 
Mobility in the financial industry
Mobility in the financial industryMobility in the financial industry
Mobility in the financial industryVincent Everts
 
Devops workshop unit2
Devops workshop unit2Devops workshop unit2
Devops workshop unit2John Willis
 
Consumer behavior and mobile payments for tech map amsterdam
Consumer behavior and mobile payments for tech map amsterdamConsumer behavior and mobile payments for tech map amsterdam
Consumer behavior and mobile payments for tech map amsterdamSteven Zwerink
 
Data Journalism 2: Interrogating, Visualising and Mashing
Data Journalism 2: Interrogating, Visualising and MashingData Journalism 2: Interrogating, Visualising and Mashing
Data Journalism 2: Interrogating, Visualising and MashingPaul Bradshaw
 
LT 08 - Guilherme Silveira - Cache hipermidia
LT 08 - Guilherme Silveira - Cache hipermidiaLT 08 - Guilherme Silveira - Cache hipermidia
LT 08 - Guilherme Silveira - Cache hipermidiaDNAD
 
Puppet camp europe 2011 hackability
Puppet camp europe 2011   hackabilityPuppet camp europe 2011   hackability
Puppet camp europe 2011 hackabilityPuppet
 
Preso color-athens-may2011-partone
Preso color-athens-may2011-partonePreso color-athens-may2011-partone
Preso color-athens-may2011-partoneRonnie Overgoor
 
2011 June - Singapore GTUG presentation. App Engine program update + intro to Go
2011 June - Singapore GTUG presentation. App Engine program update + intro to Go2011 June - Singapore GTUG presentation. App Engine program update + intro to Go
2011 June - Singapore GTUG presentation. App Engine program update + intro to Goikailan
 
Preso color-athens-may2011-parttwo
Preso color-athens-may2011-parttwoPreso color-athens-may2011-parttwo
Preso color-athens-may2011-parttwoRonnie Overgoor
 
Cundal gathering june 2011
Cundal gathering june 2011Cundal gathering june 2011
Cundal gathering june 2011Soren Harner
 
iPhone App from concept to product
iPhone App from concept to productiPhone App from concept to product
iPhone App from concept to productjoeysim
 
让开发也懂前端
让开发也懂前端让开发也懂前端
让开发也懂前端lifesinger
 
Scaling atlassian os v4
Scaling atlassian os v4Scaling atlassian os v4
Scaling atlassian os v4Soren Harner
 

Ähnlich wie Messaging patterns (20)

Javascript Views, Client-side or Server-side with NodeJS
Javascript Views, Client-side or Server-side with NodeJSJavascript Views, Client-side or Server-side with NodeJS
Javascript Views, Client-side or Server-side with NodeJS
 
Uxcampla deck jamyli
Uxcampla deck jamyliUxcampla deck jamyli
Uxcampla deck jamyli
 
iPhone Python love affair
iPhone Python love affairiPhone Python love affair
iPhone Python love affair
 
Koss, How to make desktop caliber browser apps
Koss, How to make desktop caliber browser appsKoss, How to make desktop caliber browser apps
Koss, How to make desktop caliber browser apps
 
Mobility in the financial industry
Mobility in the financial industryMobility in the financial industry
Mobility in the financial industry
 
Devops workshop unit2
Devops workshop unit2Devops workshop unit2
Devops workshop unit2
 
ITP / SED Day 2
ITP / SED Day 2ITP / SED Day 2
ITP / SED Day 2
 
Consumer behavior and mobile payments for tech map amsterdam
Consumer behavior and mobile payments for tech map amsterdamConsumer behavior and mobile payments for tech map amsterdam
Consumer behavior and mobile payments for tech map amsterdam
 
Data Journalism 2: Interrogating, Visualising and Mashing
Data Journalism 2: Interrogating, Visualising and MashingData Journalism 2: Interrogating, Visualising and Mashing
Data Journalism 2: Interrogating, Visualising and Mashing
 
ITP / SED Day 4
ITP / SED Day 4ITP / SED Day 4
ITP / SED Day 4
 
Beyond Page Objects
Beyond Page ObjectsBeyond Page Objects
Beyond Page Objects
 
LT 08 - Guilherme Silveira - Cache hipermidia
LT 08 - Guilherme Silveira - Cache hipermidiaLT 08 - Guilherme Silveira - Cache hipermidia
LT 08 - Guilherme Silveira - Cache hipermidia
 
Puppet camp europe 2011 hackability
Puppet camp europe 2011   hackabilityPuppet camp europe 2011   hackability
Puppet camp europe 2011 hackability
 
Preso color-athens-may2011-partone
Preso color-athens-may2011-partonePreso color-athens-may2011-partone
Preso color-athens-may2011-partone
 
2011 June - Singapore GTUG presentation. App Engine program update + intro to Go
2011 June - Singapore GTUG presentation. App Engine program update + intro to Go2011 June - Singapore GTUG presentation. App Engine program update + intro to Go
2011 June - Singapore GTUG presentation. App Engine program update + intro to Go
 
Preso color-athens-may2011-parttwo
Preso color-athens-may2011-parttwoPreso color-athens-may2011-parttwo
Preso color-athens-may2011-parttwo
 
Cundal gathering june 2011
Cundal gathering june 2011Cundal gathering june 2011
Cundal gathering june 2011
 
iPhone App from concept to product
iPhone App from concept to productiPhone App from concept to product
iPhone App from concept to product
 
让开发也懂前端
让开发也懂前端让开发也懂前端
让开发也懂前端
 
Scaling atlassian os v4
Scaling atlassian os v4Scaling atlassian os v4
Scaling atlassian os v4
 

Mehr von Alvaro Videla

Improvements in RabbitMQ
Improvements in RabbitMQImprovements in RabbitMQ
Improvements in RabbitMQAlvaro Videla
 
Data Migration at Scale with RabbitMQ and Spring Integration
Data Migration at Scale with RabbitMQ and Spring IntegrationData Migration at Scale with RabbitMQ and Spring Integration
Data Migration at Scale with RabbitMQ and Spring IntegrationAlvaro Videla
 
RabbitMQ Data Ingestion at Craft Conf
RabbitMQ Data Ingestion at Craft ConfRabbitMQ Data Ingestion at Craft Conf
RabbitMQ Data Ingestion at Craft ConfAlvaro Videla
 
Scaling applications with RabbitMQ at SunshinePHP
Scaling applications with RabbitMQ   at SunshinePHPScaling applications with RabbitMQ   at SunshinePHP
Scaling applications with RabbitMQ at SunshinePHPAlvaro Videla
 
Unit Test + Functional Programming = Love
Unit Test + Functional Programming = LoveUnit Test + Functional Programming = Love
Unit Test + Functional Programming = LoveAlvaro Videla
 
RabbitMQ Data Ingestion
RabbitMQ Data IngestionRabbitMQ Data Ingestion
RabbitMQ Data IngestionAlvaro Videla
 
Dissecting the rabbit: RabbitMQ Internal Architecture
Dissecting the rabbit: RabbitMQ Internal ArchitectureDissecting the rabbit: RabbitMQ Internal Architecture
Dissecting the rabbit: RabbitMQ Internal ArchitectureAlvaro Videla
 
Introduction to RabbitMQ | Meetup at Pivotal Labs
Introduction to RabbitMQ | Meetup at Pivotal LabsIntroduction to RabbitMQ | Meetup at Pivotal Labs
Introduction to RabbitMQ | Meetup at Pivotal LabsAlvaro Videla
 
Writing testable code
Writing testable codeWriting testable code
Writing testable codeAlvaro Videla
 
Rabbitmq Boot System
Rabbitmq Boot SystemRabbitmq Boot System
Rabbitmq Boot SystemAlvaro Videla
 
Cloud Foundry Bootcamp
Cloud Foundry BootcampCloud Foundry Bootcamp
Cloud Foundry BootcampAlvaro Videla
 
Cloud Messaging With Cloud Foundry
Cloud Messaging With Cloud FoundryCloud Messaging With Cloud Foundry
Cloud Messaging With Cloud FoundryAlvaro Videla
 
Código Fácil De Testear
Código Fácil De TestearCódigo Fácil De Testear
Código Fácil De TestearAlvaro Videla
 
Theres a rabbit on my symfony
Theres a rabbit on my symfonyTheres a rabbit on my symfony
Theres a rabbit on my symfonyAlvaro Videla
 
Scaling Web Apps With RabbitMQ - Erlang Factory Lite
Scaling Web Apps With RabbitMQ - Erlang Factory LiteScaling Web Apps With RabbitMQ - Erlang Factory Lite
Scaling Web Apps With RabbitMQ - Erlang Factory LiteAlvaro Videla
 
Integrating php withrabbitmq_zendcon
Integrating php withrabbitmq_zendconIntegrating php withrabbitmq_zendcon
Integrating php withrabbitmq_zendconAlvaro Videla
 
Scaling webappswithrabbitmq
Scaling webappswithrabbitmqScaling webappswithrabbitmq
Scaling webappswithrabbitmqAlvaro Videla
 

Mehr von Alvaro Videla (20)

Improvements in RabbitMQ
Improvements in RabbitMQImprovements in RabbitMQ
Improvements in RabbitMQ
 
Data Migration at Scale with RabbitMQ and Spring Integration
Data Migration at Scale with RabbitMQ and Spring IntegrationData Migration at Scale with RabbitMQ and Spring Integration
Data Migration at Scale with RabbitMQ and Spring Integration
 
RabbitMQ Data Ingestion at Craft Conf
RabbitMQ Data Ingestion at Craft ConfRabbitMQ Data Ingestion at Craft Conf
RabbitMQ Data Ingestion at Craft Conf
 
Scaling applications with RabbitMQ at SunshinePHP
Scaling applications with RabbitMQ   at SunshinePHPScaling applications with RabbitMQ   at SunshinePHP
Scaling applications with RabbitMQ at SunshinePHP
 
Unit Test + Functional Programming = Love
Unit Test + Functional Programming = LoveUnit Test + Functional Programming = Love
Unit Test + Functional Programming = Love
 
RabbitMQ Data Ingestion
RabbitMQ Data IngestionRabbitMQ Data Ingestion
RabbitMQ Data Ingestion
 
Dissecting the rabbit: RabbitMQ Internal Architecture
Dissecting the rabbit: RabbitMQ Internal ArchitectureDissecting the rabbit: RabbitMQ Internal Architecture
Dissecting the rabbit: RabbitMQ Internal Architecture
 
Introduction to RabbitMQ | Meetup at Pivotal Labs
Introduction to RabbitMQ | Meetup at Pivotal LabsIntroduction to RabbitMQ | Meetup at Pivotal Labs
Introduction to RabbitMQ | Meetup at Pivotal Labs
 
Writing testable code
Writing testable codeWriting testable code
Writing testable code
 
RabbitMQ Hands On
RabbitMQ Hands OnRabbitMQ Hands On
RabbitMQ Hands On
 
Rabbitmq Boot System
Rabbitmq Boot SystemRabbitmq Boot System
Rabbitmq Boot System
 
Cloud Foundry Bootcamp
Cloud Foundry BootcampCloud Foundry Bootcamp
Cloud Foundry Bootcamp
 
Cloud Messaging With Cloud Foundry
Cloud Messaging With Cloud FoundryCloud Messaging With Cloud Foundry
Cloud Messaging With Cloud Foundry
 
Taming the rabbit
Taming the rabbitTaming the rabbit
Taming the rabbit
 
Vertx
VertxVertx
Vertx
 
Código Fácil De Testear
Código Fácil De TestearCódigo Fácil De Testear
Código Fácil De Testear
 
Theres a rabbit on my symfony
Theres a rabbit on my symfonyTheres a rabbit on my symfony
Theres a rabbit on my symfony
 
Scaling Web Apps With RabbitMQ - Erlang Factory Lite
Scaling Web Apps With RabbitMQ - Erlang Factory LiteScaling Web Apps With RabbitMQ - Erlang Factory Lite
Scaling Web Apps With RabbitMQ - Erlang Factory Lite
 
Integrating php withrabbitmq_zendcon
Integrating php withrabbitmq_zendconIntegrating php withrabbitmq_zendcon
Integrating php withrabbitmq_zendcon
 
Scaling webappswithrabbitmq
Scaling webappswithrabbitmqScaling webappswithrabbitmq
Scaling webappswithrabbitmq
 

Kürzlich hochgeladen

Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????blackmambaettijean
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 

Kürzlich hochgeladen (20)

Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 

Messaging patterns

  • 1. Messaging Patterns Álvaro Videla - Liip AG Monday, June 6, 2011
  • 2. About Me • Developer at Liip AG • Blog: http://videlalvaro.github.com/ • Twitter: @old_sound Monday, June 6, 2011
  • 3. About Me Co-authoring RabbitMQ in Action http://bit.ly/rabbitmq Monday, June 6, 2011
  • 4. Why Do I need Messaging? Monday, June 6, 2011
  • 6. Implement a Photo Gallery Monday, June 6, 2011
  • 9. ‘Till new requirements arrive Monday, June 6, 2011
  • 11. Can we also notify the user friends when she uploads a new image? Monday, June 6, 2011
  • 12. Can we also notify the user friends when she uploads a new image? I forgot to mention we need it for tomorrow… Monday, June 6, 2011
  • 13. The Social Media Guru Monday, June 6, 2011
  • 14. We need to give badges to users for each picture upload Monday, June 6, 2011
  • 15. We need to give badges to users for each picture upload and post uploads to Twitter Monday, June 6, 2011
  • 17. Dumb! You’re delivering full size images! The bandwidth bill has tripled! Monday, June 6, 2011
  • 18. Dumb! You’re delivering full size images! The bandwidth bill has tripled! We need this fixed for yesterday! Monday, June 6, 2011
  • 19. The Developer in the other team Monday, June 6, 2011
  • 20. I need to call your PHP stuff but from Python Monday, June 6, 2011
  • 21. I need to call your PHP stuff but from Python And also Java starting next week Monday, June 6, 2011
  • 23. I don’t want to wait till your app resizes my image! Monday, June 6, 2011
  • 26. Let’s see the code evolution Monday, June 6, 2011
  • 27. First Implementation: %% image_controller handle('PUT', "/user/image", ReqData) -> image_handler:do_upload(ReqData:get_file()), ok. Monday, June 6, 2011
  • 28. Second Implementation: %% image_controller handle('PUT', "/user/image", ReqData) -> {ok, Image} = image_handler:do_upload(ReqData:get_file()), resize_image(Image), ok. Monday, June 6, 2011
  • 29. Third Implementation: %% image_controller handle('PUT', "/user/image", ReqData) -> {ok, Image} = image_handler:do_upload(ReqData:get_file()), resize_image(Image), notify_friends(ReqData:get_user()), ok. Monday, June 6, 2011
  • 30. Fourth Implementation: %% image_controller handle('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. Monday, June 6, 2011
  • 31. Final Implementation: %% image_controller handle('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. Monday, June 6, 2011
  • 32. Can our code scale to new requirements? Monday, June 6, 2011
  • 34. What if • We need to speed up image conversion Monday, June 6, 2011
  • 35. What if • We need to speed up image conversion • User notification has to be sent by email Monday, June 6, 2011
  • 36. What if • We need to speed up image conversion • User notification has to be sent by email • Stop tweeting about new images Monday, June 6, 2011
  • 37. What if • We need to speed up image conversion • User notification has to be sent by email • Stop tweeting about new images • Resize in different formats Monday, June 6, 2011
  • 38. Can we do better? Monday, June 6, 2011
  • 39. Sure. Using messaging Monday, June 6, 2011
  • 40. Design Publish / Subscribe Pattern Monday, June 6, 2011
  • 41. First Implementation: %% image_controller handle('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). Monday, June 6, 2011
  • 42. First Implementation: %% image_controller handle('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). %% friends notifier on('new_image', Msg) -> notify_friends(Msg.user, Msg.image). Monday, June 6, 2011
  • 43. First Implementation: %% image_controller handle('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). %% friends notifier on('new_image', Msg) -> notify_friends(Msg.user, Msg.image). %% points manager on('new_image', Msg) -> add_points(Msg.user, 'new_image'). Monday, June 6, 2011
  • 44. First Implementation: %% image_controller handle('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). %% friends notifier on('new_image', Msg) -> notify_friends(Msg.user, Msg.image). %% points manager on('new_image', Msg) -> add_points(Msg.user, 'new_image'). %% resizer on('new_image', Msg) -> resize_image(Msg.image). Monday, June 6, 2011
  • 46. Second Implementation: %% there’s none. Monday, June 6, 2011
  • 48. Messaging • Share data across processes Monday, June 6, 2011
  • 49. Messaging • Share data across processes • Processes can be part of different apps Monday, June 6, 2011
  • 50. Messaging • Share data across processes • Processes can be part of different apps • Apps can live in different machines Monday, June 6, 2011
  • 51. Messaging • Share data across processes • Processes can be part of different apps • Apps can live in different machines • Communication is Asynchronous Monday, June 6, 2011
  • 53. Main Concepts • Messages are sent by Producers Monday, June 6, 2011
  • 54. Main Concepts • Messages are sent by Producers • Messages are delivered to Consumers Monday, June 6, 2011
  • 55. Main Concepts • Messages are sent by Producers • Messages are delivered to Consumers • Messages goes through a Channel Monday, June 6, 2011
  • 56. Messaging and RabbitMQ Monday, June 6, 2011
  • 58. RabbitMQ • Enterprise Messaging System • Open Source MPL • Written in Erlang/OTP • Commercial Support • Messaging via AMQP Monday, June 6, 2011
  • 59. Features • Reliable and High Scalable • Easy To install • Easy To Cluster • Runs on: Windows, Solaris, Linux, OSX • AMQP 0.8 - 0.9.1 Monday, June 6, 2011
  • 60. Client Libraries • Java • .NET/C# • Erlang • Ruby, Python, PHP, Perl, AS3, Lisp, Scala, Clojure, Haskell Monday, June 6, 2011
  • 61. AMQP • Advanced Message Queuing Protocol • Suits Interoperability • Completely Open Protocol • Binary Protocol Monday, June 6, 2011
  • 62. Message Flow http://www.redhat.com/docs/en-US/Red_Hat_Enterprise_MRG/1.0/html/Messaging_Tutorial/chap-Messaging_Tutorial-Initial_Concepts.html Monday, June 6, 2011
  • 63. AMQP Model • Exchanges • Message Queues • Bindings • Rules for binding them Monday, June 6, 2011
  • 64. Exchange Types • Fanout • Direct • Topic Monday, June 6, 2011
  • 69. There are many messaging patterns http://www.eaipatterns.com/ Monday, June 6, 2011
  • 71. Competing Consumers How can a messaging client process multiple messages concurrently? Monday, June 6, 2011
  • 72. Competing Consumers Create multiple Competing Consumers on a single channel so that the consumers can process multiple messages concurrently. Monday, June 6, 2011
  • 74. Publisher Code init(Exchange, Queue) -> #'exchange.declare'{exchange = Exchange, type = <<"direct">>, durable = true}, #'queue.declare'{queue = Queue, durable = false}, #'queue.bind'{queue = Queue, exchange = Exchange}. publish_msg(Exchange, Payload) -> Props = #'P_basic'{content_type = <<"application/json">>, delivery_mode = 2}, %% persistent publish(Exchange, #amqp_msg{props = Props, payload = Payload}). Monday, June 6, 2011
  • 75. Consumer Code init_consumer(Exchange, Queue) -> init(Exchange, Queue), #'basic.consume'{ticket = 0, queue = Queue}. on(#'basic.deliver'{delivery_tag = DeliveryTag}, #amqp_msg{} = Msg) -> do_something_with_msg(Msg), #'basic.ack'{delivery_tag = DeliveryTag}. Monday, June 6, 2011
  • 76. Publish/Subscribe How can the sender broadcast an event to all interested receivers? Monday, June 6, 2011
  • 77. Publish/Subscribe Send the event on a Publish-Subscribe Channel, which delivers a copy of a particular event to each receiver. Monday, June 6, 2011
  • 79. Publisher Code init(Exchange, Queue) -> #'exchange.declare'{exchange = Exchange, type = <<"fanout">>, %% different type durable = true} %% same as before ... publish_msg(Exchange, Payload) -> Props = #'P_basic'{content_type = <<"application/json">>, delivery_mode = 2}, %% persistent publish(Exchange, #amqp_msg{props = Props, payload = Payload}). Monday, June 6, 2011
  • 80. Consumer Code A init_consumer(Exchange, ResizeImageQueue) -> init(Exchange, ResizeImageQueue), #'basic.consume'{queue = ResizeImageQueue}. on(#'basic.deliver'{delivery_tag = DeliveryTag}, #amqp_msg{} = Msg) -> resize_message(Msg), #'basic.ack'{delivery_tag = DeliveryTag}. Monday, June 6, 2011
  • 81. Consumer Code B init_consumer(Exchange, NotifyFriendsQueue) -> init(Exchange, NotifyFriendsQueue), #'basic.consume'{queue = NotifyFriendsQueue}. on(#'basic.deliver'{delivery_tag = DeliveryTag}, #amqp_msg{} = Msg) -> notify_friends(Msg), #'basic.ack'{delivery_tag = DeliveryTag}. Monday, June 6, 2011
  • 82. Consumer Code C init_consumer(Exchange, LogImageUpload) -> init(Exchange, LogImageUpload), #'basic.consume'{queue = LogImageUpload}. on(#'basic.deliver'{delivery_tag = DeliveryTag}, #amqp_msg{} = Msg) -> log_image_upload(Msg), #'basic.ack'{delivery_tag = DeliveryTag}. Monday, June 6, 2011
  • 83. Request/Reply When an application sends a message, how can it get a response from the receiver? Monday, June 6, 2011
  • 84. Request/Reply Send a pair of Request-Reply messages, each on its own channel. Monday, June 6, 2011
  • 86. Return Address How does a replier know where to send the reply? Monday, June 6, 2011
  • 87. Return Address The request message should contain a Return Address that indicates where to send the reply message. Monday, June 6, 2011
  • 89. Correlation Identifier How does a requestor that has received a reply know which request this is the reply for? Monday, June 6, 2011
  • 90. Correlation Identifier Each reply message should contain a Correlation Identifier, a unique identifier that indicates which request message this reply is for. Monday, June 6, 2011
  • 92. Putting it all together Monday, June 6, 2011
  • 93. RPC Client init() -> #'queue.declare_ok'{queue = SelfQueue} = #'queue.declare'{exclusive = true, auto_delete = true}, #'basic.consume'{queue = SelfQueue, no_ack = true}, SelfQueue. Monday, June 6, 2011
  • 94. RPC Client init() -> #'queue.declare_ok'{queue = SelfQueue} = #'queue.declare'{exclusive = true, auto_delete = true}, #'basic.consume'{queue = SelfQueue, no_ack = true}, SelfQueue. request(Payload, RequestId) -> Props = #'P_basic'{correlation_id = RequestId, reply_to = SelfQueue}, publish(ServerExchange, #amqp_msg{props = Props, payload = Payload}). Monday, June 6, 2011
  • 95. RPC Client init() -> #'queue.declare_ok'{queue = SelfQueue} = #'queue.declare'{exclusive = true, auto_delete = true}, #'basic.consume'{queue = SelfQueue, no_ack = true}, SelfQueue. request(Payload, RequestId) -> Props = #'P_basic'{correlation_id = RequestId, reply_to = SelfQueue}, publish(ServerExchange, #amqp_msg{props = Props, payload = Payload}). on(#'basic.deliver'{}, #amqp_msg{props = Props, payload = Payload}) -> CorrelationId = Props.correlation_id, do_something_with_reply(Payload). Monday, June 6, 2011
  • 96. RPC Server on(#'basic.deliver'{}, #amqp_msg{props = Props, payload = Payload}) -> CorrelationId = Props.correlation_id, ReplyTo = Props.reply_to, Reply = process_request(Payload), NewProps = #'P_basic'{correlation_id = CorrelationId}, publish("", %% anonymous exchange #amqp_msg{props = NewProps, payload = Reply}, ReplyTo). %% routing key Monday, June 6, 2011
  • 98. Control Bus How can we effectively administer a messaging system that is distributed across multiple platforms and a wide geographic area? Monday, June 6, 2011
  • 99. Control Bus Use a Control Bus to manage an enterprise integration system. Monday, June 6, 2011
  • 100. Control Bus • Send Configuration Messages • Start/Stop Services • Inject Test Messages • Collect Statistics Monday, June 6, 2011
  • 102. Control Bus Make Services “Control Bus” Enabled Monday, June 6, 2011
  • 103. Detour How can you route a message through intermediate steps to perform validation, testing or debugging functions? Monday, June 6, 2011
  • 104. Detour Construct a Detour with a context-based router controlled via the Control Bus. In one state the router routes incoming messages through additional steps while in the other it routes messages directly to the destination channel. Monday, June 6, 2011
  • 106. Wire Tap How do you inspect messages that travel on a point-to-point channel? Monday, June 6, 2011
  • 107. Wire Tap Insert a simple Recipient List into the channel that publishes each incoming message to the main channel and a secondary channel. Monday, June 6, 2011
  • 108. Wire Tap How do you inspect messages that travel on a point-to-point channel? Monday, June 6, 2011
  • 109. Wire Tap Insert a simple Recipient List into the channel that publishes each incoming message to the main channel and a secondary channel. Monday, June 6, 2011
  • 111. Smart Proxy How can you track messages on a service that publishes reply messages to the Return Address specified by the requestor? Monday, June 6, 2011
  • 112. Smart Proxy Use a Smart Proxy to store the Return Address supplied by the original requestor and replace it with the address of the Smart Proxy. When the service sends the reply message route it to the original Return Address. Monday, June 6, 2011
  • 114. Credits Pattern graphics and description taken from: http://www.eaipatterns.com/ Monday, June 6, 2011
  • 115. Thanks! @old_sound http://vimeo.com/user1169087 http://www.slideshare.net/old_sound Monday, June 6, 2011