This article is for exploring integration possibilities via outbound messages and solving below problems:
- Timeout issue – In salesforce there is strict limit of 120 seconds for callout. This could be solved if API calls are carried outside of salesforce like in heroku app where no such limit for callout is there.
- API Calls which requires polling – Polling for response becomes difficult in salesforce as in order poll for result batch is required which runs at regular interval but there cannot be more than 5 batches running simultaneously. This can be solved by implementing polling logic in heroku app where threading could be used for polling and making inbound call to salesforce when results are available.
This idea came up when I was having discussion with my colleague Tushar Kaore on integration approaches. We thought that lets try to analyze the performance and reliability of outbound messages in integration.
Here is the design of this framework:
Integration via Outbound Messages
Lets see how this would work
- Whenever API Call has to be made then in salesforce API Call record has to be created which would include below details
- On create of such API Call records salesforce would initiate an outbound message call to the heroku application with all the details which would be required to make API call
- Actual API Call will be made by heroku app to the external system. Here an API call which takes more than 120 seconds can be made and it is required to do polling then heroku app can handle that by polling in regular intervals of time.
- Heroku app will receive the response.
- Inbound API call would be made to salesforce to pass on the response received by heroku app.
- Response would be updated in API Call record and on trigger of API Call record response could be processed and proper actions could be taken.
In this structure two applications are involved Salesforce App and Heroku app.
Steps to configure app:
- Heroku App: Install the Heroku App : heroku-api-call by using deploy to heroku button from repository home page.
- Salesforce App: Insall the Salesforce App : sf-api-call by using Deploy to Salesforce button from repository home page.
- Configure workflow rule: Create workflow rule on API Call object with the outbound message action as per below screenshot.
Outbound Message Action
- Add Remote Site setting: Add the remote configured endpoint as remote site setting.
How to test:
Create an API Call record in salesforce with the endpoint. As soon as the record gets created salesforce will make outbound message call to heroku app. Heroku app will make API call to the endpoint and it will be update the received response to salesforce via making inbound api call.
I will be be testing this for performance and will check its reliability to use in production applications. Currently only GET API calls are supported and will update the code to have below featues:
- Headers support
- POST call support
features list will go on…..
Whenever real time integration is not required and this approach could be used to solve issues of
- Callouts taking more than 120 seconds
- Whenever polling for response is required.
Result of this exercise:
I created nearly 50K API calls (thats lots of API calls) and tried to see how many API calls will get processed by this mechanism. Results are very promising
Results shows that 20K API calls are fulfilled within 3 minutes i.e. 113 fulfilled API call/second. My heroku instance was bombarded with outbound messages calls and now it is down.. 🙂
Note these are the results with free heroku instance with one dyano only. So imagine if you have a heroku app with good number of dynos to fulfill requrest then you can think of very promising results.
API Call is made to http://headers.jsontest.com/ for testing.
Happy learning and keep exploring..