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:
- Go to the Keyset Configuration via the admin portal.
- Scroll down to the PubNub feature section and turn on the
Voila! You can now create
PubNub Functions for this Keyset.
Now that your Keyset is enabled for
PubNub Functions, let's create a Module.
- Go to the
PubNub Functionspage by clicking the
PubNub Functionsicon in side bar.
- 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:
- Entering a name.
- Choosing a Function Type.
- 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
For example, if you have several channels named
foo.barN, your Function can subscribe to all these channels by entering in the channel field:
For more information on wildcard subscribing see http://www.pubnub.com/knowledge-base/categories/wildcard-subscribe
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!