This section explains, through an example scenario, how the Channel Adapter EIP can be implemented using WSO2 ESB. The following topics are covered:
Introduction to Channel Adapter
Channel Adapter accesses an application's API or data and publishes messages on a channel based on this data. Also, it receives messages and invokes functionality inside the application.
For more information on Channel Adapter, refer to http://www.eaipatterns.com/ChannelAdapter.html.
Figure 1: Channel Adapter EIP
This example demonstrates WSO2 ESB's Salesforce connector transferring a message coming from a stock quote client to Salesforce API and then sends the queried response that comes from Salesforce back to the client. The diagram below depicts how to simulate the example scenario using WSO2 ESB.
Figure 2: Example Scenario of the Channel Adapter EIP
Before digging into implementation details, let's look at how the core components in the example scenario map to the Channel Adapter EIP:
|Channel Adapter EIP (Figure 1)||Example Scenario (Figure 2)|
|Message Channel||Salesforce API|
- Download and install WSO2 ESB from http://wso2.com/products/enterprise-service-bus. For a list of prerequisites and step-by-step installation instructions, refer to Installation Guide in the WSO2 ESB documentation.
- Download the Salesforce connector from https://github.com/wso2/esb-connectors/blob/master/distribution/salesforce/salesforce-connector-1.0.0.zip.
- Add and enable the Salesforce connector to your ESB instance as explained in Managing Connectors in WSO2 ESB.
- Sign up for a Salesforce developer account at https://developer.salesforce.com/. A security token will be sent to your email address. You will use your Salesforce user name, password, and this security token in the configuration below.
Start the ESB server and log into its management console UI (
//localhost:9443/carbon ). In the management console, navigate to the Main menu and click Source View in the Service Bus section. Next, copy and paste the following configuration, which helps you explore the example scenario, to the source view.
Replace the Salesforce credentials used in the configuration below with valid credentials.
Simulating the sample scenario
Send a request as follows using the Stock Quote Client to WSO2 ESB.
ant stockquote -Dtrpurl=http://localhost:8280
This command executes the connector, which sends a request to Salesforce and sends the response from Salesforce back to the client.
How the implementation works
Let's investigate in detail the elements of the ESB configuration. The line numbers below refer to the ESB configuration shown above.
- main sequence [line 18 in ESB config] - The default sequence that is triggered when the user invokes the ESB server.
- sequence [line 5 in ESB config] - The message is directed to the
inmediator when it is received by the
- salesforce.init [line 6 in ESB config] - Triggers the login call to saleforce and retrieves the security token.
- salesforce.query [line 11 in ESB config] - Triggers the query call to salesforce and retrieves the results.
- respond [line 15 in ESB config] - Sends the result back to the client.