Newer Version Available
Message Durability
Event Numbering
Each broadcasted event is assigned a numeric ID. IDs are incremented and not guaranteed to be contiguous for consecutive events. Each ID is guaranteed to be higher than the ID of the previous event. For example, the event following the event with ID 999 can have an ID of 1,025. The ID is unique for the org and the channel. The IDs of deleted events aren’t reused.
The ID is added in the replayId field of the notification message. For example, this JSON message shows the replayId field in the event object for a generic event.
1{
2 "clientId":"a1ps4wpe52qytvcvbsko09tapc",
3 "data":{
4 "event":{
5 "createdDate":"2016-03-29T19:05:28.334Z",
6 "replayId":55
7 },
8 "payload":"This is a message."
9 },
10 "channel":"/u/TestStreaming"
11}This JSON message shows the replayId field in the event object for a PushTopic event.
1{
2 "clientId":"2t80j2hcog29sdh9ihjd9643a",
3 "data":{
4 "event":{
5 "createdDate":"2016-03-29T16:40:08.208Z",
6 "replayId":13,
7 "type":"created"
8 },
9 "sobject":{
10 "Website":null,
11 "Id":"001D000000KnaXjIAJ",
12 "Name":"TicTacToe"
13 }
14 },
15 "channel":"/topic/TestAccountStreaming"
16}Replaying Events
A subscriber can choose which events to receive, such as all events within the retention window or starting after a particular event. The default is to receive only the new events sent after subscribing. Events outside the 24-hour retention period are discarded.
This high-level diagram shows how event consumers can read a stream of events by using various replay options.
To replay events, use the Streaming API endpoint.
1https://Salesforce_Instance/cometd/38.0/1// Register streaming extension
2var replayExtension = new cometdReplayExtension();
3replayExtension.setChannel(<Streaming Channel to Subscribe to>);
4replayExtension.setReplay(<Event Replay Option>);
5cometd.registerExtension('myReplayExtensionName', replayExtension);After calling the setReplay() function on the extension, the events that the subscriber receives depend on the replay value parameter passed to setReplay().
Code Samples
- Visualforce Sample
- For a sample and code walkthrough that uses Visualforce and a CometD extension in JavaScript, see: Example: Replay PushTopic and Generic Streaming Events Using a Visualforce Page