Newer Version Available
Subscribe to Platform Event Notifications with CometD
Salesforce sends platform events to CometD clients sequentially in the order they’re received. The order of event notifications is based on the replay ID of events.
The process of subscribing to platform event notifications through CometD is similar to subscribing to PushTopics or generic events. The only difference is the channel name. The platform event channel name is case-sensitive and is in the following format.
1/event/Event_Name__eUse this CometD endpoint with the API version appended to it.
1/cometd/46.0Example
If you have a platform event named Low Ink, provide this channel name when subscribing.
1/event/Low_Ink__eThe message of a delivered platform event looks similar to the following example for Low Ink events.
1{
2 "data": {
3 "schema": "dffQ2QLzDNHqwB8_sHMxdA",
4 "payload": {
5 "CreatedDate": "2017-04-09T18:31:40.517Z",
6 "CreatedById": "005D0000001cSZs",
7 "Printer_Model__c": "XZO-5",
8 "Serial_Number__c": "12345",
9 "Ink_Percentage__c": 0.2
10 },
11 "event": {
12 "replayId": 2
13 }
14 },
15 "channel": "/event/Low_Ink__e"
16}The schema field in the event message contains the ID of the platform event schema. The schema is versioned—when the schema changes, the schema ID changes as well.
To determine if the schema of an event has changed, retrieve the schema through REST API. Use the schema ID by performing a GET request to this REST API resource: /vXX.X/event/eventSchema/Schema_ID. Alternatively, you can retrieve the event schema by supplying the event name to this endpoint: /vXX.X/sobjects/Event_Name/eventSchema. For more information, see:
- Platform Event Schema by Schema ID in the REST API Developer Guide
- Platform Event Schema by Event Name in the REST API Developer Guide
You can use EMP Connector to receive delivered events. The connector subscribes to any type of streaming event and accepts the event channel name as an argument. See Example: Subscribe to and Replay Events Using a Java Client.
Add custom logic to your client to perform some operations after a platform event notification is received. For example, the client can create a request to order a new cartridge for this printer model.