How do I send & receive messages using PubNub?
Modified on: Wed, Sep 14, 2016 at 10:01 AM
What is the basic usage pattern and common use cases of publishing and subscribing to messages?
The general usage pattern for PubNub is straightforward:
- Sign-up with PubNub to get your Publish and Subscribe keys
- 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
- 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...
Did you find it helpful?
Can you please tell us how we can improve this article?