Newer Version Available
Subscribe with CometD Using the EMP Connector Sample
Salesforce provides a connector to CometD that subscribes to streaming events. The EMP
connector sample is a thin wrapper around the CometD library and simplifies subscribing to data
change events in Java. The tool subscribes to a channel, receives notifications, and supports
replaying events with durable streaming.
Prerequisites:
- Git. See Git Downloads.
- Apache Maven. This example uses Apache Maven to build the EMP Connector project. Download and install it from the Apache Maven site.
- Java Development Kit 8 or later. See Java Downloads.
Steps:
-
To get a local copy of the EMP-Connector GitHub repository:
1$ git clone https://github.com/forcedotcom/EMP-Connector.git -
To build the EMP-Connector tool, enter these commands:
1$ cd EMP-Connector 2$ mvn clean packageThe generated JAR file includes the connector and the DevLoginExample functionality. The shaded JAR contains all the dependencies for the connector, so you don’t have to download them separately. The JAR file has a -phat Maven classifier. -
Run this command.
1$ java -classpath 2target/emp-connector-0.0.1-SNAPSHOT-phat.jar com.salesforce.emp.connector.example.DevLoginExample https://MyDomainName.my.salesforce.com <username> <password> <channel>For a sandbox, replace https://MyDomainName.my.salesforce.com with https://MyDomainName--SandboxName.sandbox.my.salesforce.com.
For <channel>, use the channel to subscribe to. For example, /data/ChangeEvents.