Run a Java Client with Username and Password Login
Run a Java client that uses EMP Connector to subscribe to the channel with username and password authentication.
-
Get the EMP Connector project from GitHub. See Step 3: Download and Build the Project.
-
In the /src/main/java/com/salesforce/emp/connector/example folder, open the LoginExample.java source file.
-
Run the
LoginExampleclass and provide arguments.Argument Value username Username of the logged-in user. password Password for the username (or logged-in user). channel /u/notifications/ExampleUserChannelOptionally, to receive different events, you can include a replay ID as the last argument. Valid values are:
- –1 — Get all new events sent after subscription. This option is the default.
- –2 — Get all new events sent after subscription and all past events within the retention window. Use -2 sparingly. If a large volume of event messages is stored, retrieving all event messages can slow performance.
- Specific number — Get all events that occurred after the event with the specified replay ID.
-
When you run this client app and generate notifications using the REST resource, the output will look something like:
Generally, don’t handle usernames and passwords of others when running code in production. In a production environment, delegate the login to OAuth. The next step connects to Streaming API with OAuth.