Cloud-to-Intranet messaging by Force.com Streaming API

728 views

Published on

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
728
On SlideShare
0
From Embeds
0
Number of Embeds
9
Actions
Shares
0
Downloads
8
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Cloud-to-Intranet messaging by Force.com Streaming API

  1. 1. Cloud-to-Intranet messagingby Force.com Streaming API Shinichi Tomita @stomita Mashmatrix, Inc.
  2. 2. Cloud-to-Intranetmessaging in Force.com• HTTP callout / Outbound Messaging - Open inbound HTTP port on firewall (Almost impossible for usual companies)• API Polling - Not realtime / Consumes a lot of API quotas• Force.com Streaming API - No need to open inbound port on firewall - Almost realtime
  3. 3. Force.com Streaming API• Enables push notification from Server to subscribed client(s)• GA in Spring ’12• Standard based (Bayeux protocol) - Client libraries available in various languages
  4. 4. Message flow for generic request clients1. SecureConnect request client creates a record which includes request message to Intranet resource server2. Force.com publishes a notification to its request channel subscribers (= SecureConnect resource server)3. Resource server processes the request and access to the resource data behind the firewall4. Resource server returns response by updating the request record5. Force.com publishes a notification to its response channel subscribers (= SecureConnect request client), and SecureConnect request client receives response
  5. 5. Message flow for generic request clients 3. resource accesss 4. response 1. request Resource Server 5. Streaming 2. StreamingRequest Client
  6. 6. Callout from Apex• On submitting request, register an object which implements ResponseListener interface - Both request message and response listener object are serialized and inserted as a record• Registered response listener is callbacked by Apex trigger when the response arrived
  7. 7. Callout from Apex 3. resource access 4. response 1. request Apex Class Resource Response Listener 5. trigger Server 2. StreamingRequest Client
  8. 8. Sample code/** * An example client which link opportunity information to intranet system via SecureConnect */public class OpportunitySynchronizer { public static void linkToExternalSystem(Opportunity opp) { String oppJson = JSON.serialize(opp); SecureConnect.request(opps/link, opp.Id, new PropagateResponseListener(opp.Id)); } /** * Callbacked when the response arrived from intranet server */ public class LinkResponseListener implements SecureConnect.ResponseListener { public Id oppId { get; set; } public LinkResponseListener(Id oppId) { this.oppId = oppId; } public Type getClassType() { return LinkResponseListener.class; } public void onResponse(String responseCode, String responseData) { if (responseCode == success) { String extId = responseData; Opportunity opp = new Opportunity(Id=this.oppId, ExtId__c=extId); update opp; } } }}
  9. 9. Project on GitHub• http://github.com/stomita/fdc-secureconnect

×