Newer Version Available

This content describes an older version of this product. View Latest

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.

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. To contribute to the EMP Connector project with your own enhancements, submit pull requests to the repository at https://github.com/forcedotcom/EMP-Connector.

Important

Prerequisites:

Steps:

  1. To get a local copy of the EMP-Connector GitHub repository:
    1$ git clone https://github.com/forcedotcom/EMP-Connector.git
  2. To build the EMP-Connector tool, enter these commands:
    1$ cd EMP-Connector
    2$ mvn clean package
    The 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.
  3. Run this command.
    1$ java -classpath 
    2target/emp-connector-0.0.1-SNAPSHOT-phat.jar com.salesforce.emp.connector.example.DevLoginExample 
    3<login_URL> <username> <password> <channel>

    For <login_URL>, use your org’s My Domain login URL, including the https:// prefix. For example, https://MyDomainName.my.salesforce.com. If you don’t have a deployed My Domain, use https://login.salesforce.com for a production org and https://test.salesforce.com for a sandbox or developer environment.

    For <channel>, use the channel to subscribe to. For example, /data/ChangeEvents.