Message Persistence API for Mbed SDK
Message Persistence gives you real-time access to the history of messages published to PubNub. Each message is timestamped to the nearest 10 nanoseconds and stored across multiple availability zones in several geographic locations. You can encrypt stored messages with AES-256 so they are not readable on PubNub’s network. For details, see Message Persistence.
You control how long messages are stored through your account’s retention policy. Options include: 1 day, 7 days, 30 days, 3 months, 6 months, 1 year, or Unlimited.
You can retrieve the following:
- Messages
- Message reactions
- Files (using the File Sharing API)
History
This function fetches historical messages of a channel. Message Persistence provides real-time access to persisted messages. Stored messages are replicated across multiple availability zones in several geographic data center locations. Stored messages can be encrypted with AES-256 so they are not readable while stored on PubNub's network.
- Limit the number of messages to a specific quantity using the
4th argument
parameter.
Method(s)
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 | Description |
---|---|
p *Type: pubnub_t* | Pointer to PubNub client context. Can't be NULL. |
channel *Type: const char* | The string with the channel name to fetch the history |
count *Type: unsigned | 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 *Type: bool | If true , include the timetoken for every message . default: false |
Sample code
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 35 lines