如何配置Mule流以将oracle sql结果写入文件?

如何配置Mule流以将oracle sql结果写入文件?,mule,mule-studio,Mule,Mule Studio,我是否可以使用现成的mule组件配置一个将select语句的结果集写入文件的流 我尝试了很多变压器的组合,但只有一个完成了一半的工作 以下是配置XML: <?xml version="1.0" encoding="UTF-8"?> <mule xmlns:data-mapper="http://www.mulesoft.org/schema/mule/ee/data-mapper" xmlns:quartz="http://www.mulesoft.org/schem

我是否可以使用现成的mule组件配置一个将select语句的结果集写入文件的流

我尝试了很多变压器的组合,但只有一个完成了一半的工作

以下是配置XML:

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

<mule xmlns:data-mapper="http://www.mulesoft.org/schema/mule/ee/data-mapper" xmlns:quartz="http://www.mulesoft.org/schema/mule/quartz" xmlns:wmq="http://www.mulesoft.org/schema/mule/ee/wmq" xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking" xmlns:jdbc-ee="http://www.mulesoft.org/schema/mule/ee/jdbc" xmlns:file="http://www.mulesoft.org/schema/mule/file" xmlns:mulexml="http://www.mulesoft.org/schema/mule/xml" 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.4.1"
    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/xml http://www.mulesoft.org/schema/mule/xml/current/mule-xml.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/jdbc http://www.mulesoft.org/schema/mule/ee/jdbc/current/mule-jdbc-ee.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/ee/wmq http://www.mulesoft.org/schema/mule/ee/wmq/current/mule-wmq-ee.xsd
http://www.mulesoft.org/schema/mule/quartz http://www.mulesoft.org/schema/mule/quartz/current/mule-quartz.xsd
http://www.mulesoft.org/schema/mule/ee/data-mapper http://www.mulesoft.org/schema/mule/ee/data-mapper/current/mule-data-mapper.xsd">
    <jdbc-ee:oracle-data-source name="Oracle_Data_Source1" user="username" password="password" url="jdbc:oracle:thin:@//ip:1521/instance_name" transactionIsolation="READ_COMMITTED" doc:name="Oracle Data Source"/>
    <jdbc-ee:connector name="Database" dataSource-ref="Oracle_Data_Source1" validateConnections="true"  queryTimeout="-1" pollingFrequency="0" doc:name="Database" transactionPerMessage="false">
        <jdbc-ee:query key="selectTOP10" value="select CONTRACT_ID FROM LAM_CONTRACT where rownum&lt;11"/>
    </jdbc-ee:connector>
    <data-mapper:config name="map_to_map" transformationGraphPath="map_to_map.grf" doc:name="map_to_map"/>
    <file:connector name="File" writeToDirectory="D:\Test File Transfer\Destination" workFileNamePattern="test2.txt" autoDelete="true" outputAppend="true" streaming="true" validateConnections="true" doc:name="File"/>
    <file:endpoint path="D:\Test File Transfer\Destination" outputPattern="test2.txt" name="File1" responseTimeout="10000" doc:name="File"/>
    <flow name="oracle_to_fileFlow1" doc:name="oracle_to_fileFlow1">
        <jdbc-ee:inbound-endpoint  queryTimeout="-1" pollingFrequency="1000" doc:name="Database" connector-ref="Database" queryKey="selectTOP10"/>
        <logger level="INFO" doc:name="Logger" message="Result: #[payload]------------------------"/>
        <byte-array-to-string-transformer doc:name="Byte Array to String"/>
        <file:outbound-endpoint responseTimeout="10000" doc:name="File" ref="File1"/>
    </flow>
</mule>
我替换了db连接的用户名和密码。 如果我运行流,它将填充文本文件,如下所示:

{CONTRACT\u ID=12}{CONTRACT\u ID=13}{CONTRACT\u ID=11}{CONTRACT\u ID=14}{CONTRACT\u ID=15}{CONTRACT\u ID=9}{CONTRACT\u ID=8}{CONTRACT\u ID=7}。。。等等

我接下来需要做的是: 1我想以表格格式输出日期,第一行-列名称标题,其余行数据

2我希望能够设置/更改列分隔符

3我相信我必须使用Quartz组件才能在某个时刻启动流,并且只运行一次查询。我曾尝试配置一个,但在谷歌上花了几个小时研究如何配置后,我觉得在这里询问会更好

有人能帮忙吗?我想补充一点,我是一名C、.NET、SQL Server开发人员,所以我真的希望我不必为了使用Mule而学习java


附言:虽然我已经诅咒SSI这么长时间了,我不得不承认它与Mule相比有很多规则——仅限于个人观点:。

1和2如果你的例子中有Mule EE,这并不难。要在不到五分钟的时间内完成这项工作,您可以使用object To json transformer,然后使用DataMapper创建从json到CSV的转换。您可以选择分隔符并将列标题添加到设置的输出中

3假设您可以在google上搜索如何为Mule Quartz端点设置cron表达式,那么您首先需要流之外的端点:

<jdbc-ee:endpoint name="ep" queryKey="selectTOP10" connector-ref="Database" />
流程是这样的:

<quartz:inbound-endpoint jobName="cronJobPoolTime" cronExpression="* * * * * ?">
    <quartz:endpoint-polling-job>
        <quartz:job-endpoint ref="ep"/>
    </quartz:endpoint-polling-job>
</quartz:inbound-endpoint>      
<json:object-to-json-transformer/>
<data-mapper:transform config-ref="json_to_csv"/>
<file:outbound-endpoint responseTimeout="10000" doc:name="File" ref="File1"/>

附言:我个人的观点是,专业地使用Mule需要具备Java和相关技术的基础知识,如Spring、Maven、,等等。这是整个过程的基础。

要在文件中写入结果集,只需删除并将对象放置到XML或对象放置到JSON transformer即可