Message Queues

My reading notes for Code Fellows


Message Queues

Socket.io Chat Example

Explain to a non-technical recruiter what the Chat Example (above) does.

This chatroom uses a socket servers to allow users to connect in a central chatroom. Rather than making a call to a server anytime they want to refresh the channel, the server conncection is maintained and the server It maintains an open channel, and the server will push updates to anyone who has chosen to connect, so everyone gets updates in real time.

What proof of life are we getting on the backend from the above app?

By using node, one can use their console to view the port that is being used, and see when a user connects or disconnects.

Socket.IO gives us the i0.emit() method to send an event to everyone. What flag would you use if you want to send a message to everyone except for a certain emitting socket?

The broadcast flag

Rooms

What is a room and how might a room be useful? A room is a channel that sockets can join or leave. It can be used to broadcast events to a subset of clients. This is useful insofar as people who are interested in the same thigns can gather and communicate. Aside from simply having a good time or organizing around an idea, those like minded people can be marketed to, or one could seek to survery them.

How do you join a room?

socket.join

how do you leave a room?

socket.leave

Namespaces

What is a Namespace and what does it allow you to do? A Namespace is a communication channel that allows you to split the logic of your application over a single shared connection (also called “multiplexing”).

Each namespace potentially has its own what? (hint: 3 things)

  • event handlers
  • rooms
  • middleware

Discuss a possible use case for separate namespaces

Namespaces allow one to segregate and organize their users, and also allow for a way to limit access to the digital space.