Newer Version Available
Example: Subscribe to and Replay Events Using a Lightning Component
Add the lightning:empApi component to your
custom Lightning component to receive event messages. The lightning:empApi component provides access to methods for subscribing to a
streaming channel and listening to event messages.
All types of streaming events are supported, including:
- Platform events
- Change Data Capture events
- PushTopic events
- Generic events
The lightning:empApi component uses a shared CometD-based Streaming API connection, enabling you to run multiple streaming apps in the browser.
To call the component’s methods, add the lightning:empApi component inside your custom component and assign an aura:id attribute to it.
<lightning:empApi aura:id="empApi"/>Then in the client-side controller, add functions to call the component methods.
For an example of how to use the lightning:empApi component and a complete reference, see the empApi documentation in the Lightning Component Library.