SelectMono-for-Linux Storage & Playback API Reference for Realtime Apps

The PubNub Storage and Playback Service provides realtime 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 day, 7 days, 1 month, and Forever.


Requires Storage & Playback add-on XRequires that the Storage & Playback add-on is enabled for your key. See this page on enabling add-on features on your keys:

http://www.pubnub.com/knowledge-base/discussion/644/how-do-i-enable-add-on-features-for-my-keys.
This function fetches historical messages of a channel.
It is possible to control how messages are returned and in what order, for example you can:
  • Search for messages starting on the newest end of the timeline (default behavior - reverse = false)
  • Search for messages from the oldest end of the timeline by setting reverse to true.
  • Page through results by providing a start OR end time token.
  • Retrieve a slice of the time line by providing both a start AND end time token.
  • Limit the number of messages to a specific quantity using the count parameter.
 
Start & End parameter usage clarity:
If only the start parameter is specified (without end), you will receive messages that are older than and up to that start timetoken value.
If only the end parameter is specified (without start) you will receive messages that match that end timetoken value and newer.
Specifying values for both start and end parameters will return messages between those timetoken values (inclusive on the end value).
Keep in mind that you will still receive a maximum of 100 messages even if there are more messages that meet the timetoken values. Iterative calls to history adjusting the start timetoken is necessary to page through the full set of results if more than 100 messages meet the timetoken values.
To run History you can use the following method(s) in the Mono for Linux SDK
  1. ParameterTypeRequiredDescription
    channelStringYesSpecifies channel to return history messages from.
    startlongYesTime token delimiting the start of time slice (exclusive) to pull messages from.
    endlongYesTime token delimiting the end of time slice (inclusive) to pull messages from.
    countintYesSpecifies the number of historical messages to return.

    default/maximum is 100.
    reverseboolYesSetting to true will traverse the time line in reverse starting with the oldest message first.

    Default is false.
    userCallbackCallback Method of Type objectYesThis callback is called on receiving a message from the channel.
    errorCallbackCallback Method of Type PubnubClientError YesThis callback is called on an error event.
  2. ParameterTypeRequiredDescription
    channelstringYesSpecifies channel to return history messages from.
    startlongYesTime token delimiting the start of time slice (exclusive) to pull messages from.
    endlongYesTime token delimiting the end of time slice (inclusive) to pull messages from.
    countintYesSpecifies the number of historical messages to return.

    The Default is 100.
    reverseboolYesSetting to true will traverse the time line in reverse starting with the oldest message first.

    Default is false.
    userCallbackCallback Method of Type TYesThis callback is called on receiving a message from the channel.
    errorCallbackCallback Method of Type PubnubClientError YesThis callback is called on an error event.
  3. ParameterTypeRequiredDescription
    channelStringYesSpecifies channel to return history messages from.
    startlongYesTime token delimiting the start of time slice (exclusive) to pull messages from.
    userCallbackCallback Method of Type objectYesThis callback is called on receiving a message from the channel.
    errorCallbackCallback Method of Type PubnubClientError YesThis callback is called on an error event.
    reverseboolYesSetting to true will traverse the time line in reverse starting with the oldest message first.

    Default is false.

  4. ParameterTypeRequiredDescription
    channelStringYesSpecifies channel to return history messages from.
    startlongYesTime token delimiting the start of time slice (exclusive) to pull messages from.
    userCallbackCallback Method of Type TYesThis callback is called on receiving a message from the channel.
    errorCallbackCallback Method of Type PubnubClientError YesThis callback is called on an error event.
    reverseboolYesSetting to true will traverse the time line in reverse starting with the oldest message first.

    Default is false.

  5. ParameterTypeRequiredDescription
    channelStringYesSpecifies channel to return history messages from.
    countintYesSpecifies the number of historical messages to return.

    The Default is 100.

    userCallbackCallback Method of Type objectYesThis callback is called on receiving a message from the channel.
    errorCallbackCallback Method of Type PubnubClientError YesThis callback is called on an error event.
  6. ParameterTypeRequiredDescription
    channelStringYesSpecifies channel to return history messages from.
    countintYesSpecifies the number of historical messages to return.

    The Default is 100.

    userCallbackCallback Method of Type TYesThis callback is called on receiving a message from the channel.
    errorCallbackCallback Method of Type PubnubClientError YesThis callback is called on an error event.
  7. ParameterTypeRequiredDescription
    channelStringYesSpecifies channel to return history messages from.
    countintYesSpecifies the number of historical messages to return.

    The Default is 100.

    includeTokenboolYesWhether event dates (time tokens) should be included in response or not.
    userCallbackCallback Method of Type objectYesThis callback is called on receiving a message from the channel.
    errorCallbackCallback Method of Type PubnubClientError YesThis callback is called on an error event.
  8. ParameterTypeRequiredDescription
    channelStringYesSpecifies channel to return history messages from.
    countintYesSpecifies the number of historical messages to return.

    The Default is 100.

    includeTokenboolYesWhether event dates (time tokens) should be included in response or not.
    userCallbackCallback Method of Type TYesThis callback is called on receiving a message from the channel.
    errorCallbackCallback Method of Type PubnubClientError YesThis callback is called on an error event.
Retrieve the last 100 messages on a channel:
// retrieve last 100 messages

pubnub.DetailedHistory<string>(
    "history_channel",
    100,
    DisplayReturnMessage,
    DisplayErrorMessage);
void DisplayReturnMessage(string result)
{
    Console.WriteLine(result);
    if (!string.IsNullOrEmpty(result) && !string.IsNullOrEmpty(result.Trim()))
            {
                List<object> deserializedMessage = pubnub.JsonPluggableLibrary.DeserializeToListOfObject(result);
                if (deserializedMessage != null && deserializedMessage.Count > 0)
                {
                    object[] message = pubnub.JsonPluggableLibrary.ConvertToObjectArray(deserializedMessage[0]);
                    if (message != null)
                    {
                        if (message.Length >= 0)
                        {
                            foreach (object item in message)
                            {
                                Console.WriteLine(item);
    //IF CUSTOM OBJECT IS EXCEPTED, YOU CAN CAST THIS OBJECT TO YOUR CUSTOM CLASS TYPE
                            }
                        }
                    }
                }
            }
}
void DisplayErrorMessage(PubnubClientError pubnubError)
{
    Console.WriteLine(pubnubError.StatusCode);
}
The Mono for Linux SDK returns false on fail. An array is returned on success. The 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 history() response:

[
	["message1", "message2", "message3",... ],
	"Start Time Token",
	"End Time Token"
]
  1. pubnub.DetailedHistory<string>(
        "my_channel",
        3,
        DisplayReturnMessage,
        DisplayErrorMessage);
    
    void DisplayReturnMessage(string result)
    {
        Console.WriteLine(result);
        if (!string.IsNullOrEmpty(result) && !string.IsNullOrEmpty(result.Trim()))
                {
                    List<object> deserializedMessage = pubnub.JsonPluggableLibrary.DeserializeToListOfObject(result);
                    if (deserializedMessage != null && deserializedMessage.Count > 0)
                    {
                        object[] message = pubnub.JsonPluggableLibrary.ConvertToObjectArray(deserializedMessage[0]);
                        if (message != null)
                        {
                            if (message.Length >= 0)
                            {
                                foreach (object item in message)
                                {
                                    Console.WriteLine(item);
        //IF CUSTOM OBJECT IS EXCEPTED, YOU CAN CAST THIS OBJECT TO YOUR CUSTOM CLASS TYPE
                                }
                            }
                        }
                    }
                }
    }
    void DisplayErrorMessage(PubnubClientError pubnubError)
    {
        Console.WriteLine(pubnubError.StatusCode);
    }
    
     [
    	["Pub1","Pub2","Pub3"],
    	13406746729185766,
    	13406746780720711
    ]
    
  2. pubnub.DetailedHistory<string>(
        "my_channel",
        3557486057035336,
        DisplayReturnMessage,
        DisplayErrorMessage,
        true
    );
    
    void DisplayReturnMessage(string result)
    {
        Console.WriteLine(result);
        if (!string.IsNullOrEmpty(result) && !string.IsNullOrEmpty(result.Trim()))
                {
                    List<object> deserializedMessage = pubnub.JsonPluggableLibrary.DeserializeToListOfObject(result);
                    if (deserializedMessage != null && deserializedMessage.Count > 0)
                    {
                        object[] message = pubnub.JsonPluggableLibrary.ConvertToObjectArray(deserializedMessage[0]);
                        if (message != null)
                        {
                            if (message.Length >= 0)
                            {
                                foreach (object item in message)
                                {
                                    Console.WriteLine(item);
        //IF CUSTOM OBJECT IS EXCEPTED, YOU CAN CAST THIS OBJECT TO YOUR CUSTOM CLASS TYPE
                                }
                            }
                        }
                    }
                }
    }
    void DisplayErrorMessage(PubnubClientError pubnubError)
    {
        Console.WriteLine(pubnubError.StatusCode);
    }
    
     [
    	["Pub3","Pub4","Pub5"],
    	13406746780720711,
    	13406746845892666
    ]
    
  3. pubnub.DetailedHistory<string>(
        "my_channel",
        -1,
        13557487057035336,
        100,
        false,
        DisplayReturnMessage,
        DisplayErrorMessage);
    
    void DisplayReturnMessage(string result)
    {
        Console.WriteLine(result);
        if (!string.IsNullOrEmpty(result) && !string.IsNullOrEmpty(result.Trim()))
                {
                    List<object> deserializedMessage = pubnub.JsonPluggableLibrary.DeserializeToListOfObject(result);
                    if (deserializedMessage != null && deserializedMessage.Count > 0)
                    {
                        object[] message = pubnub.JsonPluggableLibrary.ConvertToObjectArray(deserializedMessage[0]);
                        if (message != null)
                        {
                            if (message.Length >= 0)
                            {
                                foreach (object item in message)
                                {
                                    Console.WriteLine(item);
        //IF CUSTOM OBJECT IS EXCEPTED, YOU CAN CAST THIS OBJECT TO YOUR CUSTOM CLASS TYPE
                                }
                            }
                        }
                    }
                }
    }
    void DisplayErrorMessage(PubnubClientError pubnubError)
    {
        Console.WriteLine(pubnubError.StatusCode);
    }
    
    [
    	["Pub3","Pub4","Pub5"],
    	13406746780720711,
    	13406746845892666
    ]
    
  4.  
    Usage!
    You can call the method by passing 0 or a valid time token as the argument.
    pubnub.DetailedHistory<string>(
    	channel:"my_channel", 
    	start:0, 
    	userCallback:DisplayReturnMessage, 
    	errorCallback:DisplayErrorMessage, 
    	reverse:true
    );
    
    void DisplayReturnMessage(string result)
    {
    	if (!string.IsNullOrEmpty(result) && !string.IsNullOrEmpty(result.Trim()))
                {
                    List<object>deserializedContainer = pubnub.JsonPluggableLibrary.DeserializeToListOfObject(result) as List<object>;
                    if (deserializedContainer != null && deserializedContainer.Count > 0)
                    {
                        object deserializedMessage = deserializedContainer[0] as object;
    
    		    //Messages available in list
                        List<object> messageList = pubnub.JsonPluggableLibrary.DeserializeToListOfObject(deserializedMessage.ToString());
    
    		    if (messageList != null && messageList.Count > 0)
    		    {
                        	long startTimetoken = Int64.Parse(deserializedContainer[1].ToString());
                        	long endTimetoken = Int64.Parse(deserializedContainer[2].ToString());
    
                        	pubnub.DetailedHistory<string>(
    				channel:"my_channel", 
    				start: endTimetoken, 
    				userCallback:DisplayReturnMessage, 
    				errorCallback:DisplayErrorMessage, 
    				reverse: true);
    		    }
                    }
                }
    }
  5. pubnub.DetailedHistory<string>(
        "my_channel",
        3,
        true,
        DisplayReturnMessage,
        DisplayErrorMessage);
    
    void DisplayReturnMessage(string result)
    {
        Console.WriteLine(result);
        if (!string.IsNullOrEmpty(result) && !string.IsNullOrEmpty(result.Trim()))
                {
                    List<object> deserializedMessage = pubnub.JsonPluggableLibrary.DeserializeToListOfObject(result);
                    if (deserializedMessage != null && deserializedMessage.Count > 0)
                    {
                        object[] message = pubnub.JsonPluggableLibrary.ConvertToObjectArray(deserializedMessage[0]);
                        if (message != null)
                        {
                            if (message.Length >= 0)
                            {
                                foreach (object item in message)
                                {
                                    Console.WriteLine(item);
                                    //IF CUSTOM OBJECT IS EXCEPTED, YOU CAN CAST THIS OBJECT TO YOUR CUSTOM CLASS TYPE
                                }
                            }
                        }
                    }
                }
    }
    
    void DisplayErrorMessage(PubnubClientError pubnubError)
    {
        Console.WriteLine(pubnubError.StatusCode);
    }