Feedback

PubNub FunctionsQuick Start Summary

In this Quick Start, we will lead you through a step-by-step guide of how to create and deploy a Module in the PubNub Data Stream Network.

Just like other features of the Data Stream Network, PubNub Functions must be enabled on a per Keyset basis.

To enable a Keyset:

  1. Go to the Keyset Configuration via the admin portal.
  2. Scroll down to the PubNub feature section and turn on the PubNub Functions toggle.

Voila! You can now create PubNub Functions for this Keyset.

Now that your Keyset is enabled for PubNub Functions, let's create a Module.

  1. Go to the PubNub Functions page by clicking the PubNub Functions icon in side bar.
  2. Create a Module by entering a name and a description in the square tile.
 
 

The name of a Module is a unique identifier scoped by the Keyset it's under. 

A Module is used as a container to group related Functions together. Since we just created this Module, it contains no Functions, so we'll create it now.

To create a Function, you can either hit the CREATE button on the left side or the GUIDE ME button and see some examples.

In the pop up window, configure your Function by:

  1. Entering a name.
  2. Choosing a Function Type.
  3. Providing either channel names or a URI path.

PubNub Functions can be 1 of 4 types and the type of a Function determines when and how a Function will be triggered.

  • Before Publish or Fire
  • After Publish or Fire
  • After Presence
  • On Request

For more information on Function Types, please see Function Types.

Function Types involving Publish or Presence events are triggered by messages sent to one or several channels, and must always have at least one channel defined for it.

For a Function to execute against messages sent to a single channel, enter the channel name in the channel field.

If you adopt a naming convention with 2 levels of depth when specifying your channels, you can subscribe to channels by using wildcards.

For example, if you have several channels named foo.bar1, foo.bar2, foo.bar3, …, foo.barN, your Function can subscribe to all these channels by entering in the channel field: foo.*

For more information on wildcard subscribing see http://www.pubnub.com/knowledge-base/categories/wildcard-subscribe

And now the fun part starts. Coding! At this step, you can write your code logic in standard JavaScript. This code will be executed against every message received against the predefined channels.

Now that you are ready to start executing your Function, hit the Start Module button at the top right corner and your Module will be deployed around globe in under a second!