Message Queues - andrewkyllo-401-advanced-javascript/seattle-javascript-401d34 GitHub Wiki

Message Queues

  • A queue server runs independently and is tasked with routing events and messaging between clients.
  • Any connected client can "publish" a message into the server
  • Any connected client can "subscribe" to receive messages by type
  • The Queue server has the ability to see which clients are connected, to which queues they are attached and further, to which events they are subscribed
  • The queue server is tasked with receiving any published message and then distributing it out to all connected and subscribed clients.

What is a message?

  • A package of information, categorized by queue and event
  • queue - which general bucket does this message belong
  • event - What event has happened
  • payload - data associated with the event

Real Time vs Queued Messaging

  • Real time messages are broadcasted to users whether they are logged in or not.
  • A true queue will keep track of the deliver status of every event/message.
  • Any broad cast that is not received will remain in the queue until it cane be delivered.

Use Case

  • An API server responds to a POST request
    • User's access rights are confirmed

    • The data is analyzed and normalized

    • The data is sent to the database for saving

    • The database publishes a message into the queue

      • Queue: DB
      • Event: CREATE
      • Payload: JSON Object containing the created record
    • The API server sends information back to its client as normal