使用Mulesoft将CSV文件从FTP插入MySQL

使用Mulesoft将CSV文件从FTP插入MySQL,mysql,ftp,mule,mule-studio,Mysql,Ftp,Mule,Mule Studio,我在Mulesoft EE还是新手。我需要从FTP服务器(Filezilla)获取CSV文件,并将其插入MySQL数据库(Wamp) 我想运行这个测试代码(为了测试,我用HTTP替换了FTP),但是postman插件没有显示任何结果 <?xml version="1.0" encoding="UTF-8"?> <mule xmlns:...> <db:mysql-config name="MySQL_Configuration" host="loc

我在Mulesoft EE还是新手。我需要从FTP服务器(Filezilla)获取CSV文件,并将其插入MySQL数据库(Wamp)

我想运行这个测试代码(为了测试,我用HTTP替换了FTP),但是postman插件没有显示任何结果

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

<mule xmlns:...>
    <db:mysql-config name="MySQL_Configuration" host="localhost"
        port="3306"   database="information"
        doc:name="MySQL Configuration" />
    <data-mapper:config name="CSV_To_XML" transformationGraphPath="csv_to_xml.grf" doc:name="CSV_To_XML"/>
    <jdbc-ee:mysql-data-source name="MySQL_Data_Source" user="User" password="Pass" url="jdbc:mysql://localhost:3306/information" transactionIsolation="UNSPECIFIED" doc:name="MySQL Data Source"/>
    <jdbc-ee:connector name="Database" dataSource-ref="MySQL_Data_Source" validateConnections="true" queryTimeout="-1" pollingFrequency="0" doc:name="Database"/>
    <flow name="dbFlow1" doc:name="dbFlow1">
 <http:inbound-endpoint exchange-pattern="one-way" host="localhost" port="8084" path="csv" doc:name="HTTP"/>
        <data-mapper:transform config-ref="CSV_To_XML" doc:name="CSV To XML"/>
        <byte-array-to-string-transformer doc:name="Byte Array to String"/>
        <foreach collection="#[xpath('//info')]" doc:name="For Each">
            <mulexml:dom-to-xml-transformer doc:name="DOM to XML"/>
            <db:insert config-ref="MySQL_Configuration" doc:name="Database">
                <db:parameterized-query><![CDATA[INSERT INTO `information`.`user_table`
(`current_date`,
`serialnumber`,
`gender`,
`fullname`,
`birthdate`,
`email`,
`mobilnumber`,
`address`)
VALUES
(#[xpath://date],
#[xpath://serialnumber],
#[xpath://gender],
#[xpath://fullname],
#[xpath://birthdate],
#[xpath://email],
#[xpath://mobilenumber],
#[xpath://address]
);]]></db:parameterized-query>
            </db:insert>
            <message-properties-transformer scope="invocation" doc:name="Message Properties">
                <add-message-property key="count" value="#[flowVars.counter]"/>
            </message-properties-transformer>
        </foreach>
        <logger message="#[payload] Number of records #[flowVars.count]" level="INFO" doc:name="Logger"/>
        <smtp:outbound-endpoint host="localhost" responseTimeout="10000" doc:name="SMTP"/>
    </flow>
</mule>

让我们看看以下内容是否对您有所帮助。只要把我的文件连接器换成你的FTP连接器就行了

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

<mule xmlns:smtp="http://www.mulesoft.org/schema/mule/smtp" xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking" xmlns:mulexml="http://www.mulesoft.org/schema/mule/xml" xmlns:file="http://www.mulesoft.org/schema/mule/file"
    xmlns:db="http://www.mulesoft.org/schema/mule/db" xmlns:data-mapper="http://www.mulesoft.org/schema/mule/ee/data-mapper"
    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" version="EE-3.5.0"
    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/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd
http://www.mulesoft.org/schema/mule/ee/data-mapper http://www.mulesoft.org/schema/mule/ee/data-mapper/current/mule-data-mapper.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/xml http://www.mulesoft.org/schema/mule/xml/current/mule-xml.xsd
http://www.mulesoft.org/schema/mule/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd
http://www.mulesoft.org/schema/mule/smtp http://www.mulesoft.org/schema/mule/smtp/current/mule-smtp.xsd">
    <db:mysql-config name="MySQL_Configuration" host="localhost"
        port="3306" user="" password="" database="information"
        doc:name="MySQL Configuration" />
    <data-mapper:config name="CSV_To_XML" transformationGraphPath="csv_to_xml.grf" doc:name="CSV_To_XML"/>
    <flow name="stackoverflow-ftp-dbFlow1" doc:name="stackoverflow-ftp-dbFlow1">
        <file:inbound-endpoint path="" responseTimeout="10000" doc:name="File" />
        <data-mapper:transform config-ref="CSV_To_XML" doc:name="CSV To XML"/>
        <byte-array-to-string-transformer doc:name="Byte Array to String"/>
        <foreach collection="#[xpath('//info')]" doc:name="For Each">
            <mulexml:dom-to-xml-transformer doc:name="DOM to XML"/>
            <db:insert config-ref="MySQL_Configuration" doc:name="Database">
                <db:parameterized-query><![CDATA[INSERT INTO `information`.`user_table`
(`current_date`,
`serialnumber`,
`gender`,
`fullname`,
`birthdate`,
`email`,
`mobilnumber`,
`address`)
VALUES
(#[xpath://date],
#[xpath://serialnumber],
#[xpath://gender],
#[xpath://fullname],
#[xpath://birthdate],
#[xpath://email],
#[xpath://mobilenumber],
#[xpath://address]
);]]></db:parameterized-query>
            </db:insert>
            <message-properties-transformer scope="invocation" doc:name="Message Properties">
                <add-message-property key="count" value="#[flowVars.counter]"/>
            </message-properties-transformer>
        </foreach>
        <logger message="#[payload] Number of records #[flowVars.count]" level="INFO" doc:name="Logger"/>
        <set-payload value="#[flowVars.count]" doc:name="Set Payload"/>
        <smtp:outbound-endpoint host="localhost" responseTimeout="10000" doc:name="SMTP"/>
    </flow>
</mule>
用户XMLI作为DataMapper的输出格式示例注意:流变量和xpath表达式依赖于它

<infos>
    <info>
        <date></date>
        <serialnumber></serialnumber>
        <gender></gender>
        <fullname></fullname>
        <birthdate></birthdate>
        <email></email>
        <mobilenumber></mobilenumber>
        <address></address>
    </info>
    <info>
        <date></date>
        <serialnumber></serialnumber>
        <gender></gender>
        <fullname></fullname>
        <birthdate></birthdate>
        <email></email>
        <mobilenumber></mobilenumber>
        <address></address>
    </info>
</infos>

祝你好运


PS:别忘了将mysql库添加到类路径或maven中。

让我们看看以下内容是否对您有所帮助。只要把我的文件连接器换成你的FTP连接器就行了

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

<mule xmlns:smtp="http://www.mulesoft.org/schema/mule/smtp" xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking" xmlns:mulexml="http://www.mulesoft.org/schema/mule/xml" xmlns:file="http://www.mulesoft.org/schema/mule/file"
    xmlns:db="http://www.mulesoft.org/schema/mule/db" xmlns:data-mapper="http://www.mulesoft.org/schema/mule/ee/data-mapper"
    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" version="EE-3.5.0"
    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/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd
http://www.mulesoft.org/schema/mule/ee/data-mapper http://www.mulesoft.org/schema/mule/ee/data-mapper/current/mule-data-mapper.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/xml http://www.mulesoft.org/schema/mule/xml/current/mule-xml.xsd
http://www.mulesoft.org/schema/mule/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd
http://www.mulesoft.org/schema/mule/smtp http://www.mulesoft.org/schema/mule/smtp/current/mule-smtp.xsd">
    <db:mysql-config name="MySQL_Configuration" host="localhost"
        port="3306" user="" password="" database="information"
        doc:name="MySQL Configuration" />
    <data-mapper:config name="CSV_To_XML" transformationGraphPath="csv_to_xml.grf" doc:name="CSV_To_XML"/>
    <flow name="stackoverflow-ftp-dbFlow1" doc:name="stackoverflow-ftp-dbFlow1">
        <file:inbound-endpoint path="" responseTimeout="10000" doc:name="File" />
        <data-mapper:transform config-ref="CSV_To_XML" doc:name="CSV To XML"/>
        <byte-array-to-string-transformer doc:name="Byte Array to String"/>
        <foreach collection="#[xpath('//info')]" doc:name="For Each">
            <mulexml:dom-to-xml-transformer doc:name="DOM to XML"/>
            <db:insert config-ref="MySQL_Configuration" doc:name="Database">
                <db:parameterized-query><![CDATA[INSERT INTO `information`.`user_table`
(`current_date`,
`serialnumber`,
`gender`,
`fullname`,
`birthdate`,
`email`,
`mobilnumber`,
`address`)
VALUES
(#[xpath://date],
#[xpath://serialnumber],
#[xpath://gender],
#[xpath://fullname],
#[xpath://birthdate],
#[xpath://email],
#[xpath://mobilenumber],
#[xpath://address]
);]]></db:parameterized-query>
            </db:insert>
            <message-properties-transformer scope="invocation" doc:name="Message Properties">
                <add-message-property key="count" value="#[flowVars.counter]"/>
            </message-properties-transformer>
        </foreach>
        <logger message="#[payload] Number of records #[flowVars.count]" level="INFO" doc:name="Logger"/>
        <set-payload value="#[flowVars.count]" doc:name="Set Payload"/>
        <smtp:outbound-endpoint host="localhost" responseTimeout="10000" doc:name="SMTP"/>
    </flow>
</mule>
用户XMLI作为DataMapper的输出格式示例注意:流变量和xpath表达式依赖于它

<infos>
    <info>
        <date></date>
        <serialnumber></serialnumber>
        <gender></gender>
        <fullname></fullname>
        <birthdate></birthdate>
        <email></email>
        <mobilenumber></mobilenumber>
        <address></address>
    </info>
    <info>
        <date></date>
        <serialnumber></serialnumber>
        <gender></gender>
        <fullname></fullname>
        <birthdate></birthdate>
        <email></email>
        <mobilenumber></mobilenumber>
        <address></address>
    </info>
</infos>

祝你好运


PS:别忘了将mysql库添加到类路径或maven中。

让我们看看以下内容是否对您有所帮助。只要把我的文件连接器换成你的FTP连接器就行了

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

<mule xmlns:smtp="http://www.mulesoft.org/schema/mule/smtp" xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking" xmlns:mulexml="http://www.mulesoft.org/schema/mule/xml" xmlns:file="http://www.mulesoft.org/schema/mule/file"
    xmlns:db="http://www.mulesoft.org/schema/mule/db" xmlns:data-mapper="http://www.mulesoft.org/schema/mule/ee/data-mapper"
    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" version="EE-3.5.0"
    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/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd
http://www.mulesoft.org/schema/mule/ee/data-mapper http://www.mulesoft.org/schema/mule/ee/data-mapper/current/mule-data-mapper.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/xml http://www.mulesoft.org/schema/mule/xml/current/mule-xml.xsd
http://www.mulesoft.org/schema/mule/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd
http://www.mulesoft.org/schema/mule/smtp http://www.mulesoft.org/schema/mule/smtp/current/mule-smtp.xsd">
    <db:mysql-config name="MySQL_Configuration" host="localhost"
        port="3306" user="" password="" database="information"
        doc:name="MySQL Configuration" />
    <data-mapper:config name="CSV_To_XML" transformationGraphPath="csv_to_xml.grf" doc:name="CSV_To_XML"/>
    <flow name="stackoverflow-ftp-dbFlow1" doc:name="stackoverflow-ftp-dbFlow1">
        <file:inbound-endpoint path="" responseTimeout="10000" doc:name="File" />
        <data-mapper:transform config-ref="CSV_To_XML" doc:name="CSV To XML"/>
        <byte-array-to-string-transformer doc:name="Byte Array to String"/>
        <foreach collection="#[xpath('//info')]" doc:name="For Each">
            <mulexml:dom-to-xml-transformer doc:name="DOM to XML"/>
            <db:insert config-ref="MySQL_Configuration" doc:name="Database">
                <db:parameterized-query><![CDATA[INSERT INTO `information`.`user_table`
(`current_date`,
`serialnumber`,
`gender`,
`fullname`,
`birthdate`,
`email`,
`mobilnumber`,
`address`)
VALUES
(#[xpath://date],
#[xpath://serialnumber],
#[xpath://gender],
#[xpath://fullname],
#[xpath://birthdate],
#[xpath://email],
#[xpath://mobilenumber],
#[xpath://address]
);]]></db:parameterized-query>
            </db:insert>
            <message-properties-transformer scope="invocation" doc:name="Message Properties">
                <add-message-property key="count" value="#[flowVars.counter]"/>
            </message-properties-transformer>
        </foreach>
        <logger message="#[payload] Number of records #[flowVars.count]" level="INFO" doc:name="Logger"/>
        <set-payload value="#[flowVars.count]" doc:name="Set Payload"/>
        <smtp:outbound-endpoint host="localhost" responseTimeout="10000" doc:name="SMTP"/>
    </flow>
</mule>
用户XMLI作为DataMapper的输出格式示例注意:流变量和xpath表达式依赖于它

<infos>
    <info>
        <date></date>
        <serialnumber></serialnumber>
        <gender></gender>
        <fullname></fullname>
        <birthdate></birthdate>
        <email></email>
        <mobilenumber></mobilenumber>
        <address></address>
    </info>
    <info>
        <date></date>
        <serialnumber></serialnumber>
        <gender></gender>
        <fullname></fullname>
        <birthdate></birthdate>
        <email></email>
        <mobilenumber></mobilenumber>
        <address></address>
    </info>
</infos>

祝你好运


PS:别忘了将mysql库添加到类路径或maven中。

让我们看看以下内容是否对您有所帮助。只要把我的文件连接器换成你的FTP连接器就行了

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

<mule xmlns:smtp="http://www.mulesoft.org/schema/mule/smtp" xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking" xmlns:mulexml="http://www.mulesoft.org/schema/mule/xml" xmlns:file="http://www.mulesoft.org/schema/mule/file"
    xmlns:db="http://www.mulesoft.org/schema/mule/db" xmlns:data-mapper="http://www.mulesoft.org/schema/mule/ee/data-mapper"
    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" version="EE-3.5.0"
    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/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd
http://www.mulesoft.org/schema/mule/ee/data-mapper http://www.mulesoft.org/schema/mule/ee/data-mapper/current/mule-data-mapper.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/xml http://www.mulesoft.org/schema/mule/xml/current/mule-xml.xsd
http://www.mulesoft.org/schema/mule/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd
http://www.mulesoft.org/schema/mule/smtp http://www.mulesoft.org/schema/mule/smtp/current/mule-smtp.xsd">
    <db:mysql-config name="MySQL_Configuration" host="localhost"
        port="3306" user="" password="" database="information"
        doc:name="MySQL Configuration" />
    <data-mapper:config name="CSV_To_XML" transformationGraphPath="csv_to_xml.grf" doc:name="CSV_To_XML"/>
    <flow name="stackoverflow-ftp-dbFlow1" doc:name="stackoverflow-ftp-dbFlow1">
        <file:inbound-endpoint path="" responseTimeout="10000" doc:name="File" />
        <data-mapper:transform config-ref="CSV_To_XML" doc:name="CSV To XML"/>
        <byte-array-to-string-transformer doc:name="Byte Array to String"/>
        <foreach collection="#[xpath('//info')]" doc:name="For Each">
            <mulexml:dom-to-xml-transformer doc:name="DOM to XML"/>
            <db:insert config-ref="MySQL_Configuration" doc:name="Database">
                <db:parameterized-query><![CDATA[INSERT INTO `information`.`user_table`
(`current_date`,
`serialnumber`,
`gender`,
`fullname`,
`birthdate`,
`email`,
`mobilnumber`,
`address`)
VALUES
(#[xpath://date],
#[xpath://serialnumber],
#[xpath://gender],
#[xpath://fullname],
#[xpath://birthdate],
#[xpath://email],
#[xpath://mobilenumber],
#[xpath://address]
);]]></db:parameterized-query>
            </db:insert>
            <message-properties-transformer scope="invocation" doc:name="Message Properties">
                <add-message-property key="count" value="#[flowVars.counter]"/>
            </message-properties-transformer>
        </foreach>
        <logger message="#[payload] Number of records #[flowVars.count]" level="INFO" doc:name="Logger"/>
        <set-payload value="#[flowVars.count]" doc:name="Set Payload"/>
        <smtp:outbound-endpoint host="localhost" responseTimeout="10000" doc:name="SMTP"/>
    </flow>
</mule>
用户XMLI作为DataMapper的输出格式示例注意:流变量和xpath表达式依赖于它

<infos>
    <info>
        <date></date>
        <serialnumber></serialnumber>
        <gender></gender>
        <fullname></fullname>
        <birthdate></birthdate>
        <email></email>
        <mobilenumber></mobilenumber>
        <address></address>
    </info>
    <info>
        <date></date>
        <serialnumber></serialnumber>
        <gender></gender>
        <fullname></fullname>
        <birthdate></birthdate>
        <email></email>
        <mobilenumber></mobilenumber>
        <address></address>
    </info>
</infos>

祝你好运



PS:别忘了将mysql库添加到你的类路径或maven中。

你能举一个例子说明你想从FTP加载的文件和你想存储信息的DB模式吗?@brazo.txt文件,有一个标题行,带有:date | serialnumber | gender |全名|生日| email | mobilenumber | address,然后是此标题下的所有姓名行。DB有相同的列。提前谢谢!是的,我试过了,效果不错。我假设了一个特定的文件输入,请从我的答案中尝试。如果您的输入文件看起来不一样,它将不起作用。DB连接器中的MEL表达式从有效负载检索要插入DB的信息。请确保您也阅读了有关MEL的MuleSoft文档。我希望这能帮助你走得更远。嘿,贾德,请接受我的回答也同样正确。是的,它似乎是日期格式-请参见此处,在SMTP端点之前需要一个set payload组件,该组件从count变量中获取值并将其添加为消息有效负载。我更新了我的答案。Cheers请给出一个您想从FTP加载的文件的示例,以及您想将信息存储到其中的DB模式?@brazo.txt文件有一个标题行,其中有:date | serialnumber | gender | fullname | birthdate | email | mobilenumber | address,然后是该标题下的所有名称行。DB有相同的列。提前谢谢!是的,我试过了,效果不错。我假设了一个特定的文件输入,请从我的答案中尝试。如果您的输入文件看起来不一样,它将不起作用。DB连接器中的MEL表达式从有效负载检索要插入DB的信息。请确保您也阅读了有关MEL的MuleSoft文档。我希望这能帮助你走得更远。嘿,贾德,请接受我的回答也同样正确。是的,它似乎是日期格式-请参见此处,在SMTP端点之前需要一个set payload组件,该组件从count变量中获取值并将其添加为消息有效负载。我更新了我的答案。Cheers请给出一个您想从FTP加载的文件的示例,以及您想将信息存储到其中的DB模式?@brazo.txt文件有一个标题行,其中有:date | serialnumber | gender | fullname | birthdate | email | mobilenumber | address,然后是该标题下的所有名称行。DB有相同的列。提前谢谢!是的,我试过了,效果不错。我假设了一个特定的文件输入,请从我的答案中尝试。如果您的输入文件看起来不一样,它将不起作用。DB连接器中的MEL表达式从有效负载检索要插入DB的信息。请确保您也阅读了有关MEL的MuleSoft文档。我希望这能帮助你走得更远。嘿,贾德,请接受我的回答也同样正确。是的,它似乎是日期格式-请参见此处,在SMTP端点之前需要一个set payload组件,该组件从count变量中获取值并将其添加为消息有效负载。我更新了我的答案。Cheers请给出一个您想从FTP加载的文件的示例,以及您想将信息存储到其中的DB模式?@brazo.txt文件有一个标题行,其中有:date | serialnumber | gender | fullname | birthdate | email | mobilenumber | address,然后是该标题下的所有名称行。DB有相同的列。提前谢谢!是的,我试过了,效果不错。我假设了一个特定的文件输入,请从我的答案中尝试。如果您的输入文件看起来不一样,它将不起作用。DB连接器中的MEL表达式从有效负载检索要插入DB的信息。恳求