PubNub FunctionsSending Data to a Block

PubNub Functions follows the exact same publish/subscribe communication paradigm as the rest of the PubNub Data Stream Network (DSN).

A Function subscribes to one or more channels, and executes the logic provided on each associated message.

Publishing and subscribing clients have no awareness of which (if any) PubNub Functions are configured against the messages they send and receive.

When a client publishes a message to PubNub, one of two functions may be used:

When a message is sent using the publish() function, regardless if a block is bound to the channel or not, on its way to awaiting subscribers, the message will be replicated globally to all PoPs (Point of Presence). In addition, if enabled for the keyset, all messages sent through the DSN via the publish() method may be archived via the Storage and Playback feature.

Publish() is implemented and available in all PubNub SDKs.

Unlike publish(), a message sent using fire() will not be replicated to other PoPs; it will remain at the originating PoP, and is not eligible for archiving via the Storage and Playback feature.

The fire() function should only be used when you wish to trigger a Function on a block, not for everyday publishing purposes.

Fire() is currently being implemented in all our PubNub SDKs. To learn about what SDKs are currently supporting the function, please check the documentation and select the appropriate SDK.

Sometimes it will be useful to chain data from one Function to another in sequence. For example, you may have three Functions in your block.

  • Function #1 spell checks the message.
  • Function #2 tokenizes the message into parts of speech.
  • Function #3 publishes messages, by parts of speech, to unique channels.

In order to achieve the expected results, we'd need to chain Function #1 to Function #2, and Function #2 to Function #3 – this is called Event Handler chaining.

You can chain Functions contained within the same, or different Modules.

To chain Functions, configure the destination Function channel input to that of the source Function's fire() function call.

PubNub Functions provides a rich set of tools, and this documentation does not cover all of the potential situations you may encounter. If you need help with a situation not covered by the documentation, please contact PubNub Support.