Real time Cloud Database with PubNub

We have strengthened the integration between our Cloud Database functionality and the real time messaging system built by our friends at PubNub.

Now, can automatically push a message to a PubNub channel whenever a new document is inserted, or an existing document is updated in a collection in your Cloud Database.

Enable this functionality by saving your PubNub Publish and Subscription keys in the Other APIs page of the application settings in the management console.

Once you have saved these details you will be able to enable PubNub notifications on each collection in your Cloud Database individually. Messages for each collection can be pushed to a different channel. The field is provided in the collection settings of the management console.

cloud database collection pubnub settings

The notification message pushed to the channel will have the following structure.

To push more complex messages or perform a custom action you can always use a Cloud Function as a trigger on your Cloud Database.

The same data sent automatically to the PubNub channel is also available in the $params variable to Cloud Functions executed as trigger. We published a blog post explaining how to use the PubNub PHP library from your Cloud Functions a while ago. Putting the two together allows for notifications to different channels or custom business logic before pushing the message out.

  • Stephen Blum

    This is very excellent and I want to start playing with this now. I’m signing up with CloudBase!

    • cloudbase_io

      Thanks Stephen, let us know if we can help you with anything. You can get in touch any time at support[at]

      • Stephen Blum

        I sent an email with some basic questions. Looking forward to getting this up and running!

  • Stephen Blum

    You can easily wrap this up in a Backbone.js or Angular.js SDK-addon and make a create MVC abstraction.

  • yakirperlin

    Great news and very nice feature.

  • Stephen Blum

    It works! Very easy.

    include ‘CBHelper.php’;

    // INIT the CBHelper object with an application details
    $appCode = “pubnub-test”;
    $appSecret = “UNIQE_CODE”;
    $password = md5(“PASSWORD”);

    $helper = new CBHelper($appCode, $appSecret, $password);

    // Write
    $helper->insert_document( array(array(
    ‘first_name’ => ‘Rongchao’
    )), ‘test-collection’ );