0

When you publish a Platform Event, how long does it stay published for?

I know the subscribers can enter into a state of idle or expire if they are not sure for a certain length of time. Is there anything like that for when you publish the platform event?

UPDATE: https://trailhead.salesforce.com/en/modules/platform_events_basics/units/platform_events_define_publish

It says here that it will store the PE for 24 hours. Is that considered being "published" for 24 hours, or it is storing the data for 24 hours?

5

Platform events are inherently momentary. They don't have a duration as such, but they are stored on the platform for 24 hours to facilitate replay.

Events exist in a channel, a stream, which is watched by one or more subscribers. They aren't independent objects, they don't store state, and they have no permanence - they simply represent some occurrence that is to be observed. If an event exists, it has been published; there's no transition into or out of a published state.

The CometD-based Streaming API, on which Platform Events are built, supports a replay mechanism, whereby subscribers can jump backwards in the stream of messages to a fixed point (the Replay ID of the last message they received) and have messages between that point and the present re-sent to the subscriber. That doesn't imply that the events are in a "published" state for 24 hours (because, as above, events don't have that kind of state), but that they can be accessed by a client through replay during that time window. For example, if a client drops connection for an hour, it can replay all of the events since the last event it received by supplying that event's replay ID. If its connection drops for more than 24 hours, it's out of luck.

Replay is available only through API subscriptions, not Apex.

5
  • interesting. so once the event is published and subscribed to, is it considered done? And removed from the "published" state? And although it is removed from the published state, it still has a replay id that the subscriber can go back to, if needed?
    – Olivia
    Mar 28 '18 at 15:43
  • 1
    Events aren't stateful in the way you're describing. Publishing is a unitary event: event is fired, event is received by subscribers within some small time frame. There's a 24 hour window where clients can replay the event stream, and after that the event doesn't exist anymore.
    – David Reed
    Mar 28 '18 at 15:48
  • 1
    In short: if you're the subscriber and you were not listening when the event was originally published, you have 24 hours from the time of publishing to replay that event before it is unavailable.
    – Mark Pond
    Mar 28 '18 at 16:59
  • I see. great. One more question - if two events are published back to back (or at the same time), will the subscriber take in both events as bulk?
    – Olivia
    Mar 28 '18 at 17:37
  • please avoid extended discussion or follow up questions in the comments.
    – glls
    Mar 28 '18 at 17:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.