Full-text search, data analytics, and audit trails are only three of many reasons you may want to store messages externally. Using PubNub Functions, you can save JSON messages to your database, asynchronously and reliably.
External storage tutorial
Assuming you already have a stream of JSON messages being published to a PubNub channel (such as chat messages or Bitcoin prices), follow these easy steps to create an asynchronous function that's triggered after every message is published.
Your database needs to be accessible via a REST API over HTTPS.
Setting up the Function
Set up a PubNub Function to get your code running on the network. This is where the calls to your database will happen.
To add the PubNub Function to an existing PubNub app, do the following:
Go to the application instance on your PubNub Dashboard.
Create a new module, and then create a new
After Publish or FireFunction. Configure the function to trigger on specific channels, or use
*to run it on all channels.
Use the following sample Function code to (asynchronously) save your JSON messages to your database. (You'll need to modify
postto fit your needs.)
Click Start module to start the function, and test it using the Test Payload field and Publish button on the left.
For a more detailed overview of writing a function, refer to these instructions on the Functions Overview page.