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 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 source file.
  2. Run the LoginExample class and provide arguments.
    1. In Package Explorer, navigate to the LoginExample.java file. Right-click the file, and select Run As | Run Configurations.
    2. On the Arguments tab, add values for the following arguments, separated by a space.
      Argument Value
      username Username of the logged-in user
      password Password for the username (or logged-in user)
      channel The channel name for the PushTopic: /topic/InvoiceStatementUpdates

      This quick start is based on a PushTopic event. Alternatively, you can use EMP Connector to listen to any event type. The following lists channel name formats for a sample of streaming events available in the Lightning Platform.

      Note

      Platform event
      For a custom platform event—/event/EventName__e
      For a standard platform event—/event/EventName
      For a custom channel—/event/ChannelName__chn
      Change Data Capture event
      For all change events—/data/ChangeEvents
      For a specific standard object—/data/ObjectNameChangeEvent
      For a specific custom object—/data/CustomObjectName__ChangeEvent
      For a custom channel—/data/ChannelName__chn
      PushTopic event
      /topic/PushTopicName
      Generic event
      /u/notifications/GenericStreamingChannel
    3. Click Run.

    The sample is now subscribed to the event channel and is listening to event notifications. As soon as an event notification is published and received, the tool prints it to the console.

    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. 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.
  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.

    If you’re listening to another event type, the output would look a bit different. Some events require that you publish the notification instead of Salesforce, such as with platform events.

    Note

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.