Example: Subscribe to and Replay Events Using a Java Client (EMP Connector)
The Java sample uses a library called Enterprise Messaging Platform (EMP) Connector. EMP Connector is a thin wrapper around the CometD library. It hides the complexity of creating a CometD client and subscribing to Streaming API in Java. The example subscribes to a channel, receives notifications, and supports replaying events with durable streaming.
The EMP Connector sample is deprecated and will be archived in the future. The EMP Connector code is an example only and isn’t intended for production environments. It hasn’t been rigorously tested nor performance tested for throughput and scale.
Are you looking for a code sample for subscribing to platform events and change events? Check out the Java Quick Start for Pub/Sub API in the Pub/Sub API Guide.
The CometD-based subscription mechanism in EMP Connector can receive any type of Salesforce event. Just pass in the channel name of the desired event. For example, the events that EMP Connector can receive include:
- Platform events
- Change Data Capture events
- PushTopic events (legacy)
- Generic events (legacy)
EMP Connector is based on Java and uses CometD version 3.1.0. It supports username and password authentication and OAuth bearer token authentication.
The example requires API version 37.0 or later. For a code example that supports earlier API versions, refer to an earlier version of this documentation.
-
You need access and appropriate permissions to complete the code example.
-
Create an Invoice Statement object from the user interface.
-
Step 2: Create a PushTopic (Legacy)
Create a PushTopic in the Developer Console. Event notifications are generated for updates that match the query.
-
Step 3: Download and Build the Project
Before you can run the connector examples, download the Java source files and build the Java project.
-
Step 4: Use the Connector with Username and Password Login
Now that you’ve downloaded and built EMP Connector, use it to connect to CometD and subscribe to the PushTopic.
-
(Optional) Step 5: Use the Connector with OAuth Bearer Token Login
You can use the connector with OAuth authentication as an alternative to username and password authentication. This step is optional and requires an OAuth token.
-
Learn More About EMP Connector
Let’s take a closer look at the components of EMP Connector.
See Also