Integrating Salesforce.com with an On-Premise Database
This tutorial demonstrates how to configure and deploy a CloudHub application that reads data from Salesforce.com and writes it to an on-premise MySQL database. This tutorial will walk you through the following steps:
- Create the Test Database
- Download the Example Project
- Update the Mule Configuration
- Build the Example Application
- Deploy the Application to CloudHub
- Use the Application
Prerequisites
- If you have not already reviewed the documentation and downloaded the Secure Data Gateway, please do so before getting started with this tutorial.
- This example requires an existing Salesforce.com account. To create a new developer account, see Salesforce.com Developer Account Setup. After setting up a Salesforce.com account, a security token will be emailed to you. Be sure to save this, as you will need it later in this tutorial.
Create the Test Database
In order to run the cloudhub-sfdc-test application and integrate Salesforce.com data with a private MySQL database, the expected database and table needs to be present. Run the following SQL commands on the database server referenced by the privateHost configuration element in the SDG conf/mappings.xml file.
Queries from CloudHub applications will be executed as the user specified in the Mule configuration. If necessary, ensure that the server running the SDG Client has the authority to connect to and issue queries against the database as that user.
Download the Example Project
Download the ion-sfdc-test-project-1.0.zip package and expand it.
Update the Mule Configuration
The cloudhub-sfdc-test/src/main/app/mule-config.xm is shown below:
Update mule.properties
Notice the ${db.username}, ${db.password} and ${sdg.port} variables in the mule-config.xml file.
The ${db.username} and ${db.password} parameters are credentials for the private MySQL database. The ${sdg.port} setting should match the remotePort value in the SDG conf/mappings.xml file. The cloudhub-sfdc-test-app application will use this local port to communicate with the SDG and private database.
The ${sf.username} ${sf.password} and ${sf.security.token} variables need to be set for connecting to Salesforce.com. The username is the email address used to set up the account and the security token should be the one emailed to that address.
Update these parameter values in cloudhub-sfdc-test-app/src/main/resources/mule.properties.
Build the Example Application
The example application can be built using the Maven pom.xml included in the download.
To build the application, run the following command at the root level of the cloudhub-sfdc-test-app project:
When the build completes, the application is packaged for deployment and located at cloudhub-sfdc-test-app/target/cloudhub-sfdc-test-app-1.0.zip.
Deploy the Application to CloudHub
Follow this procedure to deploy your application cloudhub-sfdc-test-app-1.0.zip to CloudHub. Click on Logs on the left-hand side to verify that your application has been successfully deployed. You should see the following text:
Use the Application
Once your application has been deployed, you can use it to transfer data from Salesforce.com to a private MySQL database with the application URL: http://YOURAPPNAME.cloudhub.io/listaccount.
The application port variable ${http.port} is specified by CloudHub and is load-balanced for you, so there is no need to specify port information in your application URL.
The first time the application is used, it will execute more slowly than subsequent invocations. This is because the Salesforce and JDBC connectors must initialize and establish connections.
Note: Make sure that the Secure Data Gateway is running on the private network before using the application URL. If the SDG is note properly connected to CloudHub, you will see database connection errors in the CloudHub logs.
Behind the Scenes
This configuration instructs Mule to listen for HTTP requests on the http://localhost:$\{http.port}/listaccount inbound endpoint.
The ${http.port} variable is dynamically provided by CloudHub and should be left parameterized as in this example. The server should also be left to localhost, as the CloudHub load balancer will handle directing traffic to the application.
When the HTTP inbound endpoint is invoked, a query is issued to Salesforce.com for the Id and Name of an Account.
An outbound JDBC connector is configured to insert this data into a on_test.cloudhub_sfdc_test_table MySQL table. The JDBC datasource url spring property references the private database over the ${sdg.port}, which is securely connected to the SDG Client running on the enterprise network. The SDG Client, in turn, brokers the connection between CloudHub and the private MySQL database.
Note: be sure this ${sdg.port} matches the remotePort mapping in the SDG conf/config.xml file.
For more information on application deployment, see the Getting Started with CloudHub guide.