CmbedmbedWindows CFreeRTOSPosix Cmbed Storage & Playback API Reference for Realtime Apps

PubNub's Storage & Playback feature enables developers to store messages as they are published, and retrieve them at a later time. Our storage layer is a time-series based database. Each published message is timestamped to the nearest 10 nanoseconds.

Learn more about our Storage & Playback feature here.

This function fetches historical messages of a channel.
PubNub Storage/Playback 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.
To run History you can use the following method(s) in the mbed SDK
  1. ParameterTypeRequiredDescription
    ppubnub_t*YesPointer to Pubnub client context. Can't be NULL.
    channelconst char*YesThe string with the channel name to fetch the history
    countunsignedYesMaximum 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_tokenboolYesIf true, include the time token for every message.

    default: false
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);
}
An array is returned on success. The pubnub_history() function returns a list of up to 100 messages, the time token of the first (oldest) message and the time token 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"
]