Newer Version Available

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

Step 4: Use the Connector with Username and Password Login

Now that you’ve downloaded and built the EMP connector, use it to connect to CometD and subscribe to the PushTopic.
Let’s run an example that uses username and password login.
  1. In the /src/main/java/com/salesforce/emp/connector/example folder, open the LoginExample.java Java source file.
  2. Run the LoginExample class, and provide the following argument values.
    Argument Value
    username Username of the logged-in user
    password Password for the username (or logged-in user)
    topic /topic/InvoiceStatementUpdates
    The sample fetches the earliest saved events within the past 24 hours. Optionally, 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.
    • –2—Get all new events sent after subscription and all past events within the past 24 hours.
    • Specific number—Get all events that occurred after the event with the specified replay ID.
  3. In a browser window, create or modify an invoice statement. After you create or change data that corresponds to the query in your PushTopic, the output looks similar to the following.
Generally, do not 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.