SUMMER OF APIs Force.com Streaming API · Further information on potential factors that could...
Transcript of SUMMER OF APIs Force.com Streaming API · Further information on potential factors that could...
Join the conversation on Twitter: #forcewebinar @forcedotcom
Force.com Streaming API SUMMER OF APIs
Pat Patterson Principal Developer Evangelist @metadaddy
Alex Toussaint Senior Product Manager @alextoussaint
Join the conversation on Twitter: #forcewebinar @forcedotcom
Force.com Streaming API SUMMER OF APIs
Pat Patterson Principal Developer Evangelist @metadaddy
Alex Toussaint Senior Product Manager @alextoussaint
Join the conversation on Twitter: #forcewebinar @forcedotcom
July 19th Apex REST API
Register at http://developer.force.com See Upcoming Events
Summer of APIs Webinar Series
Join the conversation on Twitter: #forcewebinar @forcedotcom
Got Twitter? @forcedotcom / #forcewebinar
Facebook? facebook.com/forcedotcom
Join the conversation on Twitter: #forcewebinar @forcedotcom
Safe harbor statement under the Private Securities Litigation Reform Act of 1995: This presentation may contain forward-looking statements that involve risks, uncertainties, and assumptions. If any such uncertainties materialize or if any of the assumptions proves incorrect, the results of salesforce.com, inc. could differ materially from the results expressed or implied by the forward-looking statements we make. All statements other than statements of historical fact could be deemed forward-looking, including any projections of subscriber growth, earnings, revenues, or other financial items and any statements regarding strategies or plans of management for future operations, statements of belief, any statements concerning new, planned, or upgraded services or technology developments and customer contracts or use of our services.
The risks and uncertainties referred to above include – but are not limited to – risks associated with developing and delivering new functionality for our service, our new business model, our past operating losses, possible fluctuations in our operating results and rate of growth, interruptions or delays in our Web hosting, breach of our security measures, the immature market in which we operate, our relatively limited operating history, our ability to expand, retain, and motivate our employees and manage our growth, new releases of our service and successful customer deployment, and utilization and selling to larger enterprise customers. Further information on potential factors that could affect the financial results of salesforce.com, inc. is included in our annual report on Form 10-K filed on February 24, 2011 and in other filings with the Securities and Exchange Commission. These documents are available on the SEC Filings section of the Investor Information section of our Web site.
Any unreleased services or features referenced in this or other press releases or public statements are not currently available and may not be delivered on time or at all. Customers who purchase our services should make the purchase decisions based upon features that are currently available. Salesforce.com, inc. assumes no obligation and does not intend to update these forward-looking statements.
Safe Harbor
Join the conversation on Twitter: #forcewebinar @forcedotcom
Agenda
What is the Streaming API?
When would I use it?
How do I use it?
How do I get started?
What’s the future?
Resources
Q & A
Join the conversation on Twitter: #forcewebinar @forcedotcom
What is streaming?
Streaming is the ability for a client to issue a single request and receive in response a continuous stream of updates from a server – Publish/subscribe model – Related to push technology
Examples – “New Account record created”
– “Opportunities with a deal size greater than $1M”
Join the conversation on Twitter: #forcewebinar @forcedotcom
When would I use streaming?
To receive near real-time notification of new or updated data – Taking action on change in state – e.g. send alert
– Synchronize state – e.g. update page in browser
If you are currently polling an API! – Much more efficient consumption of API calls
Join the conversation on Twitter: #forcewebinar @forcedotcom
Common Use Cases
Call Center and Support Apps – Salesforce Service Cloud – Tech Call Centers working on Cases
Financial Apps – Keep brokers and financial consultants up to date
Social Apps – Live Chatter (in future release)
Light Data Sync – Keep in-house data in sync
– Update other cloud systems
Join the conversation on Twitter: #forcewebinar @forcedotcom
Polling vs Streaming
Streaming – Client connects and
receives near real-time updates
– Bayeux protocol
– Consumes one API call per client (only when data is available)
Polling – Client must repeatedly
call API – SOAP/REST APIs
– Each poll consumes at least one API call per client (even if data is not available)
Join the conversation on Twitter: #forcewebinar @forcedotcom
Triggers vs Streaming
Streaming – Client connects and
receives near real-time updates
– Client can be any app that can talk HTTP – server process, JavaScript in browser etc.
– One to 1000 clients
– Bayeux protocol
Trigger + future – Trigger is executed on
data modification; may call web service via ‘future’ method
– Server must expose endpoint to receive messages
– (Typically) single server
– SOAP/REST APIs
Join the conversation on Twitter: #forcewebinar @forcedotcom
The Force.com Streaming API
Administrator creates a topic based on a SOQL query – PushTopic standard object
‘UX People’ by Peter Morville and Jeff Callender (‘Search Patterns’)
Join the conversation on Twitter: #forcewebinar @forcedotcom
The Force.com Streaming API
Client applications subscribe via the Bayeux protocol – http://svn.cometd.com/trunk/bayeux/bayeux.html
‘UX People’ by Peter Morville and Jeff Callender (‘Search Patterns’)
Join the conversation on Twitter: #forcewebinar @forcedotcom
The Force.com Streaming API
Client applications receive notifications on creates and updates that match WHERE clause of query
‘UX People’ by Peter Morville and Jeff Callender (‘Search Patterns’)
Join the conversation on Twitter: #forcewebinar @forcedotcom
Create a topic
Apex or API
Create PushTopic standard object – ApiVersion, Name, Query are required fields; Description is optional
PushTopic pushTopic = new PushTopic();
pushTopic.ApiVersion = 22.0;
pushTopic.Name = ’AllAccounts';
pushTopic.Description = 'All of our accounts';
pushtopic.Query = 'SELECT Id, Name FROM Account';
insert pushTopic;
What!? No LIMIT???
Join the conversation on Twitter: #forcewebinar @forcedotcom
Valid Streaming Queries
Query MUST include Id in the root of the SELECT statement, may include any other fields to be included in notifications – SELECT Id, Name, Email FROM Contact;
Object can be – a custom object – one of Account, Campaign, Case, Contact, Lead, Opportunity
Join the conversation on Twitter: #forcewebinar @forcedotcom
Valid Streaming Queries – WHERE Clause
Query may include a WHERE clause – SELECT Id FROM Account WHERE NumberOfEmployees > 1000
– Notification is generated when field specified in WHERE clause changes
– If no WHERE clause is specified, then notifications are generated for ALL changes and updates
– Special case – use record id in WHERE clause to receive updates on ANY change to the record
Join the conversation on Twitter: #forcewebinar @forcedotcom
Demo 1
Create topic in Workbench
Create topic in Java
(There will also be a simple Visualforce page to create a PushTopic in the documentation)
Join the conversation on Twitter: #forcewebinar @forcedotcom
Is Streaming ON for my Org?
You can check under – Setup > Customize > User Interface > Enable Streaming API
From SOQL – SELECT Name FROM PushTopic
From Workbench – Queries > PushTopics
Join the conversation on Twitter: #forcewebinar @forcedotcom
Streaming API - Logical Flow
Account Contacts
Leads Opportunities
Custom Objects
Manage Subscriptions Send Updates
1. Relevance Checks 2. Push Notification Processor 3. Event Dispatch 4. Query, CRUD, FLS, Sharing
Data Changes Processing Updates Notifications
Join the conversation on Twitter: #forcewebinar @forcedotcom
Subscribe via Bayeux protocol
Endpoint https://hostname/cometd – Hostname is Force.com instance URL or Visualforce server
hostname
MUST set sid (session ID) cookie on request – Cookie is set by default in JavaScript loaded from Visualforce
$.cometd.init(window.location.protocol+'//'+ window.location.hostname+'/cometd');
$.cometd.subscribe('/Contacts', function(message) {
$('#content').append('<p>New record: ' +
JSON.stringify(message.data.Name) + '</p>');
});
Join the conversation on Twitter: #forcewebinar @forcedotcom
Demo 2
Receive updates in Visualforce page – JavaScript, using CometD with jQuery bindings – Cookie handling is done for us
Join the conversation on Twitter: #forcewebinar @forcedotcom
Bayeux Implementations
Official CometD client libraries exist for JavaScript and Java – cometd.org
Implementations also exist for – Ruby – Node.js
– ActionScript/Adobe Flex MXML
– PHP
– Perl
Join the conversation on Twitter: #forcewebinar @forcedotcom
Demo 3
Authenticate via OAuth username/password flow
Create topic in Java app (via REST API)
Receive updates in Java app – Set cookie in default Java Bayeux client
Join the conversation on Twitter: #forcewebinar @forcedotcom
Limits Description Limit Maximum number of topics 20 Maximum number of clients (subscribers) per topic 1,000
Maximum number of concurrent clients (subscribers) across all topics
1,000
Timeout for inactivity during connection (server session) 110 sec
Timeout for inactivity after successful connection (keepalive) 40 sec
Timeout for session, regardless of activity (maximum session) 3600 sec
Maximum length of the SOQL query in the Query field of a PushTopic record
1300 chars
Join the conversation on Twitter: #forcewebinar @forcedotcom
How Do I Get Started?
Sign up for a Developer Edition (if you have not already done so) – http://developer.force.com/join
We will be seeding the developer community with a number of invites
You can get on the waiting list for an invite at http://developer.force.com/streaming-api-activate
Join the conversation on Twitter: #forcewebinar @forcedotcom
Best Practices
Run the Quick Start in the docs
Download Workbench – Latest version (22.0.0) includes Streaming API support
Leverage debugging tools: – Proxy such as Burp/Fiddler/Charles
– Firebug in the browser
Join the conversation on Twitter: #forcewebinar @forcedotcom
Safe Harbor: Streaming API Possible Areas of Exploration
Several areas under consideration – send feedback – Streaming Buffers (last 100 messages) – Dial Tone Test
– Add HTTP Authorization/OAuth header
– Notify on deletes
– Increased limits
– Reduce Relevance interval – More Salesforce native objects
Join the conversation on Twitter: #forcewebinar @forcedotcom
Sessions at Dreamforce 2011
Getting Started with the Force.com Streaming API
Event-Driven Programming with Node.js and the Force.com Streaming API
Register at http://developer.force.com/DF11offer
Join the conversation on Twitter: #forcewebinar @forcedotcom
July 19th Apex REST API
Register at http://developer.force.com See Upcoming Events
Summer of APIs Webinar Series
Join the conversation on Twitter: #forcewebinar @forcedotcom
Resources
Streaming API Resource Page – http://developer.force.com/streaming-api
Streaming API Developer Preview Waiting List – http://developer.force.com/streaming-api-activate
Join the conversation on Twitter: #forcewebinar @forcedotcom
Feedback: http://bit.ly/StreamingAPI7am
Questions?