What is the right way to log every published message and save it to my server db.
There are two options which I can think of:
- Use PubNub function After Publish event and forward the message to a dedicated logger channel. the server will subscribe to the channel and save the arrived messages to db. Here rise another question: when I forward the message to another channel in the PubNub function will it also trigger the PubNub function?
- use PubNub XHR request/response function and call to a rest API on my server with the published message and save it to db
What is the best practice concerning performance and cost?
Save PubNub Messages to your Private Database
We wrote an article that talks about the right way to log JSON Messages to a Private Database.
PubNub does not index your messages using FTS Indexing; at time of writing. You may want Full Text Search Indexing using your database or use an API provider like https://www.algolia.com/ for full text searching.
Data is valuable. AI and ML allows you to create insight from your data using Tensorflow. You may want to run data analysis for the message content. Using EMR / Hadoop or other big data analysis software.
You will use PubNub Functions to save your message asynchronously into your database system easily by following these steps.
To get started is easy. Assuming you already have a stream of messages being published to a PubNub data channel. Follow these easy steps. Successfully you will create a realtime function that is triggered every Publish event.
*
.*
channel.Asynchronous HTTPS Save Message Function