Newer Version Available
Subscribe to Platform Event Notifications with CometD
Salesforce sends platform events to CometD clients, including EMP Connector, 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. Here is the format of the platform event topic (channel) name.
1/event/<EventName>__eFor example, if you have a platform event named Low Ink, provide this channel name when subscribing.
1/event/Low_Ink__eEnsure that your API client uses version 37.0 or later of the CometD endpoint.
1/cometd/39.0The message of a delivered platform event looks similar to the following example for Low Ink events.
1{
2 "clientId": "123qiewfarn041rn29pf37awjr",
3 "data": {
4 "payload": {
5 "CreatedById": "005D0000001WHiZ",
6 "ReplayId": null,
7 "CreatedDate": "2016-12-14T20:08:19Z",
8 "Printer_Model__c": "MN-123",
9 "Id": null,
10 "Serial_Number__c": "10013",
11 "Ink_Percentage__c": 0.15
12 },
13 "event": {
14 "schema": "_c1_d37defc8cfbf44229cbd4fe82167be19",
15 "replayId": 7
16 }
17 },
18 "channel": "/event/Low_Ink__e"
19}Use EMP Connector to receive delivered events. The connector subscribes to streaming events and platform events in the same way—only the topic name is different. See Example: Subscribe to and Replay Events Using a Java Client in the Streaming API Developer Guide. For the topic argument, provide /event/Low_Ink__e. The topic name value is based on the example event Low Ink.
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.