Message Persistence API for PubNub Mbed SDK
Message Persistence provides real-time access to the history of all messages published to PubNub. Each published message is timestamped to the nearest 10 nanoseconds and is stored across multiple availability zones in several geographical locations. Stored messages can be encrypted with AES-256 message encryption, ensuring that they are not readable while stored on PubNub's network. For more information, refer to Message Persistence.
Messages can be stored for a configurable duration or forever, as controlled by the retention policy that is configured on your account. The following options are available: 1 day, 7 days, 30 days, 3 months, 6 months, 1 year, or Unlimited.
You can retrieve the following:
- Messages
- Message actions
- File Sharing (using File Sharing API)
History
This function fetches historical messages of a channel. Message Persistence provides real-time access to an unlimited history for all messages published to PubNub. Stored messages are replicated across multiple availability zones in several geographical data center locations. Stored messages can be encrypted with AES-256 message encryption ensuring that they are not readable while stored on PubNub's network. It is possible to control how messages are returned and in what order, for example you can:
- Limit the number of messages to a specific quantity using the
4th argument
parameter.
Method(s)
To run History
you can use the following method(s) in the mbed SDK:
enum pubnub_res pubnub_history (pubnub_t *p, const char *channel, const char *channel_group, unsigned count)
Parameter | Type | Required | Description |
---|---|---|---|
p | pubnub_t* | Yes | Pointer to PubNub client context. Can't be NULL. |
channel | const char* | Yes | The string with the channel name to fetch the history |
count | unsigned | Yes | Maximum number of messages to get. If there are less than this available on the channel , you'll get less, but you can't get more. |
include_token | bool | Yes | If true , include the timetoken for every message . default: false |
Basic Usage
Retrieve the last 100 messages on a channel:
// Sync
enum pubnub_res res;
pubnub_history(
pn,
"history_channel",
10,
false
);
res = pubnub_await(pn);
if (PNR_OK == res) {
puts("Got history! Messages:");
for (;;) {
const char *msg = pubnub_get(pn);
show all 23 linesRest Response from Server
An array is returned on success.
The pubnub_history()
function returns a list of up to 100 messages, the timetoken of the first (oldest) message and the timetoken of the last (newest) message in the resulting set of messages. The output below demonstrates the format for a pubnub_history()
response:
[
["message1", "message2", "message3",... ],
"Start Time Token",
"End Time Token"
]