Sunday 10 May 2020

Subscribe platform event from an external app using EMP Connector


Subscribe Platform Event from an External app using EMP Connector

      External apps can subscribe to platform events with CometD and perform long polling. CometD is a scalable HTTP-based event routing bus that uses an AJAX push technology

   Salesforce provides a Java library, EMP Connector, which implements all the details of connecting to CometD and listening on a channel. You can use EMP Connector to subscribe easily to platform events.


EMP Connector is a free, open-source, community-supported tool. Salesforce provides this tool as an example of how to subscribe to events using CometD. EMP Connector is based on Java 8 and uses CometD version 3.1.0. It supports username and password authentication and OAuth bearer token authentication. This walkthrough shows steps only for username and password authentication.



Let's look at an example:

Step1: Create a platform Event Object


As you can see in the screenshot I created one PE and added a custom  text field "Account_Name__c"

Step2: Create a process builder on Account to publish Platform Event 




when an account record is created or edited this process builder will create a record in Platform Event Object(publish a PE)

Step3: Subscribe Platform Event from an external application

1. You can download the EMP Connector project from:
https://github.com/forcedotcom/EMP-Connector
and then extract the zip to a local folder.  

2. In Eclipse, import the Maven project from the folder where you cloned or extracted the project. The dependencies that are specified in the Maven’s pom.xml file, such as CometD, are added in the Java project in Eclipse.   


3. You Subscribe to an event channel by running the LoginExample class(/src/main/java/com/salesforce/emp/connector/example folder)

Related Post:


No comments:

Post a Comment