Message Persistence API for PubNub Mbed SDK
The PubNub Message Persistence Service provides real-time access to history for 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 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.
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, 3, 5, 7, 15, or 30 days, and Forever.
History
Description
This function fetches historical messages of a channel. PubNub Message Persistence Service 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 thechannel
name to fetch thehistory
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 everymessage
. 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);
if (NULL == msg) {
break;
}
puts(msg);
}
} else {
printf("Getting history failed with code: %d\n", res);
}
Rest 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"
]