What is the basic usage pattern and common use cases of publishing and subscribing to messages?

The general usage pattern for PubNub is straightforward:

  1. Sign-up with PubNub to get your Publish and Subscribe keys
  2. Each client calls the Subscribe function with a channel name (multiple times if multiple channels) for clients to listen on, specifying a callback function to be triggered upon receiving a message
  3. Publish a message onto the channel, resulting in all subscribers to that channel receiving the message (typically under 100ms) and executing a callback function for each message received

There are many use cases for PubNub including:

  • A single publisher (typically a server)
  • Clients as both publishers and subscribers
  • Publishing to many channels (even millions)
  • Publishing to a specific user (e.g. live feed) using an "individual" channel
  • Publishing to a group of users (e.g. chat room) using a "global" channel
  • and many more...