Newer Version Available
Create a Java Client
Create a Java client that uses Bayeux and CometD to subscribe
to the channel.
- Download and install the CometD and Jetty .jar files if necessary.
-
In a new Java project, add the following code to a Java
source file named StreamingClientExample.java. This code subscribes to the Streaming channel you created and listens
for notifications. Depending on your Java development environment,
you might have to rename this file and class to Main.
-
Edit StreamingClientExample.java and
modify the following values:
File Name Static Resource Name USER_NAME Username of the logged-in user PASSWORD Password for the USER_NAME (or logged-in user) CHANNEL /u/notifications/ExampleUserChannel LOGIN_ENDPOINT https://test.salesforce.com (Only if you are using a sandbox. If you are in a production organization, no change is required for LOGIN_ENDPOINT.) -
Add the following code to a Java source file named SoapLoginUtil.java. This code sends a username and password
to the server and receives the session ID.
-
When you run this client app and generate notifications
using the REST resource, the output will look something like: