Amqp protocol

Concepts

Before reading

The following slides include channel-oriented AMQP API mechanics you should consider first before reading code samples.

For progressive understanding of the concepts and samples, please consider reading

Core concepts

  • You create a connection over TCP with an URI (optionally containing a virtual host)
  • You create a channel (virtual connection) over the connection
  • You use the channel API to
    • create exchanges
    • create/bind queues
    • publish on exchange
    • consume queues

Why channels ?

  • To reuse connections
  • To take advantage of requests into a given channel being serialized
  • To be able to have different consuming behaviors over the same connection 

exchanges and queues

Basically, this enables this separation of concerns:

  • A message publisher
    • ensures the exchange exists
    • publishes a message once on the exchange
    • -> publishing a message on a exchange without bound queues will be dropped instantly
  • A message consumer
    • check if the exchange exists
    • ensures the queue exists and is bound to the exchange with an optional routing key
    • starts a consumer

EXCHANGES AND QUEUES

Publisher

Consumer

Exchange

Queue

routes

publish

consumes

Conventions

URI scheme

Vhost

  • Virtual hosts should be used to implement a strict isolation
    • -> a channel on a vhost is not able to transport requests and messages corresponding to another vhost

Naming

All named things should follow a naming convention

  • exchanges
    • the application owning it
    • the message type it transports (if applicable) 
  • queues
    • the application owning it
    • the message type it stores (if applicable)
  • consumers
    • the application owning it
    • the hostname and pid

Extensions

Extensions

@TODO

Please consider the official protocol extension documentation

Libraries

Amqplib

amqplib github

  • is a channel oriented API
  • supports callback api and promises

amqp-connection-manager

amqp-connection-manager is a wrapper around amqplib

The main features it adds are:

  • automatic reconnection
  • round-robin connections between multiple brokers in a cluster
  • queues messages in memory until reconnection

 

Exercises

Exercises

With a RabbitMQ server on your machine:

  • create an application producing messages
  • create an application consuming these messages

?

Made with Slides.com