I have a lighting component which subscribes to a event channel Notification__e
on load. I have used replayId =-2
to read all the old events.
subscribe: function (component, event, helper) {
const empApi = component.find('empApi');
const channel = component.get('v.channel');
const replayId = -2;
const callback = function (message) {
console.log('Event Received : ' + JSON.stringify(message));
};
// Subscribe to the channel and save the returned subscription object.
empApi.subscribe(
channel,
replayId,
$A.getCallback(callback)
).then(
$A.getCallback(function (newSubscription) {
console.log(newSubscription);
component.set('v.subscription', newSubscription);
})
);
}
But, on reload, component either gives old events information or it errors out. I could not figure out why it sometimes retrieves old events and sometimes throws out error message. Also, it is giving stored events information which were created on 6th sept but as per doc salesforce stores events for 24 hours.
Old Events
Event Received : {"data":{"schema":"2-WbrEYaxZwZWJVS5I0l9Q",
"payload":{"CreatedById":"0052v00000VcpWtAAJ","Message__c":"Watch out, bear
spotted!","CreatedDate":"2019-09-06T09:38:56Z"},"event":
{"replayId":1025104}},"channel":"/event/Notification__e"}
Event Received : {"data":{"schema":"2-WbrEYaxZwZWJVS5I0l9Q","payload":
{"CreatedById":"0052v00000VcpWtAAJ","Message__c":"Watch out, bear
spotted!","CreatedDate":"2019-09-06T09:39:04Z"},"event":
{"replayId":1025105}},"channel":"/event/Notification__e"}
Event Received : {"data":{"schema":"2-WbrEYaxZwZWJVS5I0l9Q","payload":
{"CreatedById":"0052v00000VcpWtAAJ","Message__c":"Watch out, bear
spotted!","CreatedDate":"2019-09-10T14:10:57Z"},"event":
{"replayId":1025953}},"channel":"/event/Notification__e"}
Error Messages
{"clientId":"5qi16wx0fqh37geo1sytv4xvwp0qk","advice":{"interval":0,"reconnect":"none"},"channel":"/meta/connect","id":"3","error":"403::Unknown client","successful":false}
{"clientId":"5qjfzyexvvngf1lly1u9ozgp6y5","advice":{"interval":0,"reconnect":"none"},"channel":"/meta/connect","id":"8","error":"403::Unknown client","successful":false}
{"id":"2","successful":false,"channel":"/meta/subscribe","failure":{"reason":"Request 2 of transport long-polling exceeded 10000 ms max network delay","httpCode":0,"connectionType":"unknown","transport":{},"message":{"id":"2","channel":"/meta/subscribe","subscription":"/event/Notification__e","clientId":"5qi16wx0fqh37geo1sytv4xvwp0qk","ext":{"replay":{"/event/Notification__e":-2}}}},"subscription":"/event/Notification__e"}
{"id":"6","successful":false,"channel":"/meta/subscribe","failure":{"reason":"Request 9 of transport long-polling exceeded 10000 ms max network delay","httpCode":0,"connectionType":"unknown","transport":{},"message":{"id":"6","channel":"/meta/subscribe","subscription":"/s/notifications/notification","clientId":"5qjfzyexvvngf1lly1u9ozgp6y5","ext":{"replay":{"/s/notifications/notification":-1}}}},"subscription":"/s/notifications/notification"}