The content in this documentation is for older versions of WSO2 products. For updated information on Enterprise Integration Patterns, go to the latest Micro Integrator documentation. "> The content in this documentation is for older versions of WSO2 products. For updated information on Enterprise Integration Patterns, go to the latest Micro Integrator documentation.

Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 23 Next »

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

Example scenario

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)

Sender Application

StockQuote Client

Channel Adapter

Salesforce Connector

Message

Query Request

Message ChannelSalesforce API

Environment setup

  1. 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 Getting Started in the WSO2 ESB documentation.
  2. Download the Salesforce connector from https://github.com/wso2/esb-connectors/blob/master/distribution/salesforce/salesforce-connector-1.0.0.zip.
  3. Add and enable the Salesforce connector to your ESB instance as explained in Managing Connectors in WSO2 ESB.
  4. 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.

ESB configuration

Start the ESB server and log into its management console UI (https: //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.

<? xml version = "1.0" encoding = "UTF-8" ?>
<!-- Message Channels -->
<definitions xmlns = "http://ws.apache.org/ns/synapse">
<!-- External sequence acts as a message channel -->  
< sequence name = "ChannelAdapter" >
 <salesforce.init>
   <username>salesforce_username</username>
   <password>salesforce_password + salesforce_security_token</password>
   <loginUrl>https://login.salesforce.com/services/Soap/u/27.0</loginUrl>
   </salesforce.init>
   <salesforce.query>
   <batchSize>200</batchSize>
  
 <queryString>select 
id,name,Account.name,AssistantName,AssistantPhone,Birthdate,CreatedBy.name,Department,Description,Email,HomePhone,LastModifiedBy.Name,MobilePhone,Title
 from Contact</queryString>
   </salesforce.query>
   <respond/>
  </ sequence >
<!-- Sender will invoke the following Sequence -->
< sequence name = "main" >
    <!-- The request will first trigger to the following -->
    < in >
         <!-- Allows calling of the following sequence defined through the key -->
         < sequence key = "ChannelAdapter" />
    </ in >
    < out >
         <!-- The response given out through the channel adapter will be sent back to the sender -->
        < send />
    </ out >
</sequence>
</definitions>

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 in mediator when it is received by the main sequence.
  • 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.
  • No labels