SlideShare une entreprise Scribd logo
1  sur  40
Télécharger pour lire hors ligne
Messaging in the Cloud

AMQP, RabbitMQ and Spring




                                                         CONFIDENTIAL
                            © 2010 SpringSource, A division of VMware. All rights reserved
Messaging in the Cloud

  Need new levels of scalability

  Need a standardized wire protocol
 •  Won't ship a specific client for each environment
 •  Better interoperability


  JMS only defines an API and behavior, but no protocol

  AMQP defines a protocol




                                                           2
Why AMQP?

  Interoperability – like TCP and unlike JMS
 •  RabbitMQ leading the 2009 interoperability push around AMQP 0-9-1 towards
   AMQP 1.0
  Multiple vendors on one open, royalty-free standard
 •  You are not locked in
 •  Lower risk, lower price because of competition, easier to compare
 •  Products specialized around different areas of value e.g low latency, high
   stability, wide area
  Efficient – designed for today’s pubsub and queueing needs
 •  Binary wire protocol
 •  Support in all major languages
 •  Supported on most OS platforms
  Already in use by many major companies
  Future proof – backed by Cisco, Microsoft, VMware and many more

                                                                                 3
Broad platform and vendor support...




                                       4
RabbitMQ is used a lot in the Amazon Cloud
  RabbitMQ preferred to Amazon SQS




                                             5
Key AMQP messaging protocol requirements

  Internet protocol - like HTTP, TCP - but ASYNCHRONOUS

  Ubiquity: Open, easy & low barrier to use, understand and
 implement
  Safety: Secure and trusted global transaction network
  Fidelity: Well-stated message queuing, ordering and delivery
 semantics
  Applicability: any broker can talk to any client, support common
 messaging pattern and topologies
  Interoperability
  Manageability: Binary, scalable




                                                                      6
AMQP	
  in	
  a	
  nutshell	
  


Different
languages
Ruby, Java
…
                                              C
      P                X

                                              C

      P                X

                                              C

          AMQP                     AMQP
          protocol                 protocol



                                                  7
Exchange Types: Matching Algorithms

  Direct
  •  Routes on a routing key
  •  Two direct exchanges always exist
    •  amq.direct and the default exchange (with no public name) are mandatory
  Topic
  •  Routes on a routing pattern
  •  amq.direct is mandatory if the server supports topic exchanges
    •  Which it should according to the spec (whereas direct and fanout must be supported)
  Fanout
  •  Simple broadcast to all bound queues (no args when binding). Fast
  •  amq.fanout is mandatory

     Any Exchange that routes Messages to more than one
     queue will create multiple instances of the Message.

                                                                                             8
AMQP in more detail


                      Messages are stateless




                                               C
        P       X

                                               C

        P       X

                                               C


                                                   9
AMQP in more detail
                        Queues buffer messages for
    Exchanges are       push to consumers
X
    stateless routing
    tables.             Queues are stateful, ordered,
                        and can be persistent, transient,
                        private, shared.
                        Order might change if messages
                        are redelivered


                                            C
        P          X

                                            C

        P          X

                                            C


                                                      10
AMQP in more detail

    Queues are bound to named exchanges
    Binding can have a pattern e.g. “tony” (direct exchange)
    or “*.ibm.*” (topic exchange)




                                                     C
        P        X

                                                     C

        P        X

                                                     C


                                                               11
AMQP in more detail


P
    Producers send messages to exchanges with routing
    key e.g. “tony”, or ordered set of keys e.g.
    “buy.ibm.nyse”

    Exchanges route messages to queues whose binding
X
    pattern matches the message routing key or keys

                                                 C
        P       X

                                                 C

        P       X

                                                 C


                                                        12
Twi1er	
  style	
  pubsub	
  message	
  flow	
  

                                                                            C   Anders
                                  is at
           P             X        work                              is at
                                                                    work


Tony       P             X
               is at              is at                        is at
               work               work                         work         C   Evan

Evan and Anders want to follow what Tony says:
•  bind queues to a RabbitMQ exchange
•  pattern “tony”.

Tony publishes “is at work” to exchange using routing key “tony”.
Exchange updates Evan’s and Anders’ queues

Other patterns are possible e.g. for filtering by topic similar to this:
http://jchris.mfdz.com/posts/64
                                                                                       13
Producers	
  and	
  consumers	
  logically	
  interact	
  through	
  a	
  broker	
  cloud	
  

         C
 P                                                                                              C


  P                                                                                             P
                             X



                             X




                                                                                            P
 P
             P

                                                                                     C          C

                                                                                                    14
RabbitMQ and Spring




                                                   CONFIDENTIAL
                      © 2010 SpringSource, A division of VMware. All rights reserved
Configuring Rabbit Resources with Spring

  Spring enables decoupling of your application code from the
 underlying infrastructure
  The container provides the resources
  The application is simply coded against the API




                                                                 16
Configuring a ConnectionFactory



<bean id="connectionFactory"
       class="org.sfw.amqp.rabbit.connection.CachingConnectionFactory">
  <property name="username" value="guest"/>
  <property name="password" value="guest"/>
  <property name="channelCacheSize" value="42"/>
  <property name="hostName" value="localhost"/>
</bean>




Caches connection i.e. connection has to be stateless
i.e. can only be used for transactional access only (connection is stateful)
Otherwise use com.rabbitmq.client.ConnectionFactory



                                                                               17
Queues in RabbitMQ

  Queue deliver messages to at max one consumer
  Messages are sent to an exchange and can be routed to one or
 multiple queues
  Meta data about RabbitMQ Queues is stored in
 org.springframework.amqp.core.Queue:
 •  String name
 •  boolean durable
 •  boolean exclusive : private to one consumer
 •  boolean autoDelete
  Meta data can be used with RabbitAdminTemplate
 •  Call declare() to actually start using the Queue
  Afterwards they are identified by name
  Queues are bound to exchanges with routing keys
  Default: Bound using the name of the queues as routing key
                                                                  18
Exchanges in RabbitMQ

  Meta data about RabbitMQ Exchanges is stored
 •  DirectExchange : String as routing key, Queue binds to exchange with key
 •  FanoutExchange : No routing, what goes in must go out
 •  TopicExchange : Pattern as routing key
  String name
  boolean durable
  boolean autoDelete
  Each message received by an exchange will be delivered to each
 (qualifying) Queue bound to it




                                                                               19
Spring’s Templates

  AmqpTemplate: Generic AMQP interface
  RabbitOperations: Rabbit specific interface: (adds just a callback)
  RabbitTemplate: Implementation

  Spring might provide support for other AMQP implementations later
  Common interface




                                                                         20
Spring’s Templates

  Central point to send and receive messages
  Manages resources transparently
  Throws runtime exceptions
  Provides convenience methods and callbacks

public Message receive()
public Message receive(final String queueName)


public void send(MessageCreator messageCreator)
public void send(String routingKey, MessageCreator messageCreator)
public void send(String exchange, String routingKey, MessageCreator
 messageCreator)


                                                                  21
MessageConverter

  The RabbitTemplate uses a MessageConverter to convert between
 objects and messages
  The default SimpleMessageConverter handles basic types
 •  byte[] directly transfered
 •  String converted to byte[]
 •  Serializable serialized to byte[]
 •  Content type set accordingly
  JsonMessageConverter converts from / to JSON using Jackson
  MarshallingMessageConverter converts from / to XML using
 Spring's OXM mapping




                                                                   22
Defining a RabbitTemplate Bean

  Provide a reference to the ConnectionFactory
  Optionally provide other references
  •  MessageConverter
  •  Routing key and exchange to be used if none is specified



<bean id=“rabbitTemplate”
      class=“org.springframework.amqp.rabbit.core.RabbitTemplate”>
  <property name=“connectionFactory” ref=“connectionFactory”/>
  <property name=“messageConverter” ref=“messageConverter”/>
  <property name=“routingKey” value=“app.stock.request”/>
</bean>




                                                                     23
Sending Messages

  The template provides options
 •  One line methods that leverage the template’s MessageConverter
 •  Callback-accepting methods that offer more flexibility
  Use the simplest option for the task at hand




                                                                     24
Sending Messages with Conversion

  Leveraging the template’s MessageConverter




       public void convertAndSend(Object object);

       public void convertAndSend(String routingKey,
                                          Object object);

       public void convertAndSend(String exchange,
                                  String routingKey,
                                  Object object);


                                                            25
Sending Messages with Callbacks

  When more control is needed, use callbacks


public void convertAndSend(String routingKey, Object message,
 MessagePostProcessor messagePostProcessor);


public void send(MessageCreator messageCreator);
public void send(String routingKey, MessageCreator messageCreator);
public void send(String exchange, String routingKey,
 MessageCreator messageCreator);




        Message createMessage() {…}


                                                                      26
Setting the reply to / correlation ID

  Allows request / reply schema i.e. wait for the reply to the specific
      message
  Planned: sendAndReceive() as a direct implementation of this
      pattern

getRabbitTemplate().convertAndSend(tradeRequest, new MessagePostProcessor() {

public Message postProcessMessage(Message message)
  throws AmqpException {
   message.getMessageProperties().setReplyTo(
     new Address(defaultReplyToQueue));
   try {
      message.getMessageProperties().setCorrelationId(
       UUID.randomUUID().toString().getBytes("UTF-8"));
    } catch (UnsupportedEncodingException e) {
      throw new AmqpExcpetion(e);
    }
    return message;
}
                                                                           27
});
Synchronous Message Reception

  The RabbitTemplate can receive messages also
 •  receive() : Message
 •  receive(String queueName)
 •  receiveAndConvert()
 •  receiveAndConvert(String queueName)
  If no message is on the queue null is returned
  If no queueName is provided the queue name or queue set at the
 template will be used
  The MessageConverter can be leveraged for message reception as
 well
        Object someSerializable =
                 rabbitTemplate.receiveAndConvert();




                                                                    28
The MessageListener

  The API defines this interface for asynchronous reception of
 messages




            public void onMessage(Message) {
              // handle the message
            }




                                                                  29
Spring’s MessageListener Containers

  Spring provides lightweight containers to call MessageListeners
  SimpleMessageListenerContainer
  Advanced scheduling and endpoint management options available




                                                                     30
Defining a plain Message Listener


<bean id="messageListenerContainer"
   class="org.sfw.amqp.rabbit.listener.SimpleMessageListenerContainer">
  <property name="connectionFactory" ref="connectionFactory" />
  <property name="queueName"
   value="#{marketDataQueue.name},#{traderJoeQueue.name}"/>
  <property name="concurrentConsumers" value="5" />
  <property name="messageListener" ref="messageListenerAdapter" />
</bean>




                                                                          31
Spring's message-driven objects

  Spring also allows you to specify a plain Java object that can serve
  as a listener
<bean id="messageListenerAdapter"
  class="org.springframework.amqp.rabbit.listener.adapter.MessageListenerAdapter">
   <property name="delegate" ref="clientHandler" />
   <property name="messageConverter" ref="jsonMessageConverter" />
</bean>



  Parameter is automatically converted using a MessageConverter
  Return value sent to response-destination or the reply to
  Method with matching parameters is automatically called




                                                                               32
Demo: Hello World

  Producer send message using the RabbitTemplate
  Routing key : helloWorldQueue name "hello.world.queue"
  Goes to Default Exchange
  …and therefore to the helloWorldQueue (routing by name)
  Consumer receives message using the default receive queue
 (helloWorldQueue)

   Routing key:
   hello.world.queue

   P            X                                 C

            Default         helloWorldQueue
            Exchange        "hello.world.queue"



                                                               33
Demo: Stock Exchange

  Server sends stock prices
  Client receives stock prices
  Client can issue orders
  Orders are processed by the server
  Client receives confirmation of the trade

  Queues are private for one client




                                               34
Server sends stock prices




                        Routing key:
RabbitMarketDataGateway app.stockes.quote.?.? e.g.
called periodicaly      app.stockes.quote.nasdaq.ORCL

                      P                   X

                                     Topic
                                     Exchange
                                     app.stock.marketdata


                                                            35
Client receives stock prices

   Binding is created to attach the exchange to the queue using the
     routing key




      Routing key:
      app.stock.quotes.nasdaq.*

 X                                                              C

Topic                  marketDataQueue
Exchange               (private per consumer)
app.stock.marketdata                       ClientHandler in
                                           SimpleMessageListenerContainer
                                           with jsonMessageConverter and a
                                           MessageListenerAdapter


                                                                       36
Client can issue orders

  traderJoeQueue is set as reply to for the message




   Routing key:
   app.stock.request

   P             X

             Default
             Exchange



                                                       37
Server processes order

  Reply (i.e. confirmation) is sent to the reply to (trader Joe queue)




      X                                                C

 Default           stockRequestQueue      ServerHandler in
 Exchange          "app.stock.request"    SimpleMessageListenerContainer
                                          with jsonMessageConverter and a
                                          MessageListenerAdapter

                                                                          38
Client receives confirmation of the trade

   Binding is created to attach the exchange to the queue using the
     routing key




 X                                                             C

Default Exchange       traderJoeQueue
                                         ClientHandler in
                                         SimpleMessageListenerContainer
                                         with jsonMessageConverter and a
                                         MessageListenerAdapter


                                                                       39
Conclusion

  Ubiquitous Messaging
  AMQP: Protocol standard
  Better scalability

  http://springsource.org/spring-amqp
  Also a .NET version available




                                         40

Contenu connexe

Tendances

Messaging with amqp and rabbitmq
Messaging with amqp and rabbitmqMessaging with amqp and rabbitmq
Messaging with amqp and rabbitmqSelasie Hanson
 
Easy enterprise application integration with RabbitMQ and AMQP
Easy enterprise application integration with RabbitMQ and AMQPEasy enterprise application integration with RabbitMQ and AMQP
Easy enterprise application integration with RabbitMQ and AMQPRabbit MQ
 
[@NaukriEngineering] Messaging Queues
[@NaukriEngineering] Messaging Queues[@NaukriEngineering] Messaging Queues
[@NaukriEngineering] Messaging QueuesNaukri.com
 
Distributed messaging with AMQP
Distributed messaging with AMQPDistributed messaging with AMQP
Distributed messaging with AMQPWee Keat Chin
 
Introduction to AMQP Messaging with RabbitMQ
Introduction to AMQP Messaging with RabbitMQIntroduction to AMQP Messaging with RabbitMQ
Introduction to AMQP Messaging with RabbitMQDmitriy Samovskiy
 
Rabbitmq & Kafka Presentation
Rabbitmq & Kafka PresentationRabbitmq & Kafka Presentation
Rabbitmq & Kafka PresentationEmre Gündoğdu
 
RabbitMQ vs Apache Kafka Part II Webinar
RabbitMQ vs Apache Kafka Part II WebinarRabbitMQ vs Apache Kafka Part II Webinar
RabbitMQ vs Apache Kafka Part II WebinarErlang Solutions
 
Full Stack Bus with Javascript, RabbitMQ and Postal.js
Full Stack Bus with Javascript, RabbitMQ and Postal.jsFull Stack Bus with Javascript, RabbitMQ and Postal.js
Full Stack Bus with Javascript, RabbitMQ and Postal.jsJavier Arias Losada
 
AMQP and RabbitMQ (OKCJUG, January 2014)
AMQP and RabbitMQ (OKCJUG, January 2014)AMQP and RabbitMQ (OKCJUG, January 2014)
AMQP and RabbitMQ (OKCJUG, January 2014)Ryan Hoegg
 
Keynote: Idiomatic RabbitMQ - Gavin M Roy
Keynote: Idiomatic RabbitMQ - Gavin M RoyKeynote: Idiomatic RabbitMQ - Gavin M Roy
Keynote: Idiomatic RabbitMQ - Gavin M RoyRabbitMQ Summit
 
The RabbitMQ Message Broker
The RabbitMQ Message BrokerThe RabbitMQ Message Broker
The RabbitMQ Message BrokerMartin Toshev
 
Messaging Standards and Systems - AMQP & RabbitMQ
Messaging Standards and Systems - AMQP & RabbitMQMessaging Standards and Systems - AMQP & RabbitMQ
Messaging Standards and Systems - AMQP & RabbitMQAll Things Open
 

Tendances (20)

Amqp Basic
Amqp BasicAmqp Basic
Amqp Basic
 
Messaging with amqp and rabbitmq
Messaging with amqp and rabbitmqMessaging with amqp and rabbitmq
Messaging with amqp and rabbitmq
 
Easy enterprise application integration with RabbitMQ and AMQP
Easy enterprise application integration with RabbitMQ and AMQPEasy enterprise application integration with RabbitMQ and AMQP
Easy enterprise application integration with RabbitMQ and AMQP
 
[@NaukriEngineering] Messaging Queues
[@NaukriEngineering] Messaging Queues[@NaukriEngineering] Messaging Queues
[@NaukriEngineering] Messaging Queues
 
Distributed messaging with AMQP
Distributed messaging with AMQPDistributed messaging with AMQP
Distributed messaging with AMQP
 
Introduction to AMQP Messaging with RabbitMQ
Introduction to AMQP Messaging with RabbitMQIntroduction to AMQP Messaging with RabbitMQ
Introduction to AMQP Messaging with RabbitMQ
 
Rabbitmq & Kafka Presentation
Rabbitmq & Kafka PresentationRabbitmq & Kafka Presentation
Rabbitmq & Kafka Presentation
 
Rabbitmq basics
Rabbitmq basicsRabbitmq basics
Rabbitmq basics
 
A Closer Look at RabbitMQ
A Closer Look at RabbitMQA Closer Look at RabbitMQ
A Closer Look at RabbitMQ
 
RabbitMQ vs Apache Kafka Part II Webinar
RabbitMQ vs Apache Kafka Part II WebinarRabbitMQ vs Apache Kafka Part II Webinar
RabbitMQ vs Apache Kafka Part II Webinar
 
AMQP for phpMelb
AMQP for phpMelbAMQP for phpMelb
AMQP for phpMelb
 
Full Stack Bus with Javascript, RabbitMQ and Postal.js
Full Stack Bus with Javascript, RabbitMQ and Postal.jsFull Stack Bus with Javascript, RabbitMQ and Postal.js
Full Stack Bus with Javascript, RabbitMQ and Postal.js
 
AMQP 1.0 introduction
AMQP 1.0 introductionAMQP 1.0 introduction
AMQP 1.0 introduction
 
AMQP and RabbitMQ (OKCJUG, January 2014)
AMQP and RabbitMQ (OKCJUG, January 2014)AMQP and RabbitMQ (OKCJUG, January 2014)
AMQP and RabbitMQ (OKCJUG, January 2014)
 
Keynote: Idiomatic RabbitMQ - Gavin M Roy
Keynote: Idiomatic RabbitMQ - Gavin M RoyKeynote: Idiomatic RabbitMQ - Gavin M Roy
Keynote: Idiomatic RabbitMQ - Gavin M Roy
 
The RabbitMQ Message Broker
The RabbitMQ Message BrokerThe RabbitMQ Message Broker
The RabbitMQ Message Broker
 
Messaging Standards and Systems - AMQP & RabbitMQ
Messaging Standards and Systems - AMQP & RabbitMQMessaging Standards and Systems - AMQP & RabbitMQ
Messaging Standards and Systems - AMQP & RabbitMQ
 
RabbitMq
RabbitMqRabbitMq
RabbitMq
 
What is RabbitMQ ?
What is RabbitMQ ?What is RabbitMQ ?
What is RabbitMQ ?
 
Message Broker System and RabbitMQ
Message Broker System and RabbitMQMessage Broker System and RabbitMQ
Message Broker System and RabbitMQ
 

En vedette

RabbitMQ And Nanite
RabbitMQ And NaniteRabbitMQ And Nanite
RabbitMQ And Nanitemattmatt
 
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
 
Developing real-time data pipelines with Spring and Kafka
Developing real-time data pipelines with Spring and KafkaDeveloping real-time data pipelines with Spring and Kafka
Developing real-time data pipelines with Spring and Kafkamarius_bogoevici
 
RabbitMQ Data Ingestion
RabbitMQ Data IngestionRabbitMQ Data Ingestion
RabbitMQ Data IngestionAlvaro Videla
 
Microservices with Spring Cloud, Netflix OSS and Kubernetes
Microservices with Spring Cloud, Netflix OSS and Kubernetes Microservices with Spring Cloud, Netflix OSS and Kubernetes
Microservices with Spring Cloud, Netflix OSS and Kubernetes Christian Posta
 
Netflix0SS Services on Docker
Netflix0SS Services on DockerNetflix0SS Services on Docker
Netflix0SS Services on DockerDocker, Inc.
 
Microservices Journey NYC
Microservices Journey NYCMicroservices Journey NYC
Microservices Journey NYCChristian Posta
 
OpenShift Enterprise 3.1 vs kubernetes
OpenShift Enterprise 3.1 vs kubernetesOpenShift Enterprise 3.1 vs kubernetes
OpenShift Enterprise 3.1 vs kubernetesSamuel Terburg
 

En vedette (9)

RabbitMQ And Nanite
RabbitMQ And NaniteRabbitMQ And Nanite
RabbitMQ And Nanite
 
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
 
RabbitMQ Messaging
RabbitMQ MessagingRabbitMQ Messaging
RabbitMQ Messaging
 
Developing real-time data pipelines with Spring and Kafka
Developing real-time data pipelines with Spring and KafkaDeveloping real-time data pipelines with Spring and Kafka
Developing real-time data pipelines with Spring and Kafka
 
RabbitMQ Data Ingestion
RabbitMQ Data IngestionRabbitMQ Data Ingestion
RabbitMQ Data Ingestion
 
Microservices with Spring Cloud, Netflix OSS and Kubernetes
Microservices with Spring Cloud, Netflix OSS and Kubernetes Microservices with Spring Cloud, Netflix OSS and Kubernetes
Microservices with Spring Cloud, Netflix OSS and Kubernetes
 
Netflix0SS Services on Docker
Netflix0SS Services on DockerNetflix0SS Services on Docker
Netflix0SS Services on Docker
 
Microservices Journey NYC
Microservices Journey NYCMicroservices Journey NYC
Microservices Journey NYC
 
OpenShift Enterprise 3.1 vs kubernetes
OpenShift Enterprise 3.1 vs kubernetesOpenShift Enterprise 3.1 vs kubernetes
OpenShift Enterprise 3.1 vs kubernetes
 

Similaire à Messaging in the Cloud - AMQP, RabbitMQ and Spring

Commication Framework in OpenStack
Commication Framework in OpenStackCommication Framework in OpenStack
Commication Framework in OpenStackSean Chang
 
Messaging Standards and Systems - AMQP & RabbitMQ
Messaging Standards and Systems - AMQP & RabbitMQMessaging Standards and Systems - AMQP & RabbitMQ
Messaging Standards and Systems - AMQP & RabbitMQPOSSCON
 
Lindsay distributed geventzmq
Lindsay distributed geventzmqLindsay distributed geventzmq
Lindsay distributed geventzmqRobin Xiao
 
Rabbit MQ introduction
Rabbit MQ introductionRabbit MQ introduction
Rabbit MQ introductionSitg Yao
 
Down the RabbitMQ Hole
Down the RabbitMQ HoleDown the RabbitMQ Hole
Down the RabbitMQ HoleBizTalk360
 
Messaging for Modern Applications
Messaging for Modern ApplicationsMessaging for Modern Applications
Messaging for Modern ApplicationsTom McCuch
 
Mule with rabbit mq
Mule with rabbit mq Mule with rabbit mq
Mule with rabbit mq mdfkhan625
 
Mule with rabbitmq
Mule with rabbitmqMule with rabbitmq
Mule with rabbitmqRajkattamuri
 
Mule with rabbit mq
Mule with rabbit mq Mule with rabbit mq
Mule with rabbit mq javeed_mhd
 
Mule with rabbit mq
Mule with rabbit mqMule with rabbit mq
Mule with rabbit mqKhan625
 
Rabbit Mq in Mule
Rabbit Mq in MuleRabbit Mq in Mule
Rabbit Mq in MuleMohammed246
 
Mule with rabbit mq
Mule with rabbit mqMule with rabbit mq
Mule with rabbit mqHasan Syed
 
Rabbit mq messaginginthecloud_v_mworld_2010_ms
Rabbit mq messaginginthecloud_v_mworld_2010_msRabbit mq messaginginthecloud_v_mworld_2010_ms
Rabbit mq messaginginthecloud_v_mworld_2010_msliuhao1983
 
Rabbit mq messaginginthecloud_v_mworld_2010_ms
Rabbit mq messaginginthecloud_v_mworld_2010_msRabbit mq messaginginthecloud_v_mworld_2010_ms
Rabbit mq messaginginthecloud_v_mworld_2010_msRabbit MQ
 

Similaire à Messaging in the Cloud - AMQP, RabbitMQ and Spring (20)

Commication Framework in OpenStack
Commication Framework in OpenStackCommication Framework in OpenStack
Commication Framework in OpenStack
 
Messaging Standards and Systems - AMQP & RabbitMQ
Messaging Standards and Systems - AMQP & RabbitMQMessaging Standards and Systems - AMQP & RabbitMQ
Messaging Standards and Systems - AMQP & RabbitMQ
 
Lindsay distributed geventzmq
Lindsay distributed geventzmqLindsay distributed geventzmq
Lindsay distributed geventzmq
 
Rabbit MQ introduction
Rabbit MQ introductionRabbit MQ introduction
Rabbit MQ introduction
 
Down the RabbitMQ Hole
Down the RabbitMQ HoleDown the RabbitMQ Hole
Down the RabbitMQ Hole
 
Messaging for Modern Applications
Messaging for Modern ApplicationsMessaging for Modern Applications
Messaging for Modern Applications
 
Mule with rabbit mq
Mule with rabbit mqMule with rabbit mq
Mule with rabbit mq
 
Mule rabbitmq
Mule rabbitmqMule rabbitmq
Mule rabbitmq
 
Mule with rabbit mq
Mule with rabbit mq Mule with rabbit mq
Mule with rabbit mq
 
Mule with rabbitmq
Mule with rabbitmqMule with rabbitmq
Mule with rabbitmq
 
Mule with rabbit mq
Mule with rabbit mq Mule with rabbit mq
Mule with rabbit mq
 
Mule with rabbit mq
Mule with rabbit mqMule with rabbit mq
Mule with rabbit mq
 
Rabbit MQ
Rabbit MQRabbit MQ
Rabbit MQ
 
Mule with rabbit mq
Mule with rabbit mqMule with rabbit mq
Mule with rabbit mq
 
Rabbit Mq in Mule
Rabbit Mq in MuleRabbit Mq in Mule
Rabbit Mq in Mule
 
Mule with rabbit mq
Mule with rabbit mqMule with rabbit mq
Mule with rabbit mq
 
0mq
0mq0mq
0mq
 
Mule with rabbitmq
Mule with rabbitmqMule with rabbitmq
Mule with rabbitmq
 
Rabbit mq messaginginthecloud_v_mworld_2010_ms
Rabbit mq messaginginthecloud_v_mworld_2010_msRabbit mq messaginginthecloud_v_mworld_2010_ms
Rabbit mq messaginginthecloud_v_mworld_2010_ms
 
Rabbit mq messaginginthecloud_v_mworld_2010_ms
Rabbit mq messaginginthecloud_v_mworld_2010_msRabbit mq messaginginthecloud_v_mworld_2010_ms
Rabbit mq messaginginthecloud_v_mworld_2010_ms
 

Plus de Eberhard Wolff

Architectures and Alternatives
Architectures and AlternativesArchitectures and Alternatives
Architectures and AlternativesEberhard Wolff
 
The Frontiers of Continuous Delivery
The Frontiers of Continuous DeliveryThe Frontiers of Continuous Delivery
The Frontiers of Continuous DeliveryEberhard Wolff
 
Four Times Microservices - REST, Kubernetes, UI Integration, Async
Four Times Microservices - REST, Kubernetes, UI Integration, AsyncFour Times Microservices - REST, Kubernetes, UI Integration, Async
Four Times Microservices - REST, Kubernetes, UI Integration, AsyncEberhard Wolff
 
Microservices - not just with Java
Microservices - not just with JavaMicroservices - not just with Java
Microservices - not just with JavaEberhard Wolff
 
Deployment - Done Right!
Deployment - Done Right!Deployment - Done Right!
Deployment - Done Right!Eberhard Wolff
 
Data Architecture not Just for Microservices
Data Architecture not Just for MicroservicesData Architecture not Just for Microservices
Data Architecture not Just for MicroservicesEberhard Wolff
 
How to Split Your System into Microservices
How to Split Your System into MicroservicesHow to Split Your System into Microservices
How to Split Your System into MicroservicesEberhard Wolff
 
Microservices and Self-contained System to Scale Agile
Microservices and Self-contained System to Scale AgileMicroservices and Self-contained System to Scale Agile
Microservices and Self-contained System to Scale AgileEberhard Wolff
 
How Small Can Java Microservices Be?
How Small Can Java Microservices Be?How Small Can Java Microservices Be?
How Small Can Java Microservices Be?Eberhard Wolff
 
Data Architecturen Not Just for Microservices
Data Architecturen Not Just for MicroservicesData Architecturen Not Just for Microservices
Data Architecturen Not Just for MicroservicesEberhard Wolff
 
Microservices: Redundancy=Maintainability
Microservices: Redundancy=MaintainabilityMicroservices: Redundancy=Maintainability
Microservices: Redundancy=MaintainabilityEberhard Wolff
 
Self-contained Systems: A Different Approach to Microservices
Self-contained Systems: A Different Approach to MicroservicesSelf-contained Systems: A Different Approach to Microservices
Self-contained Systems: A Different Approach to MicroservicesEberhard Wolff
 
Microservices Technology Stack
Microservices Technology StackMicroservices Technology Stack
Microservices Technology StackEberhard Wolff
 
Software Architecture for Innovation
Software Architecture for InnovationSoftware Architecture for Innovation
Software Architecture for InnovationEberhard Wolff
 
Five (easy?) Steps Towards Continuous Delivery
Five (easy?) Steps Towards Continuous DeliveryFive (easy?) Steps Towards Continuous Delivery
Five (easy?) Steps Towards Continuous DeliveryEberhard Wolff
 
Nanoservices and Microservices with Java
Nanoservices and Microservices with JavaNanoservices and Microservices with Java
Nanoservices and Microservices with JavaEberhard Wolff
 
Microservices: Architecture to Support Agile
Microservices: Architecture to Support AgileMicroservices: Architecture to Support Agile
Microservices: Architecture to Support AgileEberhard Wolff
 
Microservices: Architecture to scale Agile
Microservices: Architecture to scale AgileMicroservices: Architecture to scale Agile
Microservices: Architecture to scale AgileEberhard Wolff
 
Microservices, DevOps, Continuous Delivery – More Than Three Buzzwords
Microservices, DevOps, Continuous Delivery – More Than Three BuzzwordsMicroservices, DevOps, Continuous Delivery – More Than Three Buzzwords
Microservices, DevOps, Continuous Delivery – More Than Three BuzzwordsEberhard Wolff
 

Plus de Eberhard Wolff (20)

Architectures and Alternatives
Architectures and AlternativesArchitectures and Alternatives
Architectures and Alternatives
 
Beyond Microservices
Beyond MicroservicesBeyond Microservices
Beyond Microservices
 
The Frontiers of Continuous Delivery
The Frontiers of Continuous DeliveryThe Frontiers of Continuous Delivery
The Frontiers of Continuous Delivery
 
Four Times Microservices - REST, Kubernetes, UI Integration, Async
Four Times Microservices - REST, Kubernetes, UI Integration, AsyncFour Times Microservices - REST, Kubernetes, UI Integration, Async
Four Times Microservices - REST, Kubernetes, UI Integration, Async
 
Microservices - not just with Java
Microservices - not just with JavaMicroservices - not just with Java
Microservices - not just with Java
 
Deployment - Done Right!
Deployment - Done Right!Deployment - Done Right!
Deployment - Done Right!
 
Data Architecture not Just for Microservices
Data Architecture not Just for MicroservicesData Architecture not Just for Microservices
Data Architecture not Just for Microservices
 
How to Split Your System into Microservices
How to Split Your System into MicroservicesHow to Split Your System into Microservices
How to Split Your System into Microservices
 
Microservices and Self-contained System to Scale Agile
Microservices and Self-contained System to Scale AgileMicroservices and Self-contained System to Scale Agile
Microservices and Self-contained System to Scale Agile
 
How Small Can Java Microservices Be?
How Small Can Java Microservices Be?How Small Can Java Microservices Be?
How Small Can Java Microservices Be?
 
Data Architecturen Not Just for Microservices
Data Architecturen Not Just for MicroservicesData Architecturen Not Just for Microservices
Data Architecturen Not Just for Microservices
 
Microservices: Redundancy=Maintainability
Microservices: Redundancy=MaintainabilityMicroservices: Redundancy=Maintainability
Microservices: Redundancy=Maintainability
 
Self-contained Systems: A Different Approach to Microservices
Self-contained Systems: A Different Approach to MicroservicesSelf-contained Systems: A Different Approach to Microservices
Self-contained Systems: A Different Approach to Microservices
 
Microservices Technology Stack
Microservices Technology StackMicroservices Technology Stack
Microservices Technology Stack
 
Software Architecture for Innovation
Software Architecture for InnovationSoftware Architecture for Innovation
Software Architecture for Innovation
 
Five (easy?) Steps Towards Continuous Delivery
Five (easy?) Steps Towards Continuous DeliveryFive (easy?) Steps Towards Continuous Delivery
Five (easy?) Steps Towards Continuous Delivery
 
Nanoservices and Microservices with Java
Nanoservices and Microservices with JavaNanoservices and Microservices with Java
Nanoservices and Microservices with Java
 
Microservices: Architecture to Support Agile
Microservices: Architecture to Support AgileMicroservices: Architecture to Support Agile
Microservices: Architecture to Support Agile
 
Microservices: Architecture to scale Agile
Microservices: Architecture to scale AgileMicroservices: Architecture to scale Agile
Microservices: Architecture to scale Agile
 
Microservices, DevOps, Continuous Delivery – More Than Three Buzzwords
Microservices, DevOps, Continuous Delivery – More Than Three BuzzwordsMicroservices, DevOps, Continuous Delivery – More Than Three Buzzwords
Microservices, DevOps, Continuous Delivery – More Than Three Buzzwords
 

Dernier

"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
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
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
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
 
"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
 
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
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
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
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
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
 
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
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
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
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 

Dernier (20)

"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
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
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
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
 
"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
 
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
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
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
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
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
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
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
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 

Messaging in the Cloud - AMQP, RabbitMQ and Spring

  • 1. Messaging in the Cloud AMQP, RabbitMQ and Spring CONFIDENTIAL © 2010 SpringSource, A division of VMware. All rights reserved
  • 2. Messaging in the Cloud   Need new levels of scalability   Need a standardized wire protocol •  Won't ship a specific client for each environment •  Better interoperability   JMS only defines an API and behavior, but no protocol   AMQP defines a protocol 2
  • 3. Why AMQP?   Interoperability – like TCP and unlike JMS •  RabbitMQ leading the 2009 interoperability push around AMQP 0-9-1 towards AMQP 1.0   Multiple vendors on one open, royalty-free standard •  You are not locked in •  Lower risk, lower price because of competition, easier to compare •  Products specialized around different areas of value e.g low latency, high stability, wide area   Efficient – designed for today’s pubsub and queueing needs •  Binary wire protocol •  Support in all major languages •  Supported on most OS platforms   Already in use by many major companies   Future proof – backed by Cisco, Microsoft, VMware and many more 3
  • 4. Broad platform and vendor support... 4
  • 5. RabbitMQ is used a lot in the Amazon Cloud   RabbitMQ preferred to Amazon SQS 5
  • 6. Key AMQP messaging protocol requirements   Internet protocol - like HTTP, TCP - but ASYNCHRONOUS   Ubiquity: Open, easy & low barrier to use, understand and implement   Safety: Secure and trusted global transaction network   Fidelity: Well-stated message queuing, ordering and delivery semantics   Applicability: any broker can talk to any client, support common messaging pattern and topologies   Interoperability   Manageability: Binary, scalable 6
  • 7. AMQP  in  a  nutshell   Different languages Ruby, Java … C P X C P X C AMQP AMQP protocol protocol 7
  • 8. Exchange Types: Matching Algorithms   Direct •  Routes on a routing key •  Two direct exchanges always exist •  amq.direct and the default exchange (with no public name) are mandatory   Topic •  Routes on a routing pattern •  amq.direct is mandatory if the server supports topic exchanges •  Which it should according to the spec (whereas direct and fanout must be supported)   Fanout •  Simple broadcast to all bound queues (no args when binding). Fast •  amq.fanout is mandatory Any Exchange that routes Messages to more than one queue will create multiple instances of the Message. 8
  • 9. AMQP in more detail Messages are stateless C P X C P X C 9
  • 10. AMQP in more detail Queues buffer messages for Exchanges are push to consumers X stateless routing tables. Queues are stateful, ordered, and can be persistent, transient, private, shared. Order might change if messages are redelivered C P X C P X C 10
  • 11. AMQP in more detail Queues are bound to named exchanges Binding can have a pattern e.g. “tony” (direct exchange) or “*.ibm.*” (topic exchange) C P X C P X C 11
  • 12. AMQP in more detail P Producers send messages to exchanges with routing key e.g. “tony”, or ordered set of keys e.g. “buy.ibm.nyse” Exchanges route messages to queues whose binding X pattern matches the message routing key or keys C P X C P X C 12
  • 13. Twi1er  style  pubsub  message  flow   C Anders is at P X work is at work Tony P X is at is at is at work work work C Evan Evan and Anders want to follow what Tony says: •  bind queues to a RabbitMQ exchange •  pattern “tony”. Tony publishes “is at work” to exchange using routing key “tony”. Exchange updates Evan’s and Anders’ queues Other patterns are possible e.g. for filtering by topic similar to this: http://jchris.mfdz.com/posts/64 13
  • 14. Producers  and  consumers  logically  interact  through  a  broker  cloud   C P C P P X X P P P C C 14
  • 15. RabbitMQ and Spring CONFIDENTIAL © 2010 SpringSource, A division of VMware. All rights reserved
  • 16. Configuring Rabbit Resources with Spring   Spring enables decoupling of your application code from the underlying infrastructure   The container provides the resources   The application is simply coded against the API 16
  • 17. Configuring a ConnectionFactory <bean id="connectionFactory" class="org.sfw.amqp.rabbit.connection.CachingConnectionFactory"> <property name="username" value="guest"/> <property name="password" value="guest"/> <property name="channelCacheSize" value="42"/> <property name="hostName" value="localhost"/> </bean> Caches connection i.e. connection has to be stateless i.e. can only be used for transactional access only (connection is stateful) Otherwise use com.rabbitmq.client.ConnectionFactory 17
  • 18. Queues in RabbitMQ   Queue deliver messages to at max one consumer   Messages are sent to an exchange and can be routed to one or multiple queues   Meta data about RabbitMQ Queues is stored in org.springframework.amqp.core.Queue: •  String name •  boolean durable •  boolean exclusive : private to one consumer •  boolean autoDelete   Meta data can be used with RabbitAdminTemplate •  Call declare() to actually start using the Queue   Afterwards they are identified by name   Queues are bound to exchanges with routing keys   Default: Bound using the name of the queues as routing key 18
  • 19. Exchanges in RabbitMQ   Meta data about RabbitMQ Exchanges is stored •  DirectExchange : String as routing key, Queue binds to exchange with key •  FanoutExchange : No routing, what goes in must go out •  TopicExchange : Pattern as routing key   String name   boolean durable   boolean autoDelete   Each message received by an exchange will be delivered to each (qualifying) Queue bound to it 19
  • 20. Spring’s Templates   AmqpTemplate: Generic AMQP interface   RabbitOperations: Rabbit specific interface: (adds just a callback)   RabbitTemplate: Implementation   Spring might provide support for other AMQP implementations later   Common interface 20
  • 21. Spring’s Templates   Central point to send and receive messages   Manages resources transparently   Throws runtime exceptions   Provides convenience methods and callbacks public Message receive() public Message receive(final String queueName) public void send(MessageCreator messageCreator) public void send(String routingKey, MessageCreator messageCreator) public void send(String exchange, String routingKey, MessageCreator messageCreator) 21
  • 22. MessageConverter   The RabbitTemplate uses a MessageConverter to convert between objects and messages   The default SimpleMessageConverter handles basic types •  byte[] directly transfered •  String converted to byte[] •  Serializable serialized to byte[] •  Content type set accordingly   JsonMessageConverter converts from / to JSON using Jackson   MarshallingMessageConverter converts from / to XML using Spring's OXM mapping 22
  • 23. Defining a RabbitTemplate Bean   Provide a reference to the ConnectionFactory   Optionally provide other references •  MessageConverter •  Routing key and exchange to be used if none is specified <bean id=“rabbitTemplate” class=“org.springframework.amqp.rabbit.core.RabbitTemplate”> <property name=“connectionFactory” ref=“connectionFactory”/> <property name=“messageConverter” ref=“messageConverter”/> <property name=“routingKey” value=“app.stock.request”/> </bean> 23
  • 24. Sending Messages   The template provides options •  One line methods that leverage the template’s MessageConverter •  Callback-accepting methods that offer more flexibility   Use the simplest option for the task at hand 24
  • 25. Sending Messages with Conversion   Leveraging the template’s MessageConverter public void convertAndSend(Object object); public void convertAndSend(String routingKey, Object object); public void convertAndSend(String exchange, String routingKey, Object object); 25
  • 26. Sending Messages with Callbacks   When more control is needed, use callbacks public void convertAndSend(String routingKey, Object message, MessagePostProcessor messagePostProcessor); public void send(MessageCreator messageCreator); public void send(String routingKey, MessageCreator messageCreator); public void send(String exchange, String routingKey, MessageCreator messageCreator); Message createMessage() {…} 26
  • 27. Setting the reply to / correlation ID   Allows request / reply schema i.e. wait for the reply to the specific message   Planned: sendAndReceive() as a direct implementation of this pattern getRabbitTemplate().convertAndSend(tradeRequest, new MessagePostProcessor() { public Message postProcessMessage(Message message) throws AmqpException { message.getMessageProperties().setReplyTo( new Address(defaultReplyToQueue)); try { message.getMessageProperties().setCorrelationId( UUID.randomUUID().toString().getBytes("UTF-8")); } catch (UnsupportedEncodingException e) { throw new AmqpExcpetion(e); } return message; } 27 });
  • 28. Synchronous Message Reception   The RabbitTemplate can receive messages also •  receive() : Message •  receive(String queueName) •  receiveAndConvert() •  receiveAndConvert(String queueName)   If no message is on the queue null is returned   If no queueName is provided the queue name or queue set at the template will be used   The MessageConverter can be leveraged for message reception as well Object someSerializable = rabbitTemplate.receiveAndConvert(); 28
  • 29. The MessageListener   The API defines this interface for asynchronous reception of messages public void onMessage(Message) { // handle the message } 29
  • 30. Spring’s MessageListener Containers   Spring provides lightweight containers to call MessageListeners   SimpleMessageListenerContainer   Advanced scheduling and endpoint management options available 30
  • 31. Defining a plain Message Listener <bean id="messageListenerContainer" class="org.sfw.amqp.rabbit.listener.SimpleMessageListenerContainer"> <property name="connectionFactory" ref="connectionFactory" /> <property name="queueName" value="#{marketDataQueue.name},#{traderJoeQueue.name}"/> <property name="concurrentConsumers" value="5" /> <property name="messageListener" ref="messageListenerAdapter" /> </bean> 31
  • 32. Spring's message-driven objects   Spring also allows you to specify a plain Java object that can serve as a listener <bean id="messageListenerAdapter" class="org.springframework.amqp.rabbit.listener.adapter.MessageListenerAdapter"> <property name="delegate" ref="clientHandler" /> <property name="messageConverter" ref="jsonMessageConverter" /> </bean>   Parameter is automatically converted using a MessageConverter   Return value sent to response-destination or the reply to   Method with matching parameters is automatically called 32
  • 33. Demo: Hello World   Producer send message using the RabbitTemplate   Routing key : helloWorldQueue name "hello.world.queue"   Goes to Default Exchange   …and therefore to the helloWorldQueue (routing by name)   Consumer receives message using the default receive queue (helloWorldQueue) Routing key: hello.world.queue P X C Default helloWorldQueue Exchange "hello.world.queue" 33
  • 34. Demo: Stock Exchange   Server sends stock prices   Client receives stock prices   Client can issue orders   Orders are processed by the server   Client receives confirmation of the trade   Queues are private for one client 34
  • 35. Server sends stock prices Routing key: RabbitMarketDataGateway app.stockes.quote.?.? e.g. called periodicaly app.stockes.quote.nasdaq.ORCL P X Topic Exchange app.stock.marketdata 35
  • 36. Client receives stock prices   Binding is created to attach the exchange to the queue using the routing key Routing key: app.stock.quotes.nasdaq.* X C Topic marketDataQueue Exchange (private per consumer) app.stock.marketdata ClientHandler in SimpleMessageListenerContainer with jsonMessageConverter and a MessageListenerAdapter 36
  • 37. Client can issue orders   traderJoeQueue is set as reply to for the message Routing key: app.stock.request P X Default Exchange 37
  • 38. Server processes order   Reply (i.e. confirmation) is sent to the reply to (trader Joe queue) X C Default stockRequestQueue ServerHandler in Exchange "app.stock.request" SimpleMessageListenerContainer with jsonMessageConverter and a MessageListenerAdapter 38
  • 39. Client receives confirmation of the trade   Binding is created to attach the exchange to the queue using the routing key X C Default Exchange traderJoeQueue ClientHandler in SimpleMessageListenerContainer with jsonMessageConverter and a MessageListenerAdapter 39
  • 40. Conclusion   Ubiquitous Messaging   AMQP: Protocol standard   Better scalability   http://springsource.org/spring-amqp   Also a .NET version available 40