How to listen to Salesforce Platform Event from simple CometD application using Java programming?

How to listen to Salesforce Platform Event from simple CometD application using Java programming?

1. Install Java Development Kit 8 or later.

2. Download and Install Apache Maven.
https://maven.apache.org/index.html

3. Download and Install Eclipse.

4. Use the following command to clone the sample CometD connector.
git clone https://github.com/forcedotcom/EMP-Connector

5. Import the project using Eclipse.

6. Create a simple Platform Event.

7. In the /src/main/java/com/salesforce/emp/connector/example folder, Right-click the LoginExample.java file and select Run As | Run Configurations.

8. On the Arguments tab, add values for the following arguments, separated by a space.
Example:

username password /event/API_Name_Of_The_Event.

9. Publish an event from Salesforce to see it in the Eclipse Console.

Sample Code:

Test_Event__e objEvent = new Test_Event__e( Test__c = String.valueOf( system.now() ) );
EventBus.publish( objEvent );

Leave a Reply