MuleESB:将Salesforce数据插入到mysql数据库中

时间:2017-04-03 14:24:21

标签: mysql salesforce mule

我有一个关于将salesforce数据插入mysql数据库的问题。

我可以查询salesforce帐户,并且我正在从salesforce帐户中检索正确的数据。

如果我想将salesforce数据插入mysql数据库,则会出错。 Just NULL值将插入数据库。

我认为对mysql组件的输入是正确的,但输出是错误的。

也许你可以帮助我。

附件是我的xml代码。怎么了?

<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:json="http://www.mulesoft.org/schema/mule/json" xmlns:dw="http://www.mulesoft.org/schema/mule/ee/dw" xmlns:db="http://www.mulesoft.org/schema/mule/db" xmlns:metadata="http://www.mulesoft.org/schema/mule/metadata" xmlns:sfdc="http://www.mulesoft.org/schema/mule/sfdc" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
    xmlns:spring="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/db http://www.mulesoft.org/schema/mule/db/current/mule-db.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/sfdc http://www.mulesoft.org/schema/mule/sfdc/current/mule-sfdc.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/ee/dw http://www.mulesoft.org/schema/mule/ee/dw/current/dw.xsd
http://www.mulesoft.org/schema/mule/json http://www.mulesoft.org/schema/mule/json/current/mule-json.xsd">
    <http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8081" doc:name="HTTP Listener Configuration"/>
    <db:mysql-config name="MySQL_Configuration" host="localhost" port="xxx" user="xxx" password="xxx" database="salesforce" doc:name="MySQL Configuration"/>
    <sfdc:config name="Salesforce__Basic_Authentication" username="xxxx" password="xxx" securityToken="xxxx" doc:name="Salesforce: Basic Authentication"/>
    <flow name="salesforce_query_mysqlFlow">
        <http:listener config-ref="HTTP_Listener_Configuration" path="/demo" doc:name="HTTP"/>
        <sfdc:query config-ref="Salesforce__Basic_Authentication" query="dsql:SELECT BillingCity,BillingCountry,BillingPostalCode,BillingStreet,Id,Name,Phone,Website FROM Account" doc:name="Salesforce"/>
        <logger message="#[org.apache.commons.collections.IteratorUtils.toList(message.payload)]" level="INFO" metadata:id="d66ba8a4-9f12-4def-b4fe-ea0669d02170" doc:name="Logger"/>
        <dw:transform-message metadata:id="72012d35-6807-484b-89bf-cab577f4f646" doc:name="Transform Message">
            <dw:input-payload mimeType="application/java" doc:sample="sample_data/list_Account_2.dwl"/>
            <dw:input-variable  variableName="salesforce_data"/>
            <dw:set-payload><![CDATA[%dw 1.0            
%output application/java
---

payload map {
    BillingCountry: $.BillingCountry,
    BillingCity: $.BillingCity,
    BillingStreet: $.BillingStreet,
    Phone:  $.Phone,
    Website:  $.Website,
    BillingPostalCode: $.BillingPostalCode,
    Name: $.Name,
    SalesforceId: $.Id
}]]></dw:set-payload>
        </dw:transform-message>
        <db:insert config-ref="MySQL_Configuration" doc:name="Database" >
            <db:parameterized-query><![CDATA[INSERT INTO salesforce.salesforce_account(
BillingCity,BillingCountry,BillingPostalCode,BillingStreet,Name,Phone,Website,Id)
VALUES 
(#[message.payload.BillingCity],#[message.payload.BillingCountry],#[message.payload.BillingPostalCode], #[message.payload.BillingStreet], #[message.payload.Name], #[message.payload.Phone],#[message.payload.Website],
#[message.payload.SalesforceId]);]]></db:parameterized-query>
        </db:insert>
        <logger message="#[message.payload]" level="INFO" doc:name="Logger"/>
    </flow>
</mule>

1 个答案:

答案 0 :(得分:0)

您还需要一个步骤才能将 Salesforce 中的所有记录插入数据库。在当前配置中,转换消息组件的输出是记录列表。虽然数据库查询需要单条记录。因此,您应该选择以下选项之一:

  1. 转化消息数据库之间添加 Collection Splitter 组件
  2. 检查/勾选数据库属性bulkMode="true"
  3. 基本设置部分内的批量模式选项