Newer Version Available
Subscribe to a Standard Platform Event Channel
Use EMP Connector to subscribe to the channel of the LoginEventStream standard
platform event. This channel tracks user logins in real time and is part of Real-time Event
Monitoring.
-
In Setup, enable streaming for the LoginEventStream event on the Event Manager
page.
-
In Eclipse, run the LoginExample class and
provide arguments.
- In Package Explorer, navigate to the LoginExample.java file. Right-click the file, and select .
-
On the Arguments tab, add values for the following arguments, separated
by a space.
Argument Value username Your Salesforce username password Your Salesforce password channel The channel name for the event. For the LoginEventStream standard event, provide /event/LoginEventStream. To perform this quick start with another standard event, pass in a channel name in the following format: /event/Event_Name
- Click Run.
The sample is now subscribed to the event channel and is listening to event notifications. As soon as an event notification is generated and received, the tool prints it to the console.
The sample fetches the earliest saved events within the retention window. 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 retention window.
- Specific number—Get all events that occurred after the event with the specified replay ID.
-
To generate an event message for a standard platform event, perform the action
that fires the event. For LoginEventStream, log in to Salesforce.
- In a browser window, navigate to https://login.salesforce.com.
- Enter your Salesforce username and password (or the credentials of another user in your org), and click Log In.
-
After you log in, EMP Connector receives an event notification for the
login action. The event message is printed in the console. The output
looks similar to the following.
1Subscribed: Subscription [/event/LoginEventStream:-2] 2Received: 3{ 4 "schema":"3J6UjLfL6cDEeBI84DSyTA", 5 "payload":{ 6 "EventDate":"2019-01-04T21:32:15.000Z", 7 "AuthServiceId":null, 8 "Platform":"Mac OSX", 9 "EvaluationTime":0.0, 10 "CipherSuite":"ECDHE-RSA-AES256-GCM-SHA384", 11 "ClientVersion":"N/A", 12 "LoginGeoId":"04F2J00006PqzoY", 13 "LoginUrl":"login.salesforce.com", 14 "LoginHistoryId":"0Ya2J0000Dt8t5aSQA", 15 "CreatedById":"00550000001ZtKcAAK", 16 "SessionKey":null, 17 "ApiType":"N/A", 18 "LoginType":"Application", 19 "PolicyOutcome":null, 20 "Status":"Success", 21 "AdditionalInfo":"{}", 22 "ApiVersion":"N/A", 23 "EventIdentifier":"eeccf731-2585-4a40-bfa5-770e31d6c2ab", 24 "RelatedEventIdentifier":null, 25 "SourceIp":"Salesforce.com IP", 26 "Username":"joe.smith@acme.com", 27 "UserId":"00550000001N45jAAC", 28 "CreatedDate":"2019-01-04T21:32:19.188Z", 29 "TlsProtocol":"TLS 1.2", 30 "LoginKey":"QuEoTPHKy22V68XV", 31 "Application":"Browser", 32 "UserType":"Standard", 33 "PolicyId":null, 34 "SessionLevel":"STANDARD", 35 "Browser":"Chrome 71" 36 }, 37 "event":{ 38 "replayId":2540 39 } 40}