Presentation slide deck used used for Forcelandia 2018. Learn how to create lightning components embedded with streaming API to display always up to date information.
Scaling API-first – The story of a global engineering organization
Forcelandia 2018 - Create lively lightning components with streaming api
1. Create Lively Lightning
Components with
Streaming API
Anshul Verma
Cynoteck Technology Solutions LLC
Email: anshul.verma@Cynoteck.com
Twitter: @toanshulverma
2.
3. Agenda
• Need
• Traditional Model (Pull)
• Push notifications (browser)
• Example Use cases
• Live Demo
• Salesforce Streaming API
• What’s under the hood
• Code Walkthrough
• Q&A
4. Need
• Stale/ Old information
• True Collaboration with real time updates
• Decisions with most up to date information
• Faster response
• Adherence to Governor limits
5. Traditional Model (Pull)
Server
(Salesforce)
Client
(Browser)
2 3
Opens
connection
Connection
established
4 5
2
3
Client sends
request
4
Server sends
response
5
Connection
closed
6
Execution block -
every time
update is
required
1 6
User wants to view
updated
information
1
6. Push Notifications (browser)
Server
(Salesforce)
Client
(Browser)
1 2
Subscribe to a
Topic
Subscription
Confirmation
5
6
3
4
New information
arrives on server
Message pushed to
client
6
5
Execution block -
every time
update is
required
3 4
Initiate Handshake
Handshake
successful
1
2
7. Publisher/ Subsriber Model (Pub-Sub)
Publisher
(Salesforce)
Account updates New Payments New Credits
Subscriber 1 Subscriber 2 Subscriber 3 Subscriber N
……
11. Push Topic
- Query - SOQL query qualifying a message
- NotifyForFields - Specify Fields which qualify to generate a push message
- Valid Values: All, Referenced (default), Select, Where
- NotifyForOperations – specify which operations qualify to generate a push message
- Valid Values: All (default), Create, Extended, Update
What is a Push Topic
12. Salesforce Streaming API Library – under the hood
- Javascript based API to internally handle complexity of connecting to Salesforce’s streaming API
and provides a developer friendly way
- Protocol – Bayeux
- Defines how asynchronous messages should be transported
- Messaging API - CometD
- Implements Bayeux protocol to create subscription endpoints and handle message distribution
- Streaming technique - Long Polling
- Client sends a request to server
- Server holds back response, untill a new message arrives
13. Long Polling (under the hood)
Server
(Salesforce)
Client
(Browser)
Salesforce Streaming API Library
Long polling mechanism to open connection to
server and allow server to wait and respond
Handshake Subscribe
New Message
Push
Notification